Reputation: 7385
I am creating a series of PDFs in an RMarkdown loop, and can't figure out how to control the spacing between the lines created with \headrule
and the start of the text within the r
chunk.
My attempts have been futile, but have included using \vspace{#pt}
in various locations, adding cat("\\vspace{#pt}")
, trying to use \usepackage{geometry}
while specifying headsep
. I'm at a loss and appreciate any and all advice/solutions.
I would like to move the text closer to the blue and red lines in the image below. Ideally the adjustment can be dynamic, since the general outline will be used as a template for similar but slightly different looking reports.
Here is a reprex for .rmd
to pdf
:
---
title:
output:
pdf_document:
latex_engine: lualatex
geometry: "top=.5in, right=.75in, left=.75in, bottom = .5in"
header-includes:
- \usepackage{fancyhdr}
- \pagestyle{fancy}
tables: yes
---
\setlength{\headheight}{144pt}
\renewcommand{\headrulewidth}{0pt}
\fancyhead[L]{%
\textbf{Here is my title}
}
\renewcommand\headrule{%
\begingroup
\vspace{2pt}
\color{blue}\hrule height 4.32pt width\headwidth
\vspace{2.16pt}
\color{red}\hrule height 4.32pt width\headwidth
\endgroup
}
```{r echo=FALSE, results = 'asis'}
cat("\\textbf{Name}")
cat("\\linebreak")
cat("\\textbf{ID}")
```
Here is the .tex
file:
% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[
]{article}
\usepackage{amsmath,amssymb}
\usepackage{lmodern}
\usepackage{ifxetex,ifluatex}
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
\usepackage{unicode-math}
\defaultfontfeatures{Scale=MatchLowercase}
\defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
\usepackage[]{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\@ifundefined{KOMAClassName}{% if non-KOMA class
\IfFileExists{parskip.sty}{%
\usepackage{parskip}
}{% else
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
\KOMAoptions{parskip=half}}
\makeatother
\usepackage{xcolor}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\hypersetup{
hidelinks,
pdfcreator={LaTeX via pandoc}}
\urlstyle{same} % disable monospaced font for URLs
\usepackage[top=.5in, right=.75in, left=.75in, bottom = .5in]{geometry}
\usepackage{longtable,booktabs,array}
\usepackage{calc} % for calculating minipage widths
% Correct order of tables after \paragraph or \subparagraph
\usepackage{etoolbox}
\makeatletter
\patchcmd\longtable{\par}{\if@noskipsec\mbox{}\fi\par}{}{}
\makeatother
% Allow footnotes in longtable head/foot
\IfFileExists{footnotehyper.sty}{\usepackage{footnotehyper}}{\usepackage{footnote}}
\makesavenoteenv{longtable}
\usepackage{graphicx}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
% Set default figure placement to htbp
\makeatletter
\def\fps@figure{htbp}
\makeatother
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{-\maxdimen} % remove section numbering
\usepackage{fancyhdr}
\pagestyle{fancy}
\ifluatex
\usepackage{selnolig} % disable illegal ligatures
\fi
\author{}
\date{\vspace{-2.5em}}
\begin{document}
\setlength{\headheight}{144pt}
\renewcommand{\headrulewidth}{0pt}
\fancyhead[L]{%
\textbf{Here is my title}
}
\renewcommand\headrule{%
\begingroup
\vspace{2pt}
\color{blue}\hrule height 4.32pt width\headwidth
\vspace{2.16pt}
\color{red}\hrule height 4.32pt width\headwidth
\endgroup
}
\textbf{Name}\linebreak\textbf{ID}
\end{document}
Upvotes: 1
Views: 644
Reputation: 38758
As markdown automatically loads approximately every package but the kitchen sink, it also loads the geometry
package. Hence you can use \setlength{\headsep}{0cm}
to change the space between the head rule and the text:
% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[
]{article}
\usepackage{amsmath,amssymb}
\usepackage{lmodern}
\usepackage{ifxetex,ifluatex}
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
\usepackage{unicode-math}
\defaultfontfeatures{Scale=MatchLowercase}
\defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
\usepackage[]{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\@ifundefined{KOMAClassName}{% if non-KOMA class
\IfFileExists{parskip.sty}{%
\usepackage{parskip}
}{% else
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
\KOMAoptions{parskip=half}}
\makeatother
\usepackage{xcolor}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\hypersetup{
hidelinks,
pdfcreator={LaTeX via pandoc}}
\urlstyle{same} % disable monospaced font for URLs
\usepackage[top=.5in, right=.75in, left=.75in, bottom = .5in]{geometry}
\usepackage{longtable,booktabs,array}
\usepackage{calc} % for calculating minipage widths
% Correct order of tables after \paragraph or \subparagraph
\usepackage{etoolbox}
\makeatletter
\patchcmd\longtable{\par}{\if@noskipsec\mbox{}\fi\par}{}{}
\makeatother
% Allow footnotes in longtable head/foot
\IfFileExists{footnotehyper.sty}{\usepackage{footnotehyper}}{\usepackage{footnote}}
\makesavenoteenv{longtable}
\usepackage{graphicx}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
% Set default figure placement to htbp
\makeatletter
\def\fps@figure{htbp}
\makeatother
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{-\maxdimen} % remove section numbering
\usepackage{fancyhdr}
\pagestyle{fancy}
\ifluatex
\usepackage{selnolig} % disable illegal ligatures
\fi
\author{}
\date{\vspace{-2.5em}}
\setlength{\headsep}{0cm}
\begin{document}
\setlength{\headheight}{144pt}
\renewcommand{\headrulewidth}{0pt}
\fancyhead[L]{%
\textbf{Here is my title}
}
\renewcommand\headrule{%
\begingroup
\vspace{2pt}
\color{blue}\hrule height 4.32pt width\headwidth
\vspace{2.16pt}
\color{red}\hrule height 4.32pt width\headwidth
\endgroup
}
\textbf{Name}\linebreak\textbf{ID}
\end{document}
Upvotes: 1