Thesisdown:加载huxtable包并创建表时,编织为PDF失败

时间:2019-08-24 11:37:25

标签: r bookdown

我想在使用 thesisdow 包创建的文档中使用 huxtable 包创建表。编织为 html 可以很好地与HTML结合使用。但是,在加载huxtable之后,一旦包含表格,就只能编织 PDF 而失败,并出现以下错误:

 ! LaTeX Error: Environment threeparttable undefined.

似乎与LaTex软件包在后台发生冲突。 在MWE下方,为thesisdown index.file。 有趣的是,在一个简单的markdown文件中,编织成html和PDF的文件都没有问题。 由于sisdown是基于bookdown的,因此将bookdown文件编织为PDF时也可能会发生错误。

index.Rmd


    ---
    knit: "bookdown::render_book"
    site: bookdown::bookdown_site
    output: 
     thesisdown::thesis_pdf: default
      # thesisdown::thesis_gitbook: default
    ---

    ```{r include_packages, include = FALSE}
    # Ensure that the thesisdown package is installed and loaded
    if(!require(devtools))
      install.packages("devtools", repos = "http://cran.rstudio.com")
    if(!require(thesisdown))
      devtools::install_github("ismayc/thesisdown")
    library(thesisdown)
    ```

    # Random Test Output - *before* calling "library(huxtable)"
    a table with pressure data
    ```{r pressure-table, echo=FALSE}
    pressure
    ```

    ```{r echo=FALSE}
    library(huxtable)
    ```

    # Random Test Output - *after* calling "library(huxtable)"
    a table with pressure data
    ```{r pressure-table2, echo=FALSE}
    pressure
    ```

MWE摘要:

  • 编织为HTML始终有效
  • 仅当“ library(huxtable)”之后没有任何表时,即未执行代码块“ pressure-table2”时,编织为PDF才有效

更新:

(1)如果与 thesisdown 一起使用,则将@ dash2提出的YAML标题中huxtable所需的LaTex软件包包括在内即可。

(2)但是,如果与 huskydown 一起使用,问题仍然存在。

1。 index.Rmd(thesisdown)


    ---
    knit: "bookdown::render_book"
    site: bookdown::bookdown_site
    output: 
     thesisdown::thesis_pdf: default
      # thesisdown::thesis_gitbook: default
    header-includes:
      - \usepackage{array}
      - \usepackage{caption}
      - \usepackage{graphicx}
      - \usepackage{siunitx}
      - \usepackage{colortbl}
      - \usepackage{multirow}
      - \usepackage{hhline}
      - \usepackage{calc}
      - \usepackage{tabularx}
      - \usepackage{threeparttable}
      - \usepackage{wrapfig}
    ---
    ...

2。 index.Rmd(huskydown)


    ---
    # UW thesis fields
    title: "My thesis title - edit in index.Rmd"
    author: "My Name"
    year: "2017"
    program: "My Department"
    chair: "Name of my committee chair"
    chairtitle: "Title of my chair"
    signature1: "person 1"
    signature2: "person 2"
    signature3: "person 3"
    abstract: |
      "Here is my abstract"
    acknowledgments: |
      "My acknowledgments"
    dedication: |
      "My dedication"
    knit: "bookdown::render_book"
    site: bookdown::bookdown_site
    output: 
      huskydown::thesis_pdf: 
        latex_engine: xelatex
    bibliography: bib/thesis.bib
    csl: csl/apa.csl
    lot: true
    lof: true
    header-includes:
      - \usepackage{tikz}
      - \usepackage{array}
      - \usepackage{caption}
      - \usepackage{graphicx}
      - \usepackage{siunitx}
      - \usepackage{colortbl}
      - \usepackage{multirow}
      - \usepackage{hhline}
      - \usepackage{calc}
      - \usepackage{tabularx}
      - \usepackage{threeparttable}
      - \usepackage{wrapfig}
    ---


    ```{r include_packages, include = FALSE}
    # This chunk ensures that the huskydown package is
    # installed and loaded. This huskydown package includes
    # the template files for the thesis.
    if(!require(devtools))
      install.packages("devtools", repos = "http://cran.rstudio.com")
    if(!require(huskydown))
      devtools::install_github("benmarwick/huskydown")
    library(huskydown)
    ```

    # Random Test Output - *before* calling "library(huxtable)"
    a table with pressure data
    ```{r pressure-table, echo=FALSE}
    pressure
    ```

    ```{r echo=FALSE}
    library(huxtable)
    ```

    # Random Test Output - *after* calling "library(huxtable)"
    a table with pressure data
    ```{r pressure-table2, echo=FALSE}
    pressure
    ```

尽管加载LaTex程序包,但仍编入索引。 huskydown 的Rmd再次引发错误:

 ! LaTeX Error: Environment threeparttable undefined.

huskydown 可能会忽略所有装有header-includes的LaTex软件包吗?

1 个答案:

答案 0 :(得分:1)

@ dash2建议的解决方案:手动包含LaTex软件包

“装有header-includes的LaTex软件包被huskydown忽略了吗?” -似乎实际上是这种假设。 因此,LaTex软件包不能包含在index.Rmd文件的YAML标头中。

huskydown论文模板包括文件“ template.tex”,该文件定义了文档类并提供了多个LaTex软件包。 将huxtable所需的所有LaTex软件包手动添加到此文件即可解决此问题:

 %-------------------------------
 % Huxtable
 %-------------------------------
 % load LaTex packages needed for huxtable 
 \usepackage{array}
 \usepackage{caption}
 \usepackage{graphicx}
 \usepackage{siunitx}
 \usepackage{colortbl}
 \usepackage{multirow}
 \usepackage{hhline}
 \usepackage{calc}
 \usepackage{tabularx}
 \usepackage{tabulary}
 \usepackage{threeparttable}
 \usepackage{wrapfig}