如何:Markdown PDF 将 table 左对齐

How to: Markdown PDF align table to the left

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

系统及其他

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

删除 kable 中的 format = "markdown" 并将 library(kableExtra) 放在某处

在@Hao的帮助下解决了

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

2) 在 template.Rmd 中包含库 (kableExtra) 而不是在 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)