Rmarkdown 到 table 标题中的 docx less-than 符号
Rmarkdown to docx less-than symbol in table caption
我想在转换为 docx 文档的 Rmarkdown 的 table 标题中使用 <
符号。我正在使用 flextable
包,因为这为 docx 格式的 table 提供了很多(需要的)灵活性。
但是pandoc
的多个转换步骤让我很困惑。获得 <
似乎并不容易,因为它是一个特殊的编码 HTML 字符。我在 HTML 中读到过,您可以通过 <
转义它。这给了我 &
也必须转义的问题。然后转换将 <
转换为 &lt;
(因为它将 &
转换为 &
)并且 \<
会产生 &amp;lt;
(因为它转换又是 &
的 &
)。 Latex 似乎也不起作用,我试过 <
、$<$
和 $\textless$
但无济于事。
所有组合基本上遵循相同的逻辑,即 <
正确转换为 <
但随后 HTML 不会再次转换。
知道如何解决这个问题吗?我想念什么?
示例 RMD 文件:
---
title: "Untitled"
author: "Unkown"
date: "1/25/2021"
output: bookdown::word_document2
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(flextable)
library(tidyverse)
```
## R Markdown
This is an R Markdown document, see Table \@ref(tab:test).
```{r test, echo = F}
flextable(head(cars, n = 10)) %>%
bold(part = "header") %>%
autofit() %>%
set_caption("Table: (\#tab:test) Example caption with less-than symbol: \< or < or < or $<$ or $\textless$")
```
这应该可以回答标题中有关 <
和 >
的问题
---
title: "Untitled"
output: bookdown::word_document2
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(flextable)
library(tidyverse)
```
## R Markdown
This is an R Markdown document, see Table \@ref(tab:test).
```{r test, echo = F, tab.id="test"}
flextable(head(cars, n = 10)) %>%
bold(part = "header") %>%
autofit() %>%
set_caption("Example caption with less-than symbol: > and <")
```
您可以使用软件包 officedown。它会将引用作为真正的 Word 引用,它还提供了一些自定义标题的功能:
---
output:
bookdown::markdown_document2:
base_format: officedown::rdocx_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, tab.cap.style="Table Caption")
library(flextable)
library(tidyverse)
```
```{r test1}
flextable(head(cars, n = 10)) %>%
bold(part = "header") %>%
autofit() %>%
set_caption("Example caption with less-than symbol: > and <")
```
```{r "test2", tab.cap="Example caption with less-than symbol: > & <"}
flextable(head(cars, n = 10)) %>%
bold(part = "header") %>%
autofit()
```
\newpage
See \@ref(tab:test1).
See \@ref(tab:test2).
我想在转换为 docx 文档的 Rmarkdown 的 table 标题中使用 <
符号。我正在使用 flextable
包,因为这为 docx 格式的 table 提供了很多(需要的)灵活性。
但是pandoc
的多个转换步骤让我很困惑。获得 <
似乎并不容易,因为它是一个特殊的编码 HTML 字符。我在 HTML 中读到过,您可以通过 <
转义它。这给了我 &
也必须转义的问题。然后转换将 <
转换为 &lt;
(因为它将 &
转换为 &
)并且 \<
会产生 &amp;lt;
(因为它转换又是 &
的 &
)。 Latex 似乎也不起作用,我试过 <
、$<$
和 $\textless$
但无济于事。
所有组合基本上遵循相同的逻辑,即 <
正确转换为 <
但随后 HTML 不会再次转换。
知道如何解决这个问题吗?我想念什么?
示例 RMD 文件:
---
title: "Untitled"
author: "Unkown"
date: "1/25/2021"
output: bookdown::word_document2
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(flextable)
library(tidyverse)
```
## R Markdown
This is an R Markdown document, see Table \@ref(tab:test).
```{r test, echo = F}
flextable(head(cars, n = 10)) %>%
bold(part = "header") %>%
autofit() %>%
set_caption("Table: (\#tab:test) Example caption with less-than symbol: \< or < or < or $<$ or $\textless$")
```
这应该可以回答标题中有关 <
和 >
的问题
---
title: "Untitled"
output: bookdown::word_document2
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(flextable)
library(tidyverse)
```
## R Markdown
This is an R Markdown document, see Table \@ref(tab:test).
```{r test, echo = F, tab.id="test"}
flextable(head(cars, n = 10)) %>%
bold(part = "header") %>%
autofit() %>%
set_caption("Example caption with less-than symbol: > and <")
```
您可以使用软件包 officedown。它会将引用作为真正的 Word 引用,它还提供了一些自定义标题的功能:
---
output:
bookdown::markdown_document2:
base_format: officedown::rdocx_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, tab.cap.style="Table Caption")
library(flextable)
library(tidyverse)
```
```{r test1}
flextable(head(cars, n = 10)) %>%
bold(part = "header") %>%
autofit() %>%
set_caption("Example caption with less-than symbol: > and <")
```
```{r "test2", tab.cap="Example caption with less-than symbol: > & <"}
flextable(head(cars, n = 10)) %>%
bold(part = "header") %>%
autofit()
```
\newpage
See \@ref(tab:test1).
See \@ref(tab:test2).