0

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.

visual reference

Any suggestions or guidance would be amazing.

PhDavey
  • 103
  • 2
  • 1
    Don't fiddle with \setlength to change the margins. Use package geometry to 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 with geometry, you can directly change the left and right margin. – cabohah Mar 08 '24 at 08:01
  • 1
    BTW: For are more detailed answer instead of a comment only, it would be helpful to have a minimal working example instead of only some code snippets. Such a MWE should start with \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

1 Answers1

2

Chunks of rmarkdown and LaTeX with not available images and that not correspond to the screenshot are not the best example to reproduce the issue, bet seems clear that you are trying to make to set the margins by the hard way. As sugested in the comments, use geometry with the option showframe to see where you have really the margins:

MWE

---
output:
  pdf_document:
    latex_engine: xelatex
classoption: landscape, showframe
geometry: [tmargin=2cm,bmargin=2.5cm,rmargin=1cm,lmargin=1.2cm]
header-includes: 
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \lhead{}
- \rhead{\textbf{Protected A} \raisebox{-.4\height}{ \includegraphics[height = 1cm]{example-image}}}
- \renewcommand{\headrulewidth}{0pt} % remove rule below header
--- 
Foo \newpage bar \newpage baz
Fran
  • 80,769