hughjonesd / huxtable

An R package to create styled tables in multiple output formats, with a friendly, modern interface.
http://hughjonesd.github.io/huxtable
Other
321 stars 28 forks source link

Text cuts off when using wrap() with latex #75

Closed raiphilibert closed 6 years ago

raiphilibert commented 6 years ago

When trying to wrap text in a table in latex, the text is cut off or spills outside of the table borders. Here's an example code:

library(huxtable)
library(magrittr)

##creat dataframe with long names
headers= c('Location', 'Date','pH -Lab Reading','Total Suspended Solids',
   'Total Cyanide','Dissolved Copper','Dissolved Iron','Dissolved Molybdenum')
df<- data.frame(matrix(rep(1:8,length(headers)),ncol=length(headers)))
names(df) <- headers

#create huxtable with wrap
df_ht <- as_huxtable(df,add_colnames = TRUE)%>% set_all_borders(1) %>%
  set_position('left') %>%
  set_width(0.8) %>%
  set_wrap(1,everywhere,TRUE) %>%
  set_left_padding(10) 

Screenshot of results:

image

hughjonesd commented 6 years ago

My guess would be that TeX simply does not know how to fit your headings inside your cell. Have you tried setting col_width? Meanwhile, I will investigate. Thanks for the report.

hughjonesd commented 6 years ago

Yup, so this gives a nicer output for me.

colw <- c(rep(1, 7), 2)
colw <- colw/sum(colw)
df_ht <- as_huxtable(df,add_colnames = TRUE)%>% set_all_borders(1) %>%
  set_position('left') %>%
  set_width(0.8) %>%
  set_wrap(1,everywhere,TRUE) %>%
  set_left_padding(10) %>% 
  set_col_width(colw)
quick_pdf(df_ht)

I think this is a LaTeX problem (or even a "computer can't read your mind" problem - choosing table widths is intrinsically hard).

hughjonesd commented 6 years ago

Closing as I don't see a way to fix.