I am new to markdown and want to produce pdf files with the university (and other) logo on each page. I tried to use fancyheadings, and I have a problem:
Putting the image in the headings works only if I call the image in the document, otherwise the pdf is not produced
NB: I also had to set the heading height otherwise the page 2 would not work with - \setlength{\headheight}{2.4 cm}.
Any suggestions were the problem is?
(using knit in Rstudio, all freshly installed)
---
title: "Test"
author: "Author Name"
header-includes:
- \usepackage{fancyhdr}
- \usepackage{lipsum}
- \pagestyle{fancy}
- \rhead {\includegraphics{pictures/headers.pdf}}
- \fancyfoot[CO,CE]{}
- \setlength{\headheight}{2.4 cm}
- \fancyfoot[LE,RO]{\thepage}
geometry: top=2cm, bottom=3cm
output: pdf_document
abstract: This is a pandoc test . . .
---
\lipsum[1-20]
![](./pictures/headers.pdf)
this line needed or it doesnot make an output ???
\cleardoublepage
This is an R Markdown document.
the includegraphics works only if there is a picture in the document, maybe because of the latex template (?).
A solution is to create a cache picture (1white pixel picture) and call it at the end of the code:
Related
I have been looking for a solution for this problem :
I'm using python ReportLab canvas to generate overlay(watermark) document from source document
and merge it into source pdf document (with PyPDF2).
Summary i have two landscape-oriented A0 single pages pdfs.
I want to overlay(watermarking) them in a manner that the resulting single page pdf contains both pages merged,
but with the same denisity.
But result (merged) document contains watermark that were rotated by 90 against source document
print(source.rect.width, source.rect.height) giving next result 5102.0 2384.0
but
print(source.mediabox.width, source.mediabox.height) giving next result 2384.0 5102.0
Problem that Source document looks landscape-oriented on devices and printers but
has structure in pdf :
Rotate 90
MediaBox [ 0 0 2384 5102 ]
watermark page has next structure in pdf
MediaBox [ 0 0 5102 2384 ]
Rotate 0
You can change the rotation of a page to 0 whilst counter-rotating its dimensions and page content to compensate - resulting in a visually-unchanged file - using cpdf's -upright operation:
cpdf -upright in.pdf -o out.pdf
Preprocessing your files in this manner should let your overlay function operate as expected.
I have a rmarkdown document where I import a few PDFs, and I would like to display four PDF-import-pages per page in my knitted PDF.
---
title: "combinePages"
author: "xxx"
date: '2022-xx-xx'
output:
pdf_document:
toc: true
header-includes:
- \usepackage{pdfpages}
---
\includepdf[pages={-}]{pdfs/Lecture1.pdf}
\includepdf[pages={-}]{pdfs/Lecture2.pdf}
Can this be done in rmarkdown?
According to the manual of pdfpages,
nup => Puts multiple logical pages onto each sheet of paper. The syntax of this option is: nup=⟨xnup⟩x⟨ynup⟩. Where ⟨xnup⟩ and ⟨ynup⟩ specify the umber of logical pages in horizontal and vertical direction, which are arranged on each sheet of paper. (Default: nup=1x1)
So, four pdf pages from an imported pdf file can be knitted per page using nup=2x2 in the option of \includepdf.
---
title: "combinePages"
author: "xxx"
date: '2022-xx-xx'
output:
pdf_document:
toc: true
header-includes:
- \usepackage{pdfpages}
---
## Multiple Page
\includepdf[pages={1-}, nup=2x2]{lorem_ipsum.pdf}
\includepdf[pages={1-}, nup=2x2]{lorem_ipsum.pdf}
So A page of the rendered document looks like this,
Explore the manual for more options.
I'm getting a weird error that I can't seem to understand. I have an rMarkdown file with a mixture of code, tables, and plain text (in RStudio).
I want to knit to PDF. I am able to do this, but only if I've deleted the cache folder. If the cache has been created, I get the following error when trying to do subsequent knits:
! LaTeX Error: Illegal character in array arg.
This is especially confusing as it always works the first time, and the PDF output looks exactly as I want it to. My code components are set to "cache=TRUE", because it's a big file and I want to cut down on loading time. I've looked up what that error means, but I can't find anything on how it relates to the cache.
If it's of any use, this is my header:
---
output:
pdf_document:
toc: yes
toc_depth: 4
number_sections: no
fig_caption: yes
latex_engine: xelatex
mainfont: Helvetica
font-family: Helvetica Neue
fontsize: 11pt
geometry: left=35mm, right=20mm, top=30mm, bottom=30mm
bibliography: resources/refs.bib
csl: resources/apa.csl
header-includes:
- \usepackage{fancyhdr} # Latex package for formatting PDFs.
- \pagestyle{fancy} # Set page style.
- \renewcommand{\headrulewidth}{1.5pt} # Thickness of header line.
- \setlength{\headheight}{13.59999pt} # Ensures consistent space between header line and text.
- \renewcommand{\href}[2]{#2\footnote{\url{#1}}} # Show URLs in footnote.
---
I can't directly share my data, but the setup for one of my tables looks like this:
exp2_age_gender_table %>%
kable("latex", booktabs = T) %>%
kable_styling(latex_options = "hold_position") %>%
column_spec(2, italic = TRUE) %>%
column_spec(4, italic = TRUE) %>%
row_spec(5, bold = TRUE)
The list of files contained in the created cache folder:
load-packages_0e5c21f97bd6e3c6091073c85b87d490.rdb
__packages
exp2-age-gend-table_009cc9300f71eb94b8251a5ed005e883.RData
exp2-age-gend-table_009cc9300f71eb94b8251a5ed005e883.rdb
exp2-age-gend-table_009cc9300f71eb94b8251a5ed005e883.rdx
exp2-age-gend-table-data_fc15cdaa97d5a922fc695858c44a93ac.RData
exp2-age-gend-table-data_fc15cdaa97d5a922fc695858c44a93ac.rdb
exp2-age-gend-table-data_fc15cdaa97d5a922fc695858c44a93ac.rdx
load-packages_0e5c21f97bd6e3c6091073c85b87d490.RData
load-packages_0e5c21f97bd6e3c6091073c85b87d490.rdx
raw-data_d44409d75a5aed8718bc355ff7b167fc.RData
raw-data_d44409d75a5aed8718bc355ff7b167fc.rdb
raw-data_d44409d75a5aed8718bc355ff7b167fc.rdx
My header looks as follows and works perfectly as intended:
---
header-includes:
- \usepackage{float}
- \usepackage{wrapfig}
- \usepackage{graphicx}
- \usepackage[fontsize=12pt]{scrextend}
- \usepackage{fontspec}
- \renewcommand*{\bibfont}{\footnotesize}
- \usepackage[dvipsnames]{xcolor}
output:
pdf_document:
latex_engine: xelatex
fig_caption: true
citation_package: biblatex
bibliography: SPP.bib
mainfont: ArialMT
geometry: margin=0.75in
---
However, the reference section already gets populated by the section name "References". Is there a way to stop that automated insertion? Thanks.
The "References" section is automatically included if you define a bibliography. Here an excerpt from the template:
$if(biblatex)$
\printbibliography$if(biblio-title)$[title=$biblio-title$]$endif$
$endif$
Do you only want to change "References" into something else. Then it would be sufficient to add biblio-title: ... to you YAML header. If you want to suppress it completely, you have remove the quoted part in a copy of the template and use this copy instead. You can find the location where the template is stored via:
system.file("rmd", "latex", package = "rmarkdown")
#> [1] "/usr/lib/R/site-library/rmarkdown/rmd/latex"
Typically there are several files there:
list.files(system.file("rmd", "latex", package = "rmarkdown"))
#> [1] "default-1.14.tex" "default-1.15.2.tex" "default-1.17.0.2.tex"
#> [4] "default.tex"
The one with the highest version number (here default-1.17.0.2.tex) is used.
I'm creating an R Markdown document which outputs a PDF document. My YAML header is the following:
---
title: "Introduction"
author: "John Doe
date: "August 26, 2018"
mainfont: Pancetta Pro
documentclass: book
output:
pdf_document:
number_sections: true
df_print: kable
fig_caption: yes
fig_width: 6
highlight: tango
includes:
in_header: preamble.tex
latex_engine: xelatex
geometry: headheight=25pt, tmargin=25mm, bmargin=20mm, innermargin=20mm, outermargin=20mm
---
In the preamble.tex file I want to have the following LaTeX commands (which just modify the way the headers are displayed):
\renewcommand{\chaptermark}[1]{\markright{#1}}
\renewcommand{\sectionmark}[1]{}
\renewcommand{\subsectionmark}[1]{}
\usepackage{titlesec}
\titleformat{\chapter}[hang]{\Huge}{\bfseries\thechapter}{0.2pt}{\thicklines\thehook}[\vspace{0.5em}]
However, when these last lines are included in the preamble.tex I get an error when knitting the R Markdown file:
! Argument of \paragraph has an extra }.
<inserted text>
\par
l.1290 \ttl#extract\paragraph
Error: Failed to compile Template.tex
I can't figure out why it won't run. The contents of thepreamble.texfile are the following:
% !TeX program = lualatex
\usepackage{relsize} % To make math slightly larger.
\newcommand{\thehook}{%
\hspace{.5em}%
\setlength{\unitlength}{1em}%
\raisebox{-.5em}{\begin{picture}(.4,1.7)
\put(0,0){\line(1,0){.2}}
\put(.2,0){\line(0,1){1.7}}
\put(.2,1.7){\line(1,0){.2}}
\end{picture}}%
\hspace{0.5em}%
} %This creates the "hook" symbol at the beginning of each chapter.
\usepackage{anyfontsize}
\usepackage{fontspec}
\setmainfont{Pancetta Pro}
% We set the font for the chapters:
\newfontfamily\chapterfont{Pancetta Pro}
% And now for the sections:
\newfontfamily\sectionfont{Pancetta Pro}
\usepackage{fancyhdr}
\fancyhead{}
\fancyfoot{}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\fancyhead[RO]{\large\sffamily\rightmark\thehook\textbf{\thepage}}
\fancyhead[LE]{\large\sffamily\textbf{\thepage}\thehook\rightmark}
\fancypagestyle{plain}{%
\fancyhf{}
}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markright{#1}}
\renewcommand{\sectionmark}[1]{}
\renewcommand{\subsectionmark}[1]{}
\fontsize{12}{20}\selectfont
\usepackage{titlesec}
\titleformat{\chapter}[hang]{\Huge}{\bfseries\thechapter}{0.2pt}{\thicklines\thehook}[\vspace{0.5em}]
When excluding the last 6 lines in the previous code there's no error and the pdf is created.
If you want to use titlesec together with rmarkdown you have to add
subparagraph: yes
to your YAML headers, c.f. several other answers.
The default LaTeX class used by rmarkdown is article, which has no chapters. You should add
documentclass: report
or
documentclass: book
to your YAML header.