0

I'm using the excellent modelsummary package to summarize my data and regression models.

One problem I've run into is having column labels -- variables for datasummary_correlation and model names for regression output -- that are too wide for the PDF page size I want. It looks fine in Rstudio and HTML, but that's just because there's no width issue there. In PDF, an overly wide table runs into the margin.

Here's an example where you can see how the column labels are too wide.

enter image description here

What I would like is to break up the column labels at the place of my choosing, so that they would consist of multiple rows (and narrower columns). In fact, what it looks like more on the HTML rendering:

enter image description here

bshor
  • 4,859
  • 8
  • 24
  • 33

1 Answers1

1

Looks like the correct strategy (h/t the author of modelsummary) is to pipe the output into one of the table helper functions, then to use the column_spec() function.

So for me, I can do (making the data columns shorter and the label column a little longer):

out <- datasummary_correlation(output="kableExtra", booktabs=T)
out %>% column_spec(1,width="1.5in") %>% column_spec(2:5,width="0.75in")
bshor
  • 4,859
  • 8
  • 24
  • 33