Skip to content

Commit

Permalink
For LaTeX output, kable now typesets numbers in math mode for better-…
Browse files Browse the repository at this point in the history
…looking minus signs. Commas, if present (as decimal or thousands separator), are wrapped in braces to prevent additional space being added after. Improves yihui#1709.
  • Loading branch information
krivit committed Jan 2, 2021
1 parent f8f90ba commit a879a2c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions R/table.R
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ kable = function(
x = cbind(' ' = rownames(x), x)
if (!is.null(col.names)) col.names = c(' ', col.names)
if (!is.null(align)) align = c('l', align) # left align row names
isn = c(FALSE, isn)
}
n = nrow(x)
x = replace_na(to_character(x), is.na(x))
Expand All @@ -154,7 +155,7 @@ kable = function(
attr(x, 'align') = align
res = do.call(
paste('kable', format, sep = '_'),
list(x = x, caption = caption, escape = escape, ...)
list(x = x, caption = caption, escape = escape, isn = isn,...)
)
structure(res, format = format, class = 'knitr_kable')
}
Expand Down Expand Up @@ -274,7 +275,7 @@ kable_latex = function(
midrule = getOption('knitr.table.midrule', if (booktabs) '\\midrule' else '\\hline'),
linesep = if (booktabs) c('', '', '', '', '\\addlinespace') else '\\hline',
caption = NULL, caption.short = '', table.envir = if (!is.null(caption)) 'table',
escape = TRUE
escape = TRUE, isn = logical(ncol(x))
) {
if (!is.null(align <- attr(x, 'align'))) {
align = paste(align, collapse = vline)
Expand All @@ -301,6 +302,7 @@ kable_latex = function(
linesep = ifelse(linesep == "", linesep, paste0('\n', linesep))

if (escape) x = escape_latex(x)
x[, isn] = paste0('\\(', gsub(',', '{,}', x[, isn], fixed=TRUE), '\\)')
if (!is.character(toprule)) toprule = NULL
if (!is.character(bottomrule)) bottomrule = NULL
tabular = if (longtable) 'longtable' else 'tabular'
Expand Down

0 comments on commit a879a2c

Please sign in to comment.