TeX - LaTeX Asked by MikeMx7f on March 29, 2021
I am working on formatting a table a coauthor originally created for publication, and running into a problem when trying to color-code rows. The degree symbol in the first data row is formatted in an odd way (by using an extra column), and this is likely the source of error, but I am unsure of an alternative that accomplishes the same thing (columns aligned, degree symbol not part of alignment). Anyway, when I add a row color, the entries in the Mean and Max Error columns are truncated:
How can I get rid of this truncation while maintaining the current alignment?
documentclass{article}
usepackage[table]{xcolor}
begin{document}
begin{tabular}{l | r | r @{}l | r @{} l }
Name & Bits & Mean Error & & Max Error &
hline
hline
A & 15 & $1.45262$&$^{circ}$ & $3.26743$&$^{circ}$
hline
rowcolor{gray}
B & 16 & $0.37364$& & $1.29985$&
C & 16 & $0.36114$& & $1.05603$&
end{tabular}
end{document}
Just insert an hphantom{^{circ}} like this:
documentclass{article}
usepackage[table]{xcolor}
begin{document}
begin{tabular}{l|r|r|r}
Name & Bits & Mean Error & Max Error
hline
hline
A & 15 & $1.45262^{circ}$ & $3.26743^{circ}$
hline
rowcolor{gray}
B & 16 & $0.37364hphantom{^{circ}} $ & $1.29985hphantom{^{circ}}$
C & 16 & $0.36114hphantom{^{circ}}$ & $1.05603hphantom{^{circ}}$
end{tabular}
end{document}
Another solution, that will save typing lots of hphantoms and $...$:
begin{tabular}{l | r | r | r}
Name & Bits & Mean Error & Max Error
hline
hline
A & 15 & 1.45262rlap{$^{circ}$} & 3.26743rlap{ $^{circ}$}
hline
rowcolor{gray}
B & 16 & 0.37364 & 1.29985
C & 16 & 0.36114 & 1.05603
end{tabular}
Correct answer by Bernard on March 29, 2021
The environment {NiceTabular}
of nicematrix
provides tools similar to those of colortbl
but using PGF/Tikz for the drawing.
Using that environment, you have directly what you wish (but you need several compilations since nicematrix
uses PGF/Tikz nodes).
documentclass{article}
usepackage{xcolor}
usepackage{nicematrix}
begin{document}
begin{NiceTabular}{l | r | r @{}l | r @{} l }[colortbl-like]
Name & Bits & Mean Error & & Max Error &
hline
hline
A & 15 & $1.45262$&$^{circ}$ & $3.26743$&$^{circ}$
rowcolor{gray}%
B & 16 & $0.37364$& & $1.29985$&
C & 16 & $0.36114$& & $1.05603$&
end{NiceTabular}
end{document}
Answered by F. Pantigny on March 29, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP