I have a document that I create, based on data from different banks and for staff across different locations and roles. My .Rmd file is as follows:
---
title: <center> <h1>Output Report</h1> </center>
mainfont: Arial
output:
pdf_document:
latex_engine: xelatex
sansfont: Arial
fig_crop: false
toc: true
classoption: landscape
fontsize: 11pt
geometry: margin=0.45in
header-includes:
- \usepackage{booktabs}
- \usepackage{sectsty} \sectionfont{\centering}
- \renewcommand{\contentsname}{}\vspace{-2cm}
---
<style>
.main-container {
max-width: 1200px !important;
}
</style>
```{r load myData, include=FALSE}
load("C:/Desktop/RawData.RData")
```
```{r global_options, R.options=knitr::opts_chunk$set(warning=FALSE, message=FALSE)}
```
\newpage
# Client One
```{r fig.width=18, fig.height=6, echo=FALSE, comment=" "}
library(ggplot2)
ggplot(subset(Durations, Client == "Client One")) +
aes(x = NumStart, y = Value) +
geom_rect(aes(xmin = NumStart, xmax = NumEnd,
ymin = 0, ymax = 0.8,
fill = Position)) +
geom_text(data=Inv[Inv$Client == "Client One",],
aes(x = Median, y = Value,
label = Symbol),
size = 4.5) +
scale_fill_manual(values=myColors) +
scale_x_continuous(expand = c(0.015, 0.015)) +
scale_y_continuous(expand = c(0, 0),limits = c(0, 0.8),
labels = c("F50", "FMID", "DMID", "D50"),
breaks = c(0.1, 0.3, 0.5, 0.7)) +
theme_classic() +
theme(legend.position = "bottom",
legend.title = element_blank(),
legend.key.size = unit(1.25, 'lines'),
legend.text = element_text(size = 12, colour = "black", face = "bold"),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
axis.text.y = element_text(face = "bold", size = 15, colour = "black"),
axis.text.x = element_text(face = "bold", colour = "black", size = 10),
axis.ticks.y = element_blank(),
axis.line.y = element_blank(),
panel.spacing = unit(0.5, "lines"),
strip.text = element_text(color = "black", size = 15, face = "bold")) +
facet_wrap(~ Bank, nrow = 1, scales = "free_x")
```
<br>
<br>
<br>
<br>
```{r, echo=FALSE, results='asis'}
library(knitr)
library(xtable)
t1 <- kable({x <- subset(Inv_Location, Client=="Client One", select = Location:DE);
names(x) <- sprintf("\\textbf{%s}", names(x))
x},
format = "latex", booktabs = TRUE, row.names = FALSE,
align = 'c', escape = FALSE)
t2 <- kable({x <- subset(Inv_Role, Client == "Client One", select = Role:DE);
names(x) <- sprintf("\\textbf{%s}", names(x))
x},
format = "latex", booktabs = TRUE, row.names = FALSE,
align = 'c', escape = FALSE)
t3 <- kable({x <- subset(Inv_ByRotation, Client == "Client One", select = Rotation:IPM);
names(x) <- sprintf("\\textbf{%s}", names(x))
x},
format = "latex", booktabs = TRUE, row.names = FALSE,
align = 'c', escape = FALSE)
t4 <- kable({x <- subset(Season_InvByLocation, Client == "Client One", select = Location:DE);
names(x) <- sprintf("\\textbf{%s}", names(x))
x},
format = "latex", booktabs = TRUE, row.names = FALSE,
align = 'c', escape = FALSE)
t5 <- kable({x <- subset(Season_InvByRole, Client == "Client One", select = Role:DE);
names(x) <- sprintf("\\textbf{%s}", names(x))
x},
format = "latex", booktabs = TRUE, row.names = FALSE,
align = 'c', digits = 2, escape = FALSE)
cat(c("\\begin{table}[!htb]
\\centering
\\begin{minipage}{.20\\linewidth}
\\centering
\\textbf{Bank - By Location}
\\centering",
t1,
"\\end{minipage}%
\\centering
\\begin{minipage}{.35\\linewidth}
\\centering
\\textbf{Bank - By Role}",
t2,
"\\end{minipage}%
\\centering
\\begin{minipage}{.25\\linewidth}
\\centering
\\textbf{Bank - By Rotation}",
t3,
"\\end{minipage}
\\end{table}"
))
cat(c("\\begin{table}[!htb]
\\centering
\\begin{minipage}{.25\\linewidth}
\\centering
\\textbf{Bank - By Location }",
t4,
"\\end{minipage}%
\\centering
\\begin{minipage}{.35\\linewidth}
\\centering
\\textbf{Bank - By Role}",
t5,
"\\end{minipage}
\\end{table}"
))
```
I now wish to simply change the font size of the tables - it is simply too big and overlapping into seperate pages.
Is it possible to do this, given my end output is a .pdf and I am using kable
to create these tables?
Thank you.
Change the font size of a piece of text using these commands, from the largest to the smallest: \Huge, \huge, \LARGE, \Large, \large, \normalsize, \small, \footnotesize, \scriptsize, and \tiny. Set the font size of the whole document by adding an option to the \documentclass command.
To change the font size, you don't need to know a lot of html for this. Open the html output with notepad ++. Control F search for "font-size". You should see a section with font sizes for the headers (h1, h2, h3,...).
Go to the menu in RStudio and click on Tools and then Global Options. Select the Appearance tab on the left. Again buried in the middle of things is the font size. Change this to 14 or 16 to start with and see what it looks like.
The RMarkdown output is based on LaTeX, and the default LaTeX font is Computer Modern. You will need to download and install the font on your computer. The CMU Serif version of this font is probably the one you want.
Maybe you can try out the kableExtra
package. To change font size, you can try
kable(x, "latex", booktabs = T) %>%
kable_styling(font_size = 7)
Or, you can try to use the scale_down
option, which will automatically scale the table to page width using the LaTeX graphicx
package.
kable(x, "latex", booktabs = T) %>%
kable_styling(latex_options = "scale_down")
You can read the full vignette here: http://haozhu233.github.io/kableExtra/awesome_table_in_pdf.pdf http://haozhu233.github.io/kableExtra/awesome_table_in_html.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With