I would like to use the <
symbol in a table caption of a Rmarkdown that converts to a docx document. I am using the flextable
package as this gives a lot of (needed) flexibility to tables in the docx format.
But I am really confused by the multiple conversion steps through pandoc
. It does not seem so easy to get to the <
as it is a special coding HTML character. I have read that in HTML you would escape it via <
. This gives me the problem that the &
has to be escaped, too. The conversion then turns <
into &lt;
(as it converts the &
into &
) and \\<
would yield me &amp;lt;
(as it converts the &
of the &
again). Latex does not seem to work either, I've tried <
, $<$
and $\\textless$
but to no avail.
All combinations basically follow the same logic, i.e. that <
are correctly transformed to <
but then the HTML is not converted again.
Any idea how to solve this? What do I miss?
Example RMD file:
---
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$")
```
set_caption("Table: (\\#tab:test) ... < or >", html_escape = FALSE)
. Also make sure you are using the latest version as there were some fixes about your issue 2/3 releases before the current one (0.6.2) – David Gohelhtml_escape
works in docx, too! Thanks as well for the update suggestions, I will check the version(s) I'm running. – bampheTable: (\\#tab:test)
part printingTable Table 1:
? If I change anything it is does not understand the label at all though... – bamphetab.id="test"
– David Gohel