Question: 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.

Answer: 
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

```
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](https://tex.stackexchange.com/questions/40943/new-line-and-no-indent-after-paragraph), 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](http://rmarkdown.rstudio.com/pdf_document_format.html#advanced-customization):

```
---
output:
   pdf_document:
      keep_tex: true
      includes: 
          in_header: parahdr.tex
---

```