在灵活的标题中使用降价

Using markdown in flextable caption

我想在灵活的标题中使用粗体和斜体。我知道可以使用 ftExtra 包将字体样式应用于 flextable 的 header 或 body 中的文本,并且可以为 word 输出中的标题选择不同的输出样式officeR。但是这些要么不适用于标题 (ftExtra),要么不提供允许选择性应用粗体和斜体的样式。

这是一些代码,标题中包含预期的降价:

library(flextable)
library(dplyr)

iris[1:10,] %>% 
  flextable() %>% 
  set_caption(caption = "**Tab. 1:** First ten (*n* = 10) samples of the Iris species dataset")

标题应读作“Tab.1: 鸢尾花物种数据集的前十 (n = 10) 个样本”。 =15=]

更新

根据 dario 的评论,可能的解决方案是:

  library(flextable)
  library(dplyr)

  iris[1:10,] %>% 
  flextable() %>% 
  
  add_header_lines("") %>% 
  
  compose(
    i = 1, part = "header",
    value = as_paragraph(
      as_chunk("Table 1: ", props = fp_text(bold = TRUE)),
      as_chunk("First ten ("),
      as_chunk("n", props = fp_text(italic = TRUE)),
      as_chunk(" = 10) samples of the Iris species dataset")
    )
  )

非常感谢。最后,我需要在不同的章节中制作大约 20 个表格,因此我将尝试 David 的建议,在编写降价促销期间构建标题。但很高兴知道有办法,尽管使用 compose.

笨重且不灵活

我为你准备了markdown模板:

---
title: "Hello World"
header-includes:
- \usepackage{caption}

output:
  pdf_document: 
       latex_engine: xelatex
---

```{r, include = FALSE}
library(flextable)
library(dplyr)    
table2 <- flextable(mtcars[1:5, 1:6])        
```     
   
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

\begin{table}[hbtp]
\captionof{table}{Text of the caption.}
`r table2`
\end{table}

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

一个输出