-
-
Notifications
You must be signed in to change notification settings - Fork 878
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
Kable typesets negative numbers incorrectly in tables #1709
Comments
This comment has been minimized.
This comment has been minimized.
@wikithink I don't understand what you mean. The first symbol (a hyphen-minus) is rendered as a hyphen in text mode, and there is no second meaning for a plus-minus symbol. Compare: cl2 <- data.frame(x = c('$-$', '$\\pm$'), y = c(20, 50), z = c('minus', 'plus-minus'))
knitr::kable(cl2, booktabs = TRUE) |
Seconding this ticket, it looks ugly in LaTeX/PDF mode in particular, not just in terms of the kerning but in terms of the length of the minus sign.
As far as I know |
On the other hand, math mode also causes space to be inserted after commas, which doesn't look good when using them as a decimal or thousands separator. There is a number of ways to remedy this:
I don't know how much of a priority it is to avoid depending on external packages, but if it's a priority, the most robust approach is probably to take the number after formatting, then run a search-and-replace replacing each comma with Lines 149 to 152 in 12b50f5
I've prototyped this, and would be happy to submit a PR. |
Correction: the best place is probably after Line 256 in 12b50f5
to prevent the \(\) or $ from being escaped, tough it requires passing isn on to kable_latex .
|
…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.
…n math mode. Improves yihui#1709.
… typesetting change. Improves yihui#1709.
…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.
…n math mode. Improves yihui#1709.
… typesetting change. Improves yihui#1709.
…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.
…n math mode. Improves yihui#1709.
… typesetting change. Improves yihui#1709.
…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.
…n math mode. Improves yihui#1709.
… typesetting change. Improves yihui#1709.
…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.
…n math mode. Improves yihui#1709.
… typesetting change. Improves yihui#1709.
…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.
…n math mode. Improves yihui#1709.
… typesetting change. Improves yihui#1709.
…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.
…n math mode. Improves yihui#1709.
… typesetting change. Improves yihui#1709.
…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.
…n math mode. Improves yihui#1709.
… typesetting change. Improves yihui#1709.
…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.
…n math mode. Improves yihui#1709.
… typesetting change. Improves yihui#1709.
…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.
…n math mode. Improves yihui#1709.
… typesetting change. Improves yihui#1709.
… typesetting change. Improves yihui#1709.
…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.
…n math mode. Improves yihui#1709.
… typesetting change. Improves yihui#1709.
…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.
…n math mode. Improves yihui#1709.
… typesetting change. Improves yihui#1709.
…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.
…n math mode. Improves yihui#1709.
… typesetting change. Improves yihui#1709.
…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.
…n math mode. Improves yihui#1709.
… typesetting change. Improves yihui#1709.
…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.
…n math mode. Improves yihui#1709.
… typesetting change. Improves yihui#1709.
The current version of
kable
generates incorrectly typeset numeric columns, especially in LaTeX output, wherever they contain negative numbers.Example
Consider this minimal example.
The output is
which renders as follows here on GitHub:
Negative numbers and minus signs
Looks OK, right? Well, not quite. The symbol before the
6
is a hyphen-minus (-, U+002D), not an explicit minus sign (−, U+2212).In HTML output the difference is not so noticeable to some, but in LaTeX-PDF output it looks extremely dodgy as far as kerning is concerned, because the numbers are incorrectly typeset in text mode and therefore the '-' symbol is misinterpreted as a hyphen rather than a minus sign.
The correct output, at least for LaTeX, should be to wrap all numbers in in-line math tags, like
$-123$
or\(-123\)
, as a hyphen-minus entered in math mode is interpreted and correctly rendered as a minus symbol, with the correct kerning.Compare these two columns, where column
y
is rendered by the defaultkable
settings from a numeric column, and columnz
has been wrapped in math tags.Possible fix
One way to accomplish this might be to replace the line
knitr/R/table.R
Line 145 in 00ffce2
with
however this may only appropriate for LaTeX output, as though it should look fine on HTML, it would be an unwelcome surprise for people not using MathJax to suddenly need it. Maybe we can make it an option, disabled by default?
Another solution
Slightly less heavy-handed: replace all hyphens in numeric columns with double hyphens, which should get typeset as en-dashes. Not strictly correct, and could cause kerning issues in LaTeX, but looks a bit better.
Workarounds
Of course one can pre-process the data before it goes into kable, but then the columns aren't numeric any more so you have to set the alignment manually. And I personally think good typography should be the default!
The text was updated successfully, but these errors were encountered: