Thesisdown:加载 huxtable 包和创建表时编织到 PDF 失败

Thesisdown: knitting to PDF fails when loading huxtable package and creating tables

我想在使用 thesisdow 创建的文档中使用 huxtable 包创建 tables包裹。编织到 html 与 HTML 配合得很好。但是,一旦在加载 huxtable:

后包含 table,编织 PDF 就会失败并出现以下错误
 ! LaTeX Error: Environment threeparttable undefined.

后台似乎与 LaTex 包发生冲突。 低于论文的 MWE index.file。 有趣的是,在一个简单的 markdown 文件中,编织到 html 和 PDF 都没有问题。 由于thesisdown是建立在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 总结:

更新:

(1) 如果使用 thesisdown,将 huxtable 所需的 LaTex 包包含在 YAML-header 中,如 @dash2 所建议的,效果很好。

(2) 但是,如果使用 huskydown,不幸的是问题仍然存在。

1. index.Rmd(论文下载)


    ---
    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(哈士奇)


    ---
    # 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 编织 index.Rmd 再次抛出错误:

 ! LaTeX Error: Environment threeparttable undefined.

加载了 header-includes 的任何 LaTex 包是否可能被 huskydown 忽略?

@dash2 推荐的解决方案:手动包含 LaTex 包

"LaTex packages loaded with header-includes ignored by huskydown?"——看来这个推定实际上是这样的。 因此,LaTex 包不能包含在 index.Rmd 文件的 YAML header 中。

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}