R Markdown: fancyhdr can't set head rule to 0 even after redefining the \headrulewidth command

Refresh

last month

Views

129 time

1

I'm trying to make a quick thesis document/template, but the documents are not allowed to have a header line, just the page numbers. I can change what exists inside the header and footers (e.g. adding a page number at the top right hand of the page), but the rule won't go away.

I tried multiple variations of the following code (this being example document to try to isolate the problem):

---
title: "Test"
author: "TEst"
date: "February 14, 2018"
output: pdf_document
header-includes:
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \AtBeginDocument{\thispagestyle{fancy}}
- \rhead{\thepage}
- \cfoot{}
- \renewcommand{\headrulewidth}{0pt}
---

\renewcommand{\headrulewidth}{0pt}
\newpage
\renewcommand{\headrulewidth}{0pt}


# Hello

But no luck. The line is always there. I even tried the \renewcommand{\headrule}{} and it still shows up. I'm thinking this may be a pandoc error, but I'm not entirely sure. Could you guys provide some insight?

Edit: This code is now the exact test case I was using to troubleshoot. The actual document is included below as well.

---
output:
  pdf_document:
    fig_caption: yes
    number_sections: yes
bibliography: library.bib
csl: methods-in-ecology-and-evolution.csl
urlcolor: black
linkcolor: black
fontsize: 12pt
geometry: margin = 1.2in
header-includes:
- \usepackage{placeins}
- \usepackage{fancyhdr}
- \usepackage{setspace}
- \usepackage{chngcntr}
- \usepackage{microtype}
- \onehalfspacing
- \counterwithin{figure}{section}
- \counterwithin{table}{section}
---

---
nocite: | 
  @Example1999, @Example2000
...

```{r global_options, include=FALSE}
knitr::opts_chunk$set(fig.path = 'figures/',
                      echo = FALSE, warning = FALSE, message = FALSE)
```

\pagenumbering{gobble}

```{r child = 'titlepage.Rmd'}
```

\newpage

```{r child = 'declaration.Rmd'}
```

\newpage
\pagestyle{fancy}

\fancyhead[LE,RO]{}
\fancyhead[LO,RE]{}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}

\pagenumbering{roman}

\renewcommand{\headrulewidth}{0pt}
\fancyhead[CO,CE]{Abstract}
\renewcommand{\headrulewidth}{0pt}
\section*{Abstract}
\addcontentsline{toc}{section}{Abstract}

```{r child = 'abstract.Rmd'}
```

\newpage
\fancyhead[CO,CE]{Acknowledgements}
\section*{Acknowledgements}
\addcontentsline{toc}{section}{Acknowledgements}

```{r child = 'acknowledgements.Rmd'}
```

\newpage
\fancyhead[CO,CE]{Table of Contents}
\setcounter{tocdepth}{2}
\tableofcontents

\newpage
\pagenumbering{arabic}

\newpage
\fancyhead[CO,CE]{Introduction}

```{r child = 'chapter1.Rmd'}
```

\FloatBarrier
\newpage
\fancyhead[CO,CE]{Methods}

```{r child = 'chapter2.Rmd'}
```

\FloatBarrier
\newpage
\fancyhead[CO,CE]{Results}

```{r child = 'chapter3.Rmd'}
```

\FloatBarrier
\newpage
\fancyhead[CO,CE]{Discussion}

```{r child = 'chapter4.Rmd'}
```

\FloatBarrier

\newpage
\fancyhead[CO,CE]{List of Figures}
\addcontentsline{toc}{section}{List of Figures}
\listoffigures

\newpage
\fancyhead[CO,CE]{List of Tables}
\addcontentsline{toc}{section}{List of Tables}
\listoftables

\newpage

```{r child = 'appendix.Rmd'}
```

\FloatBarrier
\newpage
\fancyhead[CO,CE]{References}

# References

Edit 2: Solved it! By placing the commands into a .sty file and including that file in the header via the following

output:
     pdf_document:
       fig_caption: yes
       number_sections: yes
       includes:
        in_header: test.sty
   bibliography: library.bib

I have had extremely precise control over the document via the typical LaTeX syntax, so I'm making a .sty file that should hopefully let me (and others) write their dissertations in R Markdown!

0 answers