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.

0

2 Answers 2

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
3
  • I did something similar but ya that is pretty much it.
    – Pdawg
    Oct 14, 2015 at 22:02
  • What did you do? It would help me.
    – POC
    Nov 8, 2021 at 22:08
  • This much simpler answer worked for me: stackoverflow.com/a/66128821/3277050
    – see24
    Jul 14 at 14:31
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
---
1
  • 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, 2015 at 21:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.