2
votes

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
2
A parameterized report may be what you need. Here and here are a couple of examples.eipi10
This is neat, thank you!AHegde

2 Answers

4
votes

Add this outside of Rmarkdown code chuncks after you set the variable

\fancyhead[L]{`r variable_name`}
0
votes

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