簡體   English   中英

在 flextable 標題中使用 Markdown

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM