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

collapse_rows() doesn't end up with vertically centred entry #56

Closed
EhrmannS opened this issue Sep 1, 2017 · 4 comments
Closed

collapse_rows() doesn't end up with vertically centred entry #56

EhrmannS opened this issue Sep 1, 2017 · 4 comments

Comments

@EhrmannS
Copy link

EhrmannS commented Sep 1, 2017

Hi!

I have the following example. It results in a table, where car 1 is to be found somewhere in the 4th fifth of the vertical distribution, rather than directly in the middle. This creates for more complex tables and longer values in this "collapsed cell" rather strange behaviour and sometimes the text even crosses the lower boundary of the group. It seems almost as if the value would be centred between the two maximum border of the table per page, and not between the two borders of the group that should be collapsed.

---
documentclass: book
lof: no
lot: no
output:
  bookdown::pdf_book:
    fig_caption: yes
    keep_tex: yes
    number_sections: yes
  bookdown::html_document2:
    fig_caption: yes
    theme: spacelab
subtitle: null
---
library(knitr)
library(magrittr)
library(bookdown)
library(captioner)
library(stringr)
library(dplyr)
library(kableExtra)
long_dt <- cbind(car = row.names(mtcars), mtcars)
rownames(long_dt) <- NULL
long_dt[,1] <- c(rep("car 1", 22), rep("car 2", 10))

kable(long_dt, 
      longtable = T,
      format = "latex",
      booktabs = T, 
      caption.short = "An awesome \\textsc{Longtable}.",
      caption = "An awesome Longtable, with a caption.") %>%
  add_header_above(c(" ", "Group 1" = 5, "Group 2" = 6)) %>%
  kable_styling(latex_options = "repeat_header") %>%
  collapse_rows(columns = 1)

Even more strangely, if you set the line long_dt[,1] <- c(rep("car 1", 22), rep("car 2", 10)) to long_dt[,1] <- c(rep("car 1", 16), rep("car 2", 16)), car 2 is printed where the repeated header on the second page would be printed otherwise.

If I compile it to html it works without problems.

@haozhu233
Copy link
Owner

Hi, @EhrmannS, it seems like booktabs' cmidrule messed up the multirow's calculation..

https://tex.stackexchange.com/questions/66564/vertical-alignment-using-multirow-and-booktabs

I don't know if I can find a good solution for this. I can certainly remove those midlines. I don't like them either but they are important for tables with multiple header columns. If we keep those midlines, TeX people say you can manually add adjustments to multirow. I can certainly simulate it via code but it seems like it will bring me more issues in the future.

@EhrmannS
Copy link
Author

EhrmannS commented Oct 5, 2017

I tried out another package (https://github.com/hughjonesd/huxtable) and it seems as if a very similar problem exists that might be connected to latex (hughjonesd/huxtable#9).

Just wanted to let you know. I will use a work-around for my table that doesn't require collapsing the column in the first place.

@EhrmannS EhrmannS closed this as completed Oct 5, 2017
@slyrus
Copy link

slyrus commented Mar 6, 2020

Did anyone ever come up with a proper solution for this?

@haozhu233
Copy link
Owner

@slyrus We are adding a page breaking mechanism in the latest version (not on cran yet). Check #314 for details.

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

3 participants