如何:Markdown PDF 将表格左对齐

And*_*rie 5 pdf markdown tex pandoc

目标 我一直想创建一个 pdf 报告功能,但我无法按照我的意愿重新设计 pdf 的布局。我要解决的问题之一是我无法将表格左对齐。现在它位于中间。

系统及其他

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

模板.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")
```
Run Code Online (Sandbox Code Playgroud)

构建报告.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)
Run Code Online (Sandbox Code Playgroud)

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

And*_*rie 1

可以在@Hao的帮助下解决

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

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

3)使用格式=“markdown”

模板.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")
```
Run Code Online (Sandbox Code Playgroud)

构建报告.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)
Run Code Online (Sandbox Code Playgroud)