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 reduced the space in the columns through the use of @{} in the column type:

\newcolumntype{M}{@{}c@{}}

The problem is that, when I combined this with the \cellcolor command, it overflows into the other columns. And if I remove the @{} space modification, then it sets it right.

So, how can I let the \cellcolor command now that I reduced the space of that column?

\documentclass{article}

\usepackage[table]{xcolor}
\usepackage{array}
\newcolumntype{M}{@{}c@{}}

\begin{document}
\pagestyle{empty}
\begin{table}
\begin{tabular}{l|M|c|M|M}
  & a & b & c & d\\
a & \cellcolor{black!50} 90.6 & 10 & 0 & 0\\
b & 0 & \cellcolor{black!50} 90.0 & 10 & 10\\
c & 0 & 0 & 95 & \cellcolor{black!50} 5\\
d & 0 & 10 & 5.5 & 8\\
\end{tabular}
\end{table}
\end{document}

Overflowed cellcolor table

share|improve this question

1 Answer 1

up vote 3 down vote accepted

fake the columncolor:

\documentclass{standalone}

\usepackage[table]{xcolor}
\usepackage{array}
\newcolumntype{M}{@{}>{\columncolor{white}[0pt][0pt]}c@{}}

\begin{document}
\pagestyle{empty}
\begin{table}
\begin{tabular}{l|M|c|M|M}
  & a & b & c & d\\
a & \cellcolor{black!50} 90.6 & 10 & 0 & 0\\
b & 0 & \cellcolor{black!50} 90.0 & 10 & 10\\
c & 0 & 0 & 95 & \cellcolor{black!50} 5\\
d & 0 & 10 & 5.5 & 8\\
\end{tabular}
\end{table}
\end{document}

enter image description here

However, you'll get problems with viewing the vertical lines. With some zoom values they will not be visible. Printing is no problem.

share|improve this answer
    
The problem with the lines is really annoying, the main idea is to have a really nice looking document, both printed and digital. Is there any other option to achieve the same goal? Some other package to color the tables? –  adn Jan 27 '12 at 11:12
1  
it is a problem with the viewer and not with TeX! –  Herbert Jan 27 '12 at 11:39

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.