8

When I use #### for a level 4 heading, the output in pdf(latex) does not leave a line space before the paragraph begins. For example,

#### Heading 4

Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, 
when an unknown printer took a galley of type and scrambled it to make a type
specimen book. 

Output only in pdf(latex) looks like this

Heading 4 Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

I have read everywhere that r markdown allows 1-6 #’s for the headings, so I am trying to figure out what am I doing wrong here.

Also I figured I could use \subsubsubsubsection instead of #### for the heading but that gives me an error.

Pdawg
  • 321
  • 1
  • 3
  • 7

2 Answers2

6

See Mico's answer to the following question:

https://tex.stackexchange.com/questions/60209/how-to-add-an-extra-level-of-sections-with-headings-below-subsubsection

Add this code to your tex header file and that should do it:

\documentclass{article}
\makeatletter
\renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}%
        {-2.5ex\@plus -1ex \@minus -.25ex}%
        {1.25ex \@plus .25ex}%
        {\normalfont\normalsize\bfseries}}
\makeatother
\setcounter{secnumdepth}{4} % how many sectioning levels to assign numbers to
Community
  • 1
  • 1
Scott Murff
  • 128
  • 8
2

This is essentially a LaTeX style question, not a (r)markdown-specific question. If you add the YAML header

---
output:
   pdf_document:
      keep_tex: true
---

to your document (or add these lines to an existing YAML header), the generated LaTeX file will get preserved; then you can look through the LaTeX file to see that what gets generated is:

\paragraph{Heading 4}\label{heading-4}

Lorem Ipsum ...

The problem is that the default paragraph style in LaTeX doesn't include a newline. Once you know that this is what's going on, you can search for something like this LaTeX incantation from tex.stackexchange.com, create a parahdr.tex file containing

\usepackage{titlesec}
\titleformat{\paragraph}
   {\normalfont\bfseries}
   {}
   {0pt}
   {}

and incorporate it in your YAML header according to the "advanced customization" documentation for PDF output from the rmarkdown package:

---
output:
   pdf_document:
      keep_tex: true
      includes: 
          in_header: parahdr.tex
---
Community
  • 1
  • 1
Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • 1
    Thanks for the solution. It does help with starting the paragraph on a new line but the heading does not have the section numbering on it. So, it is pretty much like writing Heading4 in bold. Looking at the latex code, the problem is that after the level 3 heading, latex thinks any more headings are paragraph headings, so fixing for that solved my problem :) – Pdawg Oct 14 '15 at 21:40