haozhu233 / haozhu233/kableExtra
Borders in knitr::kable for extra headers
- Dominant language
- R
- Stars
- 737
- Forks
- 149
- PR merge metrics
- No merged PRs in 30d
Description
This may be asking too much, but I've recently used add_header_above to add a multicolumn header to a table. I'd like to separate two headers in the same row with a vertical border. I've successfully added the border to the table body and to the column names (col.names), but the extra header confounds me. t6 is a 12 column x 6 row table and the following creates the table.
col.names <- c('Year','Beginning\nUnrecovered\nBalance',
'Interest on\nUnrecovered\nBalance',
'Cash Flow','Recovered\nAmount',
'Ending\nUnrecovered\nBalance')
col.names <- c(col.names,col.names)
hdr.above <- c('Basis: Unrecovered balance'=6,'Basis: Initial Principal'=6)
x <- knitr::kable(t6,format=TableFormat,align=a,
col.names=c(col.names,col.names),caption='ROR Results', booktabs=T, escape=F) %>%
kable_styling(bootstrap_options=c('striped','hover','condensed','responsive'),
position='center',latex_options = "hold_position",
font_size = font.size,full_width=F) %>% column_spec(7,border_left=T)
hdr.above.2 <- NULL
x %>% add_header_above(hdr.above,align='l') %>% cline(c(2,5))
The pipe to column_spec(7,border_left=T) draws a vertical border in the main body and in the column names row. The extra header from add_header_above(...) has no border. Is there a way to add one using kable?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the add_header_above and column_spec entry points, using the supplied t6 example and comparing the existing body and column-name border behavior across the HTML and LaTeX options. Done means the extra header receives the requested vertical border while the existing borders and cline behavior remain correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- html, latex, r
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100