Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap-text doesn't work when rows are collapsed and rendered as PDF through Quarto #752

Open
russ-dvm opened this issue May 2, 2023 · 1 comment

Comments

@russ-dvm
Copy link

russ-dvm commented May 2, 2023

Hello,

I am rendering a table in a PDF file using Quarto. If there is text is a row that is collapsed, it doesn't wrap properly when the column_spec width is specified. The table that I am trying to create has several columns and will overflow the page if the text in the first column is not wrapped.

Below is an example - I hope I have provided it in a useful way.

---
title: "test"

format:
  html:
    theme: cosmo
  pdf:
    documentclass: scrreprt
    include-in-header: 
      text: |
        \usepackage{booktabs}
        \usepackage{longtable}
        \usepackage{array}
        \usepackage{multirow}
        \usepackage{wrapfig}
        \usepackage{float}
        \usepackage{colortbl}
        \usepackage{pdflscape}
        \usepackage{tabu}
        \usepackage{threeparttable}
        \usepackage{threeparttablex}
        \usepackage[normalem]{ulem}
        \usepackage{makecell}
        \usepackage{xcolor}
  docx: default
editor: visual
---

```{r, echo = F, message = F, warning=F}

text_tbl <- data.frame(
    Items = c("Really really really really long column item here 1", "Really really really really long column item here 1", "Item 2"), Features = c(
    "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin vehicula tempor ex.",
    "In eu urna at magna luctus rhoncus quis in nisl. Fusce in velit varius, posuere risus",
    "Vivamus venenatis egestas eros ut tempus. Vivamus id est nisi. Aliquam molestie erat"
    ))

kbl(text_tbl, booktabs = T) %>% collapse_rows(columns = 1) %>% 
kable_styling(full_width = T) %>% 
column_spec(1, width = "10em")

Running the above in Quarto creates:
image

Thanks in advance for any insight

@vincentarelbundock
Copy link
Collaborator

Not entirely sure about this, but perhaps we need \multirow{-2}{=} instead of \multirow{-2}{*} as suggested here:

https://tex.stackexchange.com/a/332782/16188

Screenshot and LaTeX document example below:

Screenshot 2023-12-04 204452

\documentclass{article}
\usepackage{tabu}
\usepackage{booktabs}
\usepackage{multirow}

\begin{document}

\begin{tabu} to \linewidth {>{\raggedright\arraybackslash}p{10em}>{\raggedright}X}
\toprule
Items & Features\\
\midrule
 & Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin vehicula tempor ex.\\
\cmidrule{2-2}
\multirow{-2}{*}{\raggedright\arraybackslash Really really really really long column item here 1} & In eu urna at magna luctus rhoncus quis in nisl. Fusce in velit varius, posuere risus\\
\cmidrule{1-2}
Item 2 & Vivamus venenatis egestas eros ut tempus. Vivamus id est nisi. Aliquam molestie erat\\
\bottomrule
\end{tabu}

\begin{tabu} to \linewidth {>{\raggedright\arraybackslash}p{10em}>{\raggedright}X}
\toprule
Items & Features\\
\midrule
 & Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin vehicula tempor ex.\\
\cmidrule{2-2}
\multirow{-2}{=}{\raggedright\arraybackslash Really really really really long column item here 1} & In eu urna at magna luctus rhoncus quis in nisl. Fusce in velit varius, posuere risus\\
\cmidrule{1-2}
Item 2 & Vivamus venenatis egestas eros ut tempus. Vivamus id est nisi. Aliquam molestie erat\\
\bottomrule
\end{tabu}

\end{document}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants