How to wrap columns in a rendered pdf table

47 Views Asked by At

I am trying to use Quarto to render a table created as a flextable into a PDF file. Some table columns are too long, and the text does not wrap when I try to render it to a pdf.

When I try to render the table into HTML, the text wraps. What can I do to render wrapped columns in pdf?

---
title: "How to wrap text of columns in a table?"
format: pdf
editor: visual
---

```{r}
#| label: load-packages
#| include: false
library(dplyr)
library(flextable)
```

```{r}
#| label: tbl-domains
#| tbl-cap: Table title
#| warning: false
#| echo: false

table_p <- tibble(P = c(1,2,3,4,5),
                  P_name = c('aaaaaa aaaaa aaaaaa aaaaa aaaaaa aaaaa aaaaaa aaaaa aaaaaa aaaaa', 'aaaaaa aaaaa', 'bb bbbbb', 'bb bbbbb', 'bb bbbbb'),
                  D_name = c('xxxx xxxx','yyyyyy y yy','zzzz zz','fffff fffffffff','ggggg gggggggggggggggg ggggg gggggggggggggggg ggggg gggggggggggggggg ggggg gggggggggggggggg'))

ft <- flextable(table_p)
ft <- set_header_labels(ft, P_name = "First", 
                        D_name = "Second" )
ft <- set_table_properties(ft, layout = "autofit", width = .8,
                           opts_pdf = list(tabcolsep = 5))
ft
```
0

There are 0 best solutions below