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

valign does not work correctly #9

Open dquang opened 7 years ago

dquang commented 7 years ago

Hi,

Thank you very much for the excellent package.

I have a problem of valign function in output pdf document. The valign does not work as expected. The sample Rmd code is following. Output table in the PDF file has v-aligned bottom even the setting is "top". Output to HTML is correct.

Could you please check again?

Another question is: how can I justify the column to the both side?

regards, Quang huxtable_issue.pdf

---
output: pdf_document
#geometry: inner=3.8cm, outer=25mm, top=25mm, bottom=25mm
#documentclass: report
header_includes:
#- \usepackage{graphicx}
- \usepackage{booktabs}
#- \usepackage{tabularx}
---
library(dplyr)
library(huxtable)
lorem1 <- "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce nec quam ut tortor interdum pulvinar id vitae magna. Proin at diam vitae lectus dignissim auctor nec dictum lectus. Fusce venenatis eros congue velit feugiat, ac aliquam ipsum gravida. Cras bibendum malesuada est in tempus."

lorem2 <- "Integer vel placerat purus. Nulla facilisi. Etiam odio magna, porttitor et est nec, placerat pellentesque ex."
ht <-
huxtable(
  Col1 = c("Paragraph 1", "Paragraph 2"),
  Text = c(lorem1, lorem2), add_colnames = TRUE
) %>%
  set_wrap(value = TRUE)     %>%
  set_width(1)                 %>%
  set_col_width(c(0.3, 0.7))   %>%
  set_valign("top")
ht
valign(ht)
hughjonesd commented 7 years ago

See https://hughjonesd.github.io/huxtable/design-principles.html and also https://tex.stackexchange.com/questions/359415/how-can-i-find-the-cell-height-in-a-tabular for why this is unlikely to be fixable. The bottom line is, LaTeX table vertical alignment doesn't work the way you think it does, and is not actually very useful for anything. But I can't fix that without fixing LaTeX ;-)

dquang commented 7 years ago

Understood, thank you! It seems that there are always problems with LaTex :) Wish you all the best!

eweisbrod commented 3 years ago

Hi, I am having a similar problem. When I check valign in my huxtable, it says "top" everywhere. However, something in the huxtable latex code is coding all the parboxes as parbox[b]. I manually changed them all to parbox[t] and it fixed the table and top-aligned everything properly.

I'm not sure if I've give enough info, but is there anything you could possibly investigate to prevent huxtable from specifying parbox[b] instead of parbox[t] ?

hughjonesd commented 3 years ago

Yeah, I have to admit that the current setup is a mess.


library(huxtable)
library(dplyr)
tmp <- hux("shorter","Long content that should wrap")

tmp %>% set_valign("bottom") %>% set_width(0.3) %>% set_all_borders() %>% quick_pdf()

bottom

tmp %>% set_valign("top") %>% set_width(0.3) %>% set_all_borders() %>% quick_pdf()

top

hughjonesd commented 3 years ago

On the other hand, if alignment is in response to fixing row_height() then valign doesn't really do anything.

This is a breaking change, and it might affect other situations, so will need to test before making it.