Last active
January 19, 2025 02:13
-
-
Save moi90/fe88ca891bcdc069044255425fea3078 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\documentclass{article} | |
\usepackage{siunitx} | |
\usepackage{booktabs} | |
\usepackage[table]{xcolor} | |
\usepackage{etoolbox} | |
% Individual \itshape or \bfseries work without this. | |
% Combinations of both need the robustified version | |
\robustify\itshape | |
\robustify\bfseries | |
\begin{document} | |
% Required so that siunitx can detect \bfseries, \itshape, etc | |
\sisetup{detect-all = true} | |
\begin{table}[t] | |
\centering | |
\caption{\texttt{siunitx S} columns require a special treatment to format them correctly.} | |
\begin{tabular}{SS} | |
\toprule | |
% Non-number headings require braces: | |
{Heading A} & {Heading B} \\ | |
% Fails with an error: Heading A & Heading B \\ | |
\midrule | |
1.00 & 2.00 \\ | |
% This is the only way to correctly color and format cells for siunitx: | |
{\cellcolor[gray]{0.8}} \bfseries 10.0 & \bfseries\itshape 20.0\\ | |
100.000 & 200.000 \\ | |
% color | |
\color{red} 1000.00 & \color{green} \bfseries 2000.00\\ | |
\multicolumn{2}{c}{(Cells aligned at decimal dot)}\\ | |
\midrule | |
10.0 & 20.0 \\ | |
% \cellcolor does not work without enclosing braces: Wrong alignment | |
\cellcolor[gray]{0.8} \textbf 10.0 & \bfseries \itshape 20.0 \\ | |
\multicolumn{2}{c}{(Second 10.0 is wrongly aligned,}\\ | |
\multicolumn{2}{c}{formatting is only applied to first digit.)}\\ | |
\midrule | |
10.0 & 20.0 \\ | |
% \textbf and \textit do not work: Wrong alignment | |
{\cellcolor[gray]{0.8}} \textbf{10.0} & \textit{20.0}\\ | |
\multicolumn{2}{c}{(Second 10.0 and 20.0 are wrongly aligned)}\\ | |
\bottomrule | |
\end{tabular} | |
\end{table} | |
\begin{table}[t] | |
\centering | |
\caption{Formatting also works with regular \texttt{c} columns} | |
\begin{tabular}{cc} | |
\toprule | |
% Non-number headings require braces: | |
{Heading A} & {Heading B} \\ | |
% Fails with an error: Heading A & Heading B \\ | |
\midrule | |
1.00 & 2.00 \\ | |
% This is the only way to correctly color and format cells for siunitx: | |
{\cellcolor[gray]{0.8}} \bfseries 10.0 & \bfseries \itshape 20.0\\ | |
100.000 & 200.000 \\ | |
\color{red} 1000.00 & \color{green} \bfseries 2000.00\\ | |
\bottomrule | |
\end{tabular} | |
\end{table} | |
\end{document} |
Thanks! I subscribed to the pull requests. Is there anything I can do to speed up the review process?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
40731