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 Jun 15, 2020
1 parent 3373ebe commit 20ba36a
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 @@ -140,6 +140,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 @@ -151,7 +152,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 @@ -271,7 +272,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 @@ -298,6 +299,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 20ba36a

Please sign in to comment.