r-markdown和kableExtra pdf输出出现错误

时间:2018-12-15 21:55:57

标签: r r-markdown bookdown kable kableextra

---
title: "test_kableExtra"
date: "14/12/2018"
output: 
  pdf_document:
    latex_engine: xelatex
    includes:
      in_header: head.tex
---

``` {r table, echo = FALSE}
library(tidyverse)
library(kableExtra)

table <- tibble(`Column title` = "lots of very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very long text ")

kable(table, booktabs = T, caption = "Table title") %>%
  kable_styling(full_width = F) %>%
  column_spec(1, width = "5cm")

```

More text...

在head.tex中:

\usepackage{float}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{array}
\usepackage{multirow}
\usepackage{wrapfig}
\usepackage{colortbl}
\usepackage{pdflscape}
\usepackage{tabu}
\usepackage{threeparttable}
\usepackage{threeparttablex}
\usepackage[normalem]{ulem}
\usepackage{makecell}

我收到错误! LaTeX Error: \caption outside float.

如果我删除caption = "Table title"

然后我得到这个输出

enter image description here

我不明白为什么:

  • 列宽未更改为5cm,

  • 为什么代码块后的文本居中

  • 为什么出现“ \ begin {tab ...”和“ \ end {table}”。

谢谢您的帮助!

0 个答案:

没有答案