1

I am printing a table that contains _ characters with kable() in a quarto file using an HTML output and it is italicizing and/or bolding the output rather than printing the _ characters. How can I print the output as is rather than converting it into italicized and/or bolded text?

I messed around with

#| output: asis

and it just further messed up the formatting.

You can see the problem if you render this:

```{r}
blah <- data.frame(word = c("abcde", "a_c_e", "_b___", "__c__"))

blah |> 
  knitr::kable()
```
0

2 Answers 2

2

You could use the following trick: add the parse-latex filter and render the kable to LaTeX, i.e.

---
title: "Untitled"
format: html
filters: [parse-latex.lua]
---

```{r}
blah <- data.frame(word = c("abcde", "a_c_e", "_b___", "__c__"))
```

```{r}
#| layout-ncol: 2
#| tbl-subcap: ["HTML table", "LaTeX table"]

blah |> 
  knitr::kable()

blah |> 
  knitr::kable(format = "latex")
```

Result:

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

That is high quality magic. Thank you so much!
2

Kable generates raw HTML, which is then spliced back into the Markdown document. We can control at read time whether the contents of HTML elements should be parsed as Markdown or handled verbatim. For that, we'll have to disable the markdown_in_html_blocks Markdown extension:

---
from: 'markdown-markdown_in_html_blocks'
---

The cells should now be passed through without being interpreted as Markdown.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.