【发布时间】:2017-09-13 16:06:42
【问题描述】:
我是 RMarkdown 和 LaTex 的初学者,虽然喜欢在 R 中创建报告!我已经拿起了一些代码来创建我所追求的确切 .pdf 报告,尽管在某些美学方面存在困难。
我的数据是机密的,但这里是使用内置 R 数据集的布局/确切数量的绘图和表格的副本。
---
title: <center> <h1>Call Centre Report</h1> </center>
mainfont: Arial
output:
pdf_document:
latex_engine: xelatex
sansfont: Arial
fig_crop: false
toc: true
classoption: landscape
fontsize: 14pt
geometry: margin=0.5in
header-includes:
- \usepackage{booktabs}
---
<style>
.main-container {
max-width: 1200px !important;
}
</style>
```{r global_options, R.options=knitr::opts_chunk$set(warning=FALSE, message=FALSE)}
```
\newpage
# Iris
```{r fig.width=18, fig.height=7, echo=FALSE, comment=" "}
library(ggplot2)
ggplot(data = iris, aes(x = Sepal.Length, y = Sepal.Width, colour = Species)) +
geom_point() +
theme_classic()
```
<br>
<br>
```{r, echo=FALSE, results='asis'}
library(knitr)
library(xtable)
t1 <- kable(subset(iris, Sepal.Length=="5.1", select = Petal.Length:Species),
format = "latex", booktabs = TRUE, row.names = FALSE)
t2 <- kable(subset(chickwts, feed=="horsebean", select = weight:feed),
format = "latex", booktabs = TRUE, row.names = FALSE)
t3 <- kable(subset(mtcars, gear=="4", select = disp:wt),
format = "latex", booktabs = TRUE, row.names = FALSE, digits=2)
cat(c("\\begin{table}[!htb]
\\begin{minipage}{.35\\linewidth}
\\centering",
t1,
"\\end{minipage}%
\\begin{minipage}{.35\\linewidth}
\\centering",
t2,
"\\end{minipage}%
\\begin{minipage}{.35\\linewidth}
\\centering",
t3,
"\\end{minipage}
\\end{table}"
))
```
我想整理以下内容,但不知道该怎么做:
- 将第 2 页上的
Iris标题设为粗体并居中,但将其保留为目录中的标题。- 将三个表格中的每个表格的标题加粗
- 将每个表格中的所有文本居中
- 删除表 1 中
1.7, 0.5, setosa之后的大间隙,从而删除该行中的其他表。
我们将不胜感激任何帮助或指向特定文档的链接。
更新
下面提供的答案效果很好,除了我的数据包含一个百分比列,RMarkdown 和 LaTeX 似乎不喜欢它。我已经用一些虚拟数据更新了我的代码,这与我的机密数据非常相似,希望可以解决这个错误。
谢谢!
---
title: <center> <h1>Call Centre Report</h1> </center>
mainfont: Arial
output:
pdf_document:
latex_engine: xelatex
sansfont: Arial
fig_crop: false
toc: true
classoption: landscape
fontsize: 14pt
geometry: margin=0.5in
header-includes:
- \usepackage{booktabs}
---
<style>
.main-container {
max-width: 1200px !important;
}
</style>
```{r global_options, R.options=knitr::opts_chunk$set(warning=FALSE, message=FALSE)}
```
\newpage
# Iris
```{r fig.width=18, fig.height=7, echo=FALSE, comment=" "}
library(ggplot2)
ggplot(data = iris, aes(x = Sepal.Length, y = Sepal.Width, colour = Species)) +
geom_point() +
theme_classic()
```
<br>
<br>
```{r, echo=FALSE, results='asis'}
library(knitr)
library(xtable)
# Create some dummy data
Data <- data.frame(Fruit = sample(c("Apple", "Orange"), 10, replace = TRUE),
Score = sample(1:10))
# Include percentage column
Data$Percentage <- (paste0(round(100 * Data$Score/100), "%"))
t1 <- kable({x <- subset(iris, Sepal.Length=="5.1", select = Petal.Length:Species);
names(x) <- sprintf("\\textbf{%s}", names(x))
x},
format = "latex", booktabs = TRUE, row.names = FALSE,
align = 'c', escape = FALSE)
t2 <- kable({x <- subset(chickwts, feed=="horsebean", select = weight:feed);
names(x) <- sprintf("\\textbf{%s}", names(x))
x},
format = "latex", booktabs = TRUE, row.names = FALSE,
align = 'c', escape = FALSE)
t3 <- kable({x <- subset(Data, Fruit=="Apple", select = Score:Percentage);
names(x) <- sprintf("\\textbf{%s}", names(x))
x},
format = "latex", booktabs = TRUE, row.names = FALSE,
align = 'c', escape = FALSE)
cat(c("\\begin{table}[!htb]
\\begin{minipage}{.35\\linewidth}
\\centering",
t1,
"\\end{minipage}%
\\begin{minipage}{.35\\linewidth}
\\centering",
t2,
"\\end{minipage}%
\\begin{minipage}{.35\\linewidth}
\\centering",
t3,
"\\end{minipage}
\\end{table}"
))
```
【问题讨论】: