作法:在左侧Markdown PDF对齐表格

时间:2018-07-10 07:16:46

标签: pdf markdown pandoc tex

目标 我一直想创建一个pdf报告功能,但是我无法按照自己的意愿重新设置pdf的样式。我要解决的问题之一是无法将表格向左对齐。现在它居中。

系统和其他

  • CentOS 6.9版(最终版)
  • TeX 3.141592(Web2C 7.5.6)

template.Rmd

---
title: "Reporting"
output: pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r, results='asis', echo=FALSE}
knitr::kable(head(cars), format = "markdown") %>%
  kable_styling(bootstrap_options = "striped", full_width = F, position = "left")
```

build_report.R

# Libraries
require(knitr)
require(markdown)
library(RMySQL)
library(png)
library(kableExtra)

# create .md file
knit("template.Rmd", "template.md")

# create .html file
markdownToHTML("template.md", "template.html", options=c("use_xhml"))

# create .pdf file
command <- paste0("pandoc -V geometry:'left=0.5in,bottom=1in,top=1.5in' -s ", "template.html", " -o ", "output.pdf")
system(command)

output.pdf 输出示例(忽略了无关信息)1

2 个答案:

答案 0 :(得分:0)

format = "markdown"中的kable移到library(kableExtra)

答案 1 :(得分:0)

可以在@Hao的帮助下解决它

1)从.Rmd到.md直接转换为PDF,省略markdownToHTML()

2)将库(kableExtra)包含在 template.Rmd 中,而不包含在 build_report.R

3)使用格式=“ markdown”

template.Rmd

---
title: "Reporting"
output: pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r, results='asis', echo=FALSE}
knitr::kable(head(cars), format = "markdown") %>%
  kable_styling(bootstrap_options = "striped", full_width = F, position = "left")
```

build_report.R

# Libraries
require(knitr)
require(markdown)
library(RMySQL)
library(png)
library(kableExtra)

# create .md file
knit("template.Rmd", "template.md")

# create .pdf file
command <- paste0("pandoc -V geometry:'left=0.5in,bottom=1in,top=1.5in' -s ", "template.md", " -o ", "output.pdf")
system(command)