I'm currently having an issue with latex in Rmarkdown (using fancyhdr package). I am trying to make a data report with a certain template style. But as of right now, my heading1 for each page is not aligned properly. I assume it has something to do with my \headheight, but I am not sure how to resolve it.
This is currently done in R-markdown, and I am quite confident that the issue has something to do with my YAML. I would be very appreciated if anyone could tell me how to fix my YAML coding for \headheight or overall improving my coding for YAML to fix the overlapping issue.
There are no errors when I run this code, but this is the warnings that they provide me (but I have no idea how to resolve the warning)
Package Fancyhdr Warning: \headheight is too small (12.0pt):
Make it at least 32.08571pt.
We now make it that large for the rest of the document.
This may cause the page layout to be inconsistent, however.
This is my YAML:
---
output:
pdf_document:
latex_engine: pdflatex
header-includes:|
\usepackage{graphicx}
\usepackage{fancyhdr}
\pagestyle{fancy}
\newcommand{\helv}{%
\fontfamily{phv}\fontseries{b}\fontsize{9}{11}\selectfont}
\fancyhead[R]{\includegraphics[width=3cm]{logo.png}}
\fancyhead[L]{\textbf\selectfont\sffamily{Daily Report}}
\fancyfoot[L]{\textbf\selectfont\sffamily{NOT INTENDED FOR FORWARDING}}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}
classoption: a4paper
---
And these are in the rest of the codes:
```r-markdown
## \selectfont\sffamily{EQUITY 1}
# content page 1
\newpage
## \selectfont\sffamily{EQUITY 2}
# content page 2
I posted an image of the pdf output on TeXStackExchange: https://tex.stackexchange.com/questions/482525/having-problems-with-latex-coding-in-rmarkdown-fancyhdr-headheight
I would like all of them to be aligned with each other. I do not know if I have done my coding in YAML correctly.
The warning is pretty explicit that the headheight needs to be larger than 32.08571pt. This requirement can be fulfilled by adding e.g. \setlength{\headheight}{32.09pt} to your header-includes.
---
output:
pdf_document:
latex_engine: pdflatex
header-includes:|
\usepackage{graphicx}
\usepackage{fancyhdr}
\pagestyle{fancy}
\newcommand{\helv}{%
\fontfamily{phv}\fontseries{b}\fontsize{9}{11}\selectfont}
\fancyhead[R]{\includegraphics[width=3cm]{logo.png}}
\fancyhead[L]{\textbf\selectfont\sffamily{Daily Report}}
\fancyfoot[L]{\textbf\selectfont\sffamily{NOT INTENDED FOR FORWARDING}}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}
\setlength{\headheight}{32.09pt}
classoption: a4paper
---
Related
Given the code below, which currently outputs the page number on top of the page, I would like it to output the PDF page count as in Page 1 of 3. I have done a lot of searching but haven't found any way to include the total page number.
Question Is this possible to do w/ in R Markdown ? If not, are there any workarounds ?
I have googled this and haven't found anything obvious such as YAML or TeX solutions, however, I may be missing something or not searching for the correct things.
RMarkdown Code
---
title: "R Markdown Example With Numbered Sections"
output:
bookdown::pdf_document2:
toc: true
toc_depth: 6
number_sections: true
includes:
in_header: header.tex
header-includes:
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \fancyhead[RO,RE]{\thepage}
- \fancyhead[LO,LE]{Header Message}
- \fancyfoot[LE,LO]{Footer Messge on the Left}
- \fancyfoot[LE,RO]{Footer Messge on the Right}
---
\thispagestyle{fancy}
# Example R Rarkdown : Numbered Sections
## R Markdown
### Description
Some description text
\newpage
#### Details
Details go here.
\newpage
## Plots
Plots go here
\newpage
Last page
Current header
Desired Header
Make sure you have the lastpage package installed.
Then modify your header includes to look like this:
header-includes:
- \usepackage{fancyhdr}
- \usepackage{lastpage}
- \pagestyle{fancy}
- \fancyhead[RO,RE]{\thepage\ of \pageref{LastPage}}
- \fancyhead[LO,LE]{Header Message}
- \fancyfoot[LE,LO]{Footer Messge on the Left}
- \fancyfoot[LE,RO]{Footer Messge on the Right}
I am trying to learn Rmarkdown, but there is something that's quite elusive. I am trying to put my name at the top of every page of the PDF I print, however I also get the various headers from the text in the markdown file in the header, and it often overlaps and makes everything unreadable. I learned the basics from another thread on here, but still struggling. I only want my name in the header. I tried to modify it like what you see below, but then I don't get anything at all. This is my YAML:
---
title: "Something"
author: "something"
date: "42 42 42"
output: pdf_document
includes:
in_header: {My name}
fontsize: 12pt
header-includes:
\usepackage{setspace}
\onehalfspacing
---
Anyone who could write it so that I get only my name at the top of the page? Also, the onehalfspacing is the same as setting spacing to 1.5 in word right?
I think there is a conceptual problem: The things you put in includes: in_header: in the yaml are the files included in the preamble of your tex document, similar to what you have in header-includes:. This is not in any way related to the headline of your document.
If you like to change this, have a look at the fancyhdr latex package
Please also note that the syntax for multiline header-includes: is wrong in your example. You need to prefix each line with -
---
title: "Something"
author: "something"
date: "42 42 42"
output: pdf_document
fontsize: 12pt
header-includes:
- \usepackage{setspace}
- \onehalfspacing
- \usepackage{fancyhdr}
- \fancyhead[c]{your name}
- \pagestyle{fancy}
- \setlength{\headheight}{15pt}
---
test
\newpage
test
I'm creating reports using what I think is a combination of Rmarkdown/Knitr, YAML, LaTeX and Pandoc (I don't fully understand which parts of my code pertain to what because I'm not well versed in anything except R).
I want to know how to add a "dynamic" header, where the contents of the header can be called from variables I read in, for eg., a value from a dataframe I import into the R session.
Specifically, I want to add, say, a unique ID# for every report, to be printed on every page of the report (not necessarily in the header), with a new unique ID# for every new report I generate, without having to manually change this information in the header section each time I make a new report.
This is my current header:
header-includes:
\usepackage{fancyhdr}
\usepackage{graphicx}
\usepackage{eurosym}
\usepackage{booktabs}
\pagestyle{fancy}
\fancyhf{}
\addtolength{\headheight}{1.0cm}
\rfoot{Page \thepage}
\usepackage{setspace}
\setlength{\topsep}{0pt}
\fancypagestyle{plain}{\pagestyle{fancy}}
\renewcommand{\footrulewidth}{0.4pt}
\iffalse
\fi
\rhead{\fontsize{28}{12}\selectfont My Report}
\lhead{\includegraphics[width=6cm]{path/to/my/png.png}}
\cfoot{some information about footer goes here }
\usepackage{floatrow}
\floatsetup[table]{capposition=top, objectset=centering}
\setlength\parindent{0 pt}\setlength{\parskip}{0.0pt plus 0.0pt}
output:
pdf_document:
keep_tex: yes
latex_engine: xelatex
geometry: "left=2cm,right=2cm,top=2.5cm,bottom=3cm"
mainfont: Calibri
fontsize: 12pt
Add this outside of Rmarkdown code chuncks after you set the variable
\fancyhead[L]{`r variable_name`}
A combination of eipi10 's comment to my question (specifically, his link to the Rmarkdown/Rstudio webpage) and this post is what finally worked for me:
https://stackoverflow.com/a/35044316/3276842
I have some .Rmd files in which I need to make some changes to the layout in subsections. This example shows what I need to do.
This is an example Rmd code:
---
title: "test"
output:
pdf_document:
latex_engine: xelatex
number_sections: yes
toc: yes
toc_depth: 3
html_document: default
mainfont: Calibri Light
header-includes:
- \usepackage[dutch]{babel}
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \fancyfoot[LE,RO]{test}
- \usepackage{floatrow}
- \floatsetup[table]{capposition=top}
- \usepackage{dcolumn}
- \usepackage{here}
- \usepackage{caption}
- \captionsetup{labelsep=space,justification=justified,singlelinecheck=off}
---
# Article
## title
#### subsubsubtitle {-}
Here is some text
The result if generating pdf is:
But what I really want is:
So I want the text to be starting on the next line instead of right after the section header. (Also I don't want the subsection to be numbered and, that's why I put the {-} right after it.)
Does someone know how to manage this?
This addresses the Latex side of the problem.
The \paragraph, which is what \subsubsubsection is, just has different formatting and presentation. One of the things is that it doesn't start a new line. This is in pure Latex.
Ways around it:
The package titlesec allows you to customize the title appearance a lot. See this post.
Do it in Latex itself -- [re]define how \paragraph works -- see the above post, and/or this post.
Tweak it in the next itself, adding a newline. See below.
There may be a more direct way in .Rmd but I am not familiar with it and this has the Latex tag.
I have to address another aspect of this, without debating poster's purpose. Such deep hierarchy may indicate a need to rethink the structure. Does it help in making the document easier and more intuitive to use, or does it do the opposite?
With that out of the way, here are some direct ways of making it add a line, as requested.
Tweak it in the text itself, so that it takes a newline (\newline alone doesn't work).
\paragraph{title_text}
\mbox{ }\\
paragraph text here
Another way
\paragraph{title_text} \hspace{0pt} \\
paragraph text here
With titlesec package you can redefine the \paragraph, by changing [runin] to [hung]
\usepackage{titlesec}
\titleformat{\paragraph}[hung] % default is [runin]
{\normalfont\normalsize\bfseries}
{\theparagraph}{1em}{}
Or, can explicitly change the spacings
\usepackage{titlesec}
\titleformat{\paragraph}
{\normalfont\normalsize\bfseries}{\theparagraph}{1em}{}
\titlespacing*{\paragraph}
{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
For a succinct summary of the titlesec package see this post.
All this is straight-up Latex and I am not sure how it works with .Rmd.
I'm currently preparing a presentation in RStudio (using RMarkdown and Knitr, outputting to a Beamer presentation) that has quite a few references.
I'm using a pretty typical YAML header:
---
title: "Title"
author: "Me"
date: "February 27th, 2016"
output:
beamer_presentation
csl: ../../apa.csl
bibliography: ../../RefenceDesk.bib
---
This presentation compiles and the references appear as they should, but unfortunately they all appear on one slide (and actually run off the page). Is there any way to have the references appear on multiple slides?
{.allowframebreaks} is the solution for multislides bibliographies in beamer. It works out of the box with regular pandoc templates (see my previous answer). However, knitr has a setting that prevents it, by redefining \widowpenalties in its beamer template. You can verify that if you examine the .tex file with keep_tex: true.
In my opinion, this is a bug. A quick fix would be to reset \widowpenalties to its default value. It can be done in your yaml front matter:
---
title: Title
header-includes:
- \widowpenalties 1 150
output:
beamer_presentation
---
Then, you can indicate the reference section as such:
## References {.allowframebreaks}
As #David above said in the comments:
For me it didnt work with ## References {.allowframebreaks} but it worked out with # References {.allowframebreaks}.
I would like to point out that, apparently for the reference slide to work you have to create a last slide with the same heading level es set by slide_level: __ at the YAML section.
So, the user should set one of the following:
# References {.allowframebreaks}. for those using slide_level: 1, OR
## References {.allowframebreaks}. for those using slide_level: 2, OR
### References {.allowframebreaks}. for those using slide_level: 3 and so on...
While this goes outside of using the regular pandoc citation template, I have found another approach that can be used to put the references across slides but it relies on the natbib citation package.
In the YAML front matter, I added:
---
title: "Title"
output:
beamer_presentation:
citation_package: natbib
bibliography: ../../RefenceDesk.bib
biblio-style: "apalike"
---
The reference slide does not get a title and I cannot seem to adjust the font size (by using a \scriptsize at the end of the .Rmd file), but at least they appear coherently.
EDIT: For parsimony, I removed the csl: ../../apa.csl line, since natbib does not require it.