[英]Using markdown in flextable caption
我想在灵活的标题中使用粗体和斜体。 我知道可以使用ftExtra
包将字体样式应用于 flextable 的标题或正文中的文本,并且可以为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")
标题应为“表 1:鸢尾属物种数据集的前十个 ( n = 10) 个样本”
更新
根据 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
笨重且不灵活。
我为你准备了一个降价模板:
---
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:
一个输出
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.