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 tables with many $\pm$ values that I was using the @{decl} command to have nice alignment. However, I wanted to add some row colors. Trying to use colortbl I found that the cell/row color was on top of my $\pm$. I tried playing with the overhang, but then the color wasn't behind the $\pm$.

MWE is below.

\documentclass{article}
\usepackage{color}
\usepackage{colortbl}

\begin{document}
\begin{tabular}{l@{$\pm$}r}
\multicolumn{2}{c}{value} \\
\hline
1 & 2 \\ 
\rowcolor{white}[0pt] 2&3 \\
\rowcolor{yellow}[0pt] 3&4\\
\end{tabular}


\begin{tabular}{l@{$\pm$}r}
\multicolumn{2}{c}{value} \\
\hline
1 & 2 \\ 
\rowcolor{white} 2&3 \\
\rowcolor{yellow} 3&4\\
\end{tabular}
\end{document}

Is there any nice/simple way to do this LaTeX? I'm sure there is something complicated, but I thought this would be a relatively simple use case. If it possibly matters, I'm making a Poster in Beamer.

Latex Table Results

share|improve this question

2 Answers 2

up vote 4 down vote accepted

You can use the dcolumn package to easily get the alignment (with the right spacing around \pm) and the color:

\documentclass{article}
\usepackage{dcolumn}
\usepackage[table]{xcolor}

\newcolumntype{L}{D{,}{{}\pm{}}{1,1}}

\begin{document}

\noindent\begin{tabular}{L}
\multicolumn{1}{c}{value} \\
\hline
1,2 \\ 
\rowcolor{blue!30} 2,3 \\
\rowcolor{yellow!60} 3,4 \\
\end{tabular}

\noindent\begin{tabular}{L}
\multicolumn{1}{c}{value} \\
\hline
1,2 \\ 
\rowcolor{blue!30}[0pt] 2,3 \\
\rowcolor{yellow!60}[0pt] 3,4 \\
\end{tabular}

\end{document}

enter image description here

share|improve this answer
    
Yes I thought to mention in my answer that the spacing around pm is distinctly odd if done that way. That certainly looks a lot better. Depends a bit what the real example is rather than this (nicely small) MWE:-) –  David Carlisle Jul 24 '12 at 23:04
    
This works! I hadn't used dcolumn before and wouldn't have thought of cross-purposing it this way. The alignment works ok - I have very few cells that end up looking strange this way (can fix by hand). –  ackey Jul 25 '12 at 5:04

The coloured pannels are laid out before each cell content so you want to make the cell before the @{} be extended under it and the one after the @{} to not extend back over it.

enter image description here

Unfortunately I think that means something like:

\documentclass{article}
\usepackage{color}
\usepackage{colortbl}

\begin{document}
\begin{tabular}{l@{$\pm$}r}
\multicolumn{2}{c}{value} \\
\hline
1 & 2 \\ 
\rowcolor{white}[0pt] 2&3 \\
%\rowcolor{yellow}[0pt]
\multicolumn{1}{>{\columncolor{yellow}[0pt][20pt]}l@{$\pm$}}{3}&
\multicolumn{1}{>{\columncolor{yellow}[0pt]}l}{4}\\
\end{tabular}
\end{document}
share|improve this answer
    
That is somewhat easier than I was expecting, but it will get quite ugly when I have many (right now, 3 or 4) of these value with error sets. –  ackey Jul 24 '12 at 21:56
2  
sorry. blame the author of the package. –  David Carlisle Jul 24 '12 at 22:21
    
Luckily the author of colortbl gets plenty of credit for the dcolumn package and the excellent Companion book. (-: –  ackey Jul 25 '12 at 5:07

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.