可折叠桌子周围的多个bookdown/rmarkdown/knitr问题

可折叠桌子周围的多个bookdown/rmarkdown/knitr问题,r,rstudio,knitr,r-markdown,bookdown,R,Rstudio,Knitr,R Markdown,Bookdown,在RStudio中,我试图将rmarkdown与(主要用于引用表格和图形的功能)结合使用,但在表格和标题中的格式设置方面遇到了麻烦。请考虑以下例子: --- title: "Test" knit: "bookdown::render_book" output: bookdown::pdf_book: keep_tex: yes link-citations: true references: - type: article-journal

在RStudio中,我试图将rmarkdown与(主要用于引用表格和图形的功能)结合使用,但在表格和标题中的格式设置方面遇到了麻烦。请考虑以下例子:

---
title: "Test"
knit: "bookdown::render_book"
output:
  bookdown::pdf_book:
    keep_tex: yes
link-citations: true
references:
- type: article-journal
  id: WatsonCrick1953
  author:
  - family: Watson
    given: J. D.
  - family: Crick
    given: F. H. C.
  issued:
    1953
  title: 'Molecular structure of nucleic acids: a structure for     deoxyribose
nucleic acid'
  container-title: Nature
  volume: 171
  issue: 4356
  page: 737-738
---
```{r setup, include=FALSE}
library(knitr)
opts_chunk$set(echo = TRUE)
```
@WatsonCrick1953
```{r test-table, tidy=FALSE, echo = FALSE}
kable(
  data.frame(
    Citation = c("@WatsonCrick1953"),
    Formatted.String = c("Some--Thing^2^")),
  caption = "*Bold* in a caption;"#, booktabs = TRUE
)
```
结果产品的详细信息如下:

这有多个问题:

  • 标题中的“粗体”不是rmarkdown格式
  • “^2^”没有生成预期的上标(特别奇怪,因为“-”被理解为破折号)
  • 表格中未理解引用(在文本中,表格代码上方,它工作正常,但未包含在屏幕截图中)
  • 另一个问题是,当前生成的latex没有生成对“booktabs”包的引用,这可能是正确使用kable的“booktabs=TRUE”参数所必需的(它直接来自booktabs文档,因此应该可以工作)

    请让我知道如何才能实现我正在努力的目标


    Joh

    由于您正在编织PDF,因此
    kable()
    的输出将自动检测到这一点,并进行格式化以生成乳胶

    因此,您需要使用latex指令来格式化文本

    试试这个:

  • 将区块选项设置为
    results='asis'
  • 使用
    \\textbf{}
    生成粗体
  • 例如:

    ```{r test-table, tidy=FALSE, echo = FALSE, results='asis'}
    library(knitr)
    kable(
      data.frame(
        Citation = c("@WatsonCrick1953"),
        Formatted.String = c("Some--Thing^2^")),
      caption = "\\textbf{Bold} in a caption -- ;"
    
    )
    ```
    

    切换到
    pander
    可以达到以下目的:

    ---
    title: "Test"
    knit: "bookdown::render_book"
    output:
      bookdown::pdf_book:
        keep_tex: yes
    link-citations: true
    references:
    - type: article-journal
      id: WatsonCrick1953
      author:
      - family: Watson
        given: J. D.
      - family: Crick
        given: F. H. C.
      issued:
        1953
      title: 'Molecular structure of nucleic acids: a structure for deoxyribose nucleic acid'
      container-title: Nature
      volume: 171
      issue: 4356
      page: 737-738
    ---
    ```{r setup, include=FALSE}
    library(knitr)
    opts_chunk$set(echo = TRUE)
    library(pander)
    ```
    @WatsonCrick1953
    ```{r test-table, tidy=FALSE, echo = FALSE}
    pander(
      data.frame(
      Citation = c("@WatsonCrick1953"),
      Formatted.String = c("Some--Thing^2^")),
      caption = "*Not bold* in a caption; **bold** in a caption;",
      style = "simple",
      justify = "left"
    )
    ```
    
    结果如下:

  • 标题格式很明显
  • 正确理解“^2^”等
  • 引用的效果很好
    我很高兴找到这篇文章,尽管我无法复制安德里的答案。我想补充一点,通过修改标题,也可以使用
    pander
    引用表格:
    caption=“(\\\\\\选项卡:测试表格)*标题中不加粗*;标题中**加粗*”,

    我修改了代码以生成一篇文章pdf文档而不是一本书,此代码适用于我:

    ---
    title: "Test"
    output:
      bookdown::pdf_document2:
        keep_tex: yes
    link-citations: true
    references:
    - type: article-journal
      id: WatsonCrick1953
      author:
      - family: Watson
        given: J. D.
      - family: Crick
        given: F. H. C.
      issued:
        1953
      title: 'Molecular structure of nucleic acids: a structure for deoxyribose nucleic acid'
      container-title: Nature
      volume: 171
      issue: 4356
      page: 737-738
    ---
    ```{r setup, include=FALSE}
    library(knitr)
    opts_chunk$set(echo = TRUE)
    library(pander)
    ```
    
    @WatsonCrick1953 in Table \@ref(tab:test-table)
    
    ```{r test-table, tidy=FALSE, echo = FALSE}
    pander(
      data.frame(
      Citation = c("@WatsonCrick1953"),
      Formatted.String = c("Some--Thing^2^")),
      caption = "(\\#tab:test-table) *Not bold* in a caption; **bold** in a caption;",
      style = "simple",
      justify = "left"
    )
    ```
    

    谢谢你的评论。“\\textbf{}”位确实可以工作,尽管这是以可移植性(无html)为代价的,这很烦人。但是,表的内部格式(上标和引用)在bookdown上下文中不起作用……正如建议的那样,`header includes:-\usepackage{booktabs}`解决了booktabs问题。您对以下问题是否也有一些建议:?非常感谢!