Search code examples
formattinglatexpandocbookdownheading

Change font size of ATX-header in markdown


I am writing a book with bookdown. Unfortunately, I have no clue how to format (e.g. setting font size) ATX-hearder (#, ##, ## etc.). So far, it does not work via pandoc or preamble.tex.

I have tried the following, with regard to this.

Unfortunately, there is an error message :

\usepackage{titlesec} \titleformat{\chapter}[display] {\normalfont\sffamily\huge\bfseries\color{blue}} {\chaptertitlename\ \thechapter}{20pt}{\Huge}

Thanks in advance!


Solution

  • Your best bet here is to add a LaTeX preamble to the document. In here, you can define the required LaTeX packages. Two changes are made to the base template:

    Here is a minimal example

    ---
    output: 
      pdf_document:
        includes:
          in_header: header.tex
    subparagraph: true
    ---
    
    
    # Section
    
    ## Subsection
    

    The preamble.tex file is saved in the same directory:

    \usepackage{titlesec}
    \usepackage{color}
    
    \titleformat*{\section}{\LARGE}
    
    \titleformat{\subsection}[display]
      {\normalfont\sffamily\huge\bfseries\color{blue}} {\chaptertitlename\ \thechapter}{20pt}{\Huge}
    

    enter image description here