Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a table with numbers that I have aligned using the S column type provided by the siunitx package. I need to make one of the table elements red, but when I do that, the number that is red is no longer aligned.

What is the right way to do this? MWE below.

\documentclass{article}
\usepackage{siunitx}
\usepackage[]{xcolor}

\begin{document}
\begin{table} \centering
    \caption{Table with \texttt{c} column type.}
    \begin{tabular}{cc}
        \hline
        Symbol & \multicolumn{1}{c}{Value} \\
        \hline
        $\pi$ & 3.141592654 \\
        $2\pi$ & 6.283185307 \\
        $4\pi$ & 12.56637061 \\
        $8\pi$ & {\color{red}25.13274123} \\
        $e$   & 2.71828182845904524 \\
        $\sqrt{2}$ & 1.41421356237309505 \\
        \hline
    \end{tabular}
\end{table}

\begin{table} \centering
    \caption{Table with \texttt{S} column type.}
    \begin{tabular}{cS}
        \hline
        Symbol & \multicolumn{1}{c}{Value} \\
        \hline
        $\pi$ & 3.141592654 \\
        $2\pi$ & 6.283185307 \\
        $4\pi$ & 12.56637061 \\
        $8\pi$ & {\color{red}25.13274123} \\
        $e$   & 2.71828182845904524 \\
        $\sqrt{2}$ & 1.41421356237309505 \\
        \hline
    \end{tabular}
\end{table}
\end{document}
share|improve this question

1 Answer 1

up vote 4 down vote accepted

Simply remove the braces around the \color{red}25.13274123. They are not necessary, and content wrapped in braces are not considered numbers I think, hence not aligned as such.

Also, the \multicolumn is not necessary, it is enough to wrap Value in braces. The reason, as I understand it, is that the e in Value could be considered a part of an exponential number, e.g. 3e8, and siunitx will then try to align it. To protect it from alignment, wrap it in braces. This is mentioned in the manual, section 4.6 Tabular material (the last sentence starting on page 13).

\documentclass{article}
\usepackage{siunitx}
\usepackage{xcolor}
\begin{document}
\begin{table} \centering
    \caption{Table with \texttt{S} column type.}
    \begin{tabular}{cS}
        \hline
        Symbol & {Value} \\
        \hline
        $\pi$ & 3.141592654 \\
        $2\pi$ & 6.283185307 \\
        $4\pi$ & 12.56637061 \\
        $8\pi$ & \color{red}25.13274123 \\
        $e$   & 2.71828182845904524 \\
        $\sqrt{2}$ & 1.41421356237309505 \\
        \hline
    \end{tabular}
\end{table}
\end{document}

enter image description here

share|improve this answer
    
I think siunitx, by default, will center-set items that are surrounded curly braces, regardless of the contents of the group. –  Mico Aug 14 '12 at 17:34
    
Well that was so easy, I'm almost embarrassed to have asked the question. Thanks! –  Jeremy Aug 14 '12 at 17:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.