So, I am on a project, where the user can select an option and the output pdf should be generated accordingly as a pdf report. The Shiny app does work well and the pdf report too. I would like to just go one step further and customize the pdf report’s styling to make it visually more attractive. To that end, I am pretty much using a similar customized pdf styling that I found online. However, I am having difficulty to apply the customized pdf style, written in .tex
, to the dynamic pdf report made with RMarkdown
. So, here is a sample code from the R Markdown document;
---
title: "`r unique(data_selected$aaa)` - AAA"
subtitle: BBB
geometry: margin=1in
output:
pdf_document:
latex_engine: xelatex
fig_caption: true
keep_tex: true
includes:
in_header: pdf_report_styling.tex
---
# Header 1
some text here
`{r aaa}
data <- read_excel("data.xlsx")
data_selected <- data %>%
filter(aaa == data$aaa)
table_gt <- data_selected %>%
gt() %>%
tab_style(style = list(cell_fill(color = "lightgray")),
locations = cells_body(columns = everything())
)
table_gt
And the .tex
file I am using to customize my pdf report is this;
% load packages
usepackage{geometry}
usepackage{xcolor}
usepackage{eso-pic}
usepackage{fancyhdr}
usepackage{sectsty}
usepackage{fontspec}
usepackage{titlesec}
%% Set page size with a wider right margin
geometry{a4paper, total={170mm,257mm}, left=20mm, top=20mm, bottom=20mm, right=50mm}
%% Let's define some colours
definecolor{light}{HTML}{D3D3D3}
definecolor{highlight}{HTML}{800080}
definecolor{dark}{HTML}{330033}
%% Let's add the border on the right hand side
AddToShipoutPicture{%
AtPageLowerLeft{%
put(LenToUnit{dimexprpaperwidth-3cm},0){%
color{light}rule{3cm}{LenToUnitpaperheight}%
}%
}%
% logo
}
%% Style the page number
fancypagestyle{mystyle}{
fancyhf{}
renewcommandheadrulewidth{0pt}
fancyfoot[R]{thepage}
fancyfootoffset{3.5cm}
}
setlength{footskip}{20pt}
%% style the chapter/section fonts
chapterfont{color{dark}fontsize{20}{16.8}selectfont}
sectionfont{color{dark}fontsize{20}{16.8}selectfont}
subsectionfont{color{dark}fontsize{14}{16.8}selectfont}
titleformat{subsection}
{sffamilyLargebfseries}{thesection}{1em}{}[{titlerule[0.8pt]}]
% left align title
makeatletter
renewcommand{maketitle}{bgroupsetlength{parindent}{0pt}
begin{flushleft}
{sffamilyhugetextbf{MakeUppercase{@title}}} vspace{0.3cm} newline
{Large {@subtitle}} newline
@author
end{flushleft}egroup
}
makeatother
%% Use some custom fonts
setsansfont{Ubuntu}[
Path = fonts/Ubuntu/,
Scale = 0.9,
Extension = .ttf,
UprightFont = *-Regular,
BoldFont = *-Bold,
ItalicFont = *-Italic,
]
setmainfont{keplerstd}[
Path = fonts/keplerstd/,
Scale = 0.9,
Extension = .ttf,
UprightFont = garr45w,
BoldFont = bold,
ItalicFont = italic
]
When the dynamic pdf report is tried to be generated the following error occurs;
! LaTeX Error: There's no line here to end.
I appreciate any comments and suggestions to fix the issue. Thank you for your kind attention beforehand.