haozhu233 / kableExtra

Construct Complex Table with knitr::kable() + pipe.
https://haozhu233.github.io/kableExtra/
Other
688 stars 147 forks source link

conflict between full_width = TRUE and `width`? #669

Open ericpgreen opened 2 years ago

ericpgreen commented 2 years ago

I'm using bookdown to create a Tufte-style PDF with margin notes. I use full_width = TRUE to constrain the table to the main column and prevent it from bleeding into the margin notes area. I get an error when I also try to set width in column_spec.

! Misplaced \noalign.
\toprule ->\noalign 
                    {\ifnum 0=`}\fi \@aboverulesep =\abovetopsep \global \@b...
l.577 \end{tabu}
# packages
  library(knitr)
  library(tidyverse)
  library(kableExtra)

# data
  test <- tribble(
    ~A, ~B,
    "Lorem ipsum", "Lorem ipsum dolor sit amet, consectetur adipiscing elit",
    "Lorem ipsum", "Lorem ipsum dolor sit amet, consectetur adipiscing elit"
  )

# table
  kable(test, format = "latex", booktabs = T, caption="Test") %>%
    row_spec(0, bold=TRUE) %>%
    column_spec(1, bold=TRUE, width="2cm") %>%   # works without width="2cm"
    kable_styling(full_width = TRUE, position = "left")
christophsax commented 2 years ago

I have the same issue. This is an issue with the tabu package and probably a duplicate of #625.

ericpgreen commented 2 years ago

Thanks, @christophsax. I'm using tabu by default, so I'll need to look into how it's used and possible alternatives. If you find a solution I'd love to know more.