Bookdown pdf_book not respecting markdown italics

Hi everyone,

I'd like to insert a knitr::kable table into a bookdown document that I'm rendering to pdf_book. However, it appears that the *asterisk* and _underscore_ markdown methods for italicizing text aren't respected during the render.

Here's my example:

---
title: "test"
output:
  bookdown::pdf_book:
    keep_tex: yes
---
knitr::opts_chunk$set(echo = TRUE)
df <- data.frame(Standard = "This is standard",
                    Italics = "*This piece* should be in italics")

knitr::kable(
  df, booktabs = TRUE,
  caption = 'Testing italics using kable'
)

Here's the output:

You can get the markdown italic tags interpreted properly by adding format="markdown" as an argument to kable.

knitr::kable(
  df, format="markdown",
  booktabs = TRUE, 
  caption = 'Testing italics using kable'
)

Another option would be to use latex markup instead. That also requires adding the escape=FALSE argument to kable.

df <- data.frame(Standard = "This is standard",
                 Italics = "\\emph{This piece} should be in italics")

knitr::kable(
  df, booktabs = TRUE, escape=FALSE,
  caption = 'Testing italics using kable'
)
1 Like

Nailed it, thank you!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.