haozhu233 / haozhu233/kableExtra

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

Open
#752 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
737
Forks
149
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the supplied R and Quarto example, then inspect how collapse_rows() and column_spec() produce the LaTeX table for PDF output. Compare the generated table with the HTML result and verify that text in collapsed rows wraps within the specified column width without overflowing the page.

Written by the indexing model from the issue text.

Assessment

Tech stack
latex, r
Domain
data-visualization
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.