2

I am struggling with building the basic pdf document for my thesis in markdown. It worked well, until I tried to add a header with \usepackage{fancyhdr}. Then it returns the error

! Undefined control sequence.
<argument> \undefinedpagestyle

I also realized there is no folder saying fancyhdr in the main miktex folder.

Here's my yaml header:

---
output: 
  bookdown::pdf_document2:
    toc: true
    toc_depth: 3
    number_section: true
    header-includes:
      - \usepackage{float}
      - \usepackage{fancyhdr}
      - \usepackage[margins=raggedright]{floatrow}
      - \usepackage{placeins}
      - \usepackage{chngcntr}
      - \counterwithin{figure}{section}
      - \counterwithin{table}{section}
      - \usepackage[german]{babel}
fontsize: 11pt
linestretch: 1.5
lang: de-DE
geometry: margin=2.5cm
link-citations: true
---

Here's, how I use the pagestyle in the code:

``` {r setup, include=FALSE}
library(knitr)
library(tidyverse)

opts_chunk$set(echo=FALSE)
```

\pagebreak
\pagenumbering{Roman}

\newpage
\listoffigures
\newpage
\listoftables
\newpage
\section*{Abkürzungsverzeichnis}

\pagebreak

\pagenumbering{arabic}

\pagestyle{fancy}
\fancyhead[LO,LE]{\leftmark}
\fancyfoot[CO,CE]{\thepage}

\renewcommand{\footrulewidth}{\headrulewidth}

I am quite confused about this error because my friend's file looks exactly the same regarding the fancyhdr region. He doesn't get any error.

Please help!

1
  • 1
    You might have to install the fancyhdr package with the miktex console program. Jun 19 at 21:53

1 Answer 1

1

Three problems:

  • the indentation of the header is wrong. header-includes can't be indented. It is not a property of pdf_document2 but needs to be at the top level

  • you can't combine the floatrow and float packages

  • rmarkdown automatically loads babel. You can't load it a second time with different options


---
output: 
  bookdown::pdf_document2:
    toc: true
    keep_tex: true
    toc_depth: 3
    number_section: true
header-includes:
  - \usepackage{fancyhdr}
  - \usepackage[margins=raggedright]{floatrow}
  - \usepackage{placeins}
  - \usepackage{chngcntr}
  - \counterwithin{figure}{section}
  - \counterwithin{table}{section}
fontsize: 11pt
linestretch: 1.5
lang: de-DE
geometry: margin=2.5cm
link-citations: true
---


``` {r setup, include=FALSE}
library(knitr)
library(tidyverse)

opts_chunk$set(echo=FALSE)
```

\pagebreak
\pagenumbering{Roman}

\newpage
\listoffigures
\newpage
\listoftables
\newpage
\section*{Abkürzungsverzeichnis}

\pagebreak

\pagenumbering{arabic}

\pagestyle{fancy}
\fancyhead[LO,LE]{\leftmark}
\fancyfoot[CO,CE]{\thepage}

\renewcommand{\footrulewidth}{\headrulewidth}

test

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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