I'm using Rmarkdown to produce a landscape pdf document with xelatex.
For my YAML header I'm using
output:
pdf_document:
latex_engine: xelatex
keep_tex: true
includes:
in_header: 'preamble.tex'
classoption: landscape
and in my preamble.tex
% Create custom blue coloring function
\usepackage{color}
\definecolor{headerblue}{HTML}{236593}
\usepackage{fancyhdr}
\pagestyle{fancy}
% vertical margins
\setlength{\topmargin}{-1in}
\setlength{\headheight}{60.0pt} %set height of box that contains header
\setlength{\headsep}{5pt}
% horizontal margins
\setlength{\oddsidemargin}{-0.5in}
\setlength{\evensidemargin}{\oddsidemargin}
% Left header with Community Profile info created within .Rmd file
\lhead{}
\rhead{\textbf{Protected A} \raisebox{-.4\height} % Create right header with raised text
{\includegraphics[width = 5cm]{./image/HSIAR-Logo-blue_small.png}}} % and HSIAR logo
\renewcommand{\headrulewidth}{0pt} % remove rule below header
For the \lhead in the .Rmd
`{=latex}
\lhead{
\fontsize{18pt}{18pt}\selectfont \textbf{\textcolor{headerblue}{`r header_name`}}}
I have two issues I'm not sure how to address.
The first is after all my margin adjustments, I get a large-ish gap on the right hand side where the text and header won't go into. It appears there is no margin adjustment option for this, I can just manually try and get /textwidth to the right size? Or is there a better way?
Lastly, for /rhead the raisebox does a great job elevating the text. However I only want it on the right. It also raises the text for my lhead. I thought putting an empty /lhead{} in my preamble might help, but no luck.
Any suggestions or guidance would be amazing.


\setlengthto change the margins. Use packagegeometryto setup the margins you want. Currently you only change the left margin of odd and even pages. To change the right margin of odd and even pages, you would need to change\textwidth. But withgeometry, you can directly change the left and right margin. – cabohah Mar 08 '24 at 08:01\documentclass, have all the packages and preamble code and a document body from\begin{document}to\end{document}needed to reproduce the issue without change. This should also be possible using a code generator, if you show a minimized generated LaTeX document. – cabohah Mar 08 '24 at 08:07