我根据来自不同银行的数据以及不同地点和角色的员工创建了一份文档。我的.Rmd文件如下:
---
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}"
))
```
我现在希望简单地改变表格的字体大小 - 它太大而且重叠成单独的页面。
是否可以这样做,因为我的最终输出是.pdf而我使用kable
来创建这些表?
谢谢。
答案 0 :(得分:11)
也许您可以试用kableExtra
套餐。要更改字体大小,您可以尝试
kable(x, "latex", booktabs = T) %>%
kable_styling(font_size = 7)
或者,您可以尝试使用scale_down
选项,该选项会使用LaTeX graphicx
包自动将表格缩放到页面宽度。
kable(x, "latex", booktabs = T) %>%
kable_styling(latex_options = "scale_down")
您可以在此处阅读完整的插图:http://haozhu233.github.io/kableExtra/awesome_table_in_pdf.pdf http://haozhu233.github.io/kableExtra/awesome_table_in_html.html