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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i am using a formatted table like this:

    \documentclass[a4paper,10pt]{report}    

    \usepackage[table]{xcolor}

    \begin{document}
    \begin{tabular}{|c|r@{,}l|c|c|c|c|}
    \hline
    $B_N$ & \multicolumn{2}{c|}{$C_N$} & $i$ & $j$ & $k$ & $l$ \\
    \hline \rowcolor{gray!35}
    $B_1$ & 5 & 128 & 0 & 1 & 0 & 0 \\ 
    \hline \rowcolor{gray!35}
    $B_2$ & 0 & 281 & 0 & 1 & 0 & 1 \\
    \hline
    $B_{11}$ & 0 & $008 \cdot e$ & 2 & -1 & -1 & 0 \\ 
    \end{tabular}
    \end{document}

And as you can see here:

Broken text: 5, is missing

the 5, and the 0, are cut in half. I found a similar problem (\rowcolor truncating cells in table) but i can not fix my bug with use of this answer. How do i fix this issue ?

Thanks

share|improve this question
up vote 7 down vote accepted

Sorry blame the author of colortbl not xcolor the interface here is rubbish, however you can do this:

enter image description here

\documentclass[a4paper,10pt]{report}    

    \usepackage[table]{xcolor}

    \begin{document}
    \begin{tabular}{|c|r@{,}l|c|c|c|c|}
    \hline
    $B_N$ & \multicolumn{2}{c|}{$C_N$} & $i$ & $j$ & $k$ & $l$ \\
    \hline \rowcolor{gray!35}
    $B_1$ &
\multicolumn{1}{>{\columncolor{gray!35}[\tabcolsep][6pt]}r@{,}}{5}& 
\multicolumn{1}{@{}>{\columncolor{gray!35}[0pt][\tabcolsep]}l|}{128}&
0 & 1 & 0 & 0 \\ 
    \hline \rowcolor{gray!35}
    $B_2$ & 
\multicolumn{1}{>{\columncolor{gray!35}[\tabcolsep][6pt]}l@{,}}{0} &
\multicolumn{1}{@{}>{\columncolor{gray!35}[0pt][\tabcolsep]}l|}{281}&
 0 & 1 & 0 & 1 \\ 
\hline
    $B_{11}$ & 0 & $008 \cdot e$ & 2 & -1 & -1 & 0 \\
\hline 
    \end{tabular}

\end{document}
share|improve this answer
    
To me is than simpler to add siunitx package and use column type S, erase surplus ampersand in table and wrote numbers as usual we write decimal numbers.. :-) – Zarko Jan 25 at 12:05
    
@Zarko sure (or dcolumn) but there are legitimate uses of @ which can't be replaced by a numeric column and \rowcolor essentially always messes up in that case. (Easier to see it is wrong than see what to do instead) – David Carlisle Jan 25 at 12:09
    
@Zarko although actually you could post an answer along those lines which is a useful practical alternative (and if you stop me getting a tick you will make egreg's day:-) – David Carlisle Jan 25 at 12:11
    
well, i made the minimal example a little too minimal as it seams, sry. i added another line (B_11) since with this line the spacing gets different and the (otherwise working) solution becomes bad. – John.Doe_876 Jan 25 at 12:12
    
@John.Doe_876 sorry, fixed. – David Carlisle Jan 25 at 12:29

An practical alternative: To write decimal numbers alegned at decimal mark you can use two packages:

  • dcolumn
  • siumitx

With both you simple merge r andl column in one and numbers write as ordinary decimal Numbers. Since I'm more familiar with siunitx ...

   \documentclass[a4paper,10pt]{report}

    \usepackage[table]{xcolor}
    \usepackage[output-decimal-marker={,}]{siunitx}

\begin{document}
    \begin{tabular}{|c|S[table-format=1.3]|c|c|c|c|}
    \hline
$B_N$ & {$C_N$} & $i$ & $j$ & $k$ & $l$ \\
    \rowcolor{gray!35}\hline
$B_1$ & 5,128 & 0 & 1 & 0 & 0 \\
    \rowcolor{gray!35}\hline 
$B_2$ & 0,281 & 0 & 1 & 0 & 1 \\
    \hline
    \end{tabular}
\end{document}

The looks of table is the same as in David Carlisle answer:

enter image description here

Upgrade: It seems, that above solution is more appropriate for new tables, for the existing the following escape of colortbl limitation (malfunction) can be simple solution: \documentclass[a4paper,10pt]{report}

\usepackage[table]{xcolor}

\begin{document}
\begin{tabular}{|c|r<{,\kern-\tabcolsep}>{\kern-\tabcolsep}l|c|c|c|c|}
\hline
$B_N$ & \multicolumn{2}{c|}{$C_N$} & $i$ & $j$ & $k$ & $l$ \\
\hline \rowcolor{gray!35}
$B_1$ & 5 & 128 & 0 & 1 & 0 & 0 \\
\hline \rowcolor{gray!35}
$B_2$ & 0 & 281 & 0 & 1 & 0 & 1 \\
\hline
$B_{11}$ & 0 & $008 \cdot e$ & 2 & -1 & -1 & 0 \\
\hline
\end{tabular}
\end{document}

The result is the same as at the first example:enter image description here

share|improve this answer
    
+1 :-)......... – David Carlisle Jan 25 at 12:30
    
@DavidCarlisle, I thing that I found a (rude) solution which overcome colortbl limitation .... See upgrade of my answer. – Zarko Jan 25 at 13:39
    
yes I wondered about using > instead of @ that works as well. The main problem is that \rowcolour has no information about the table preamble (at least no information in a form it can use) so it assumes \tabcolsep space, which isn't the case with @ using >< is easier to handle as it happens "inside" the column just as if those commands had been in the cell, whereas @ really changes the column layout. – David Carlisle Jan 25 at 14:05

Use the math mode if it is more an array as a tabular:

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{icomma,rccol}

\begin{document}

$\begin{array}{|c|R{1}{3}|c|c|c|c|}\hline
B_N & \multicolumn{1}{c|}{C_N} & i & j & k & l \\
\rowcolor{gray!35}\hline
B_1 & 5,128 & 0 & 1 & 0 & 0 \\
\rowcolor{gray!35}\hline 
B_2 & 0,281 & 0 & 1 & 0 & 1 \\\hline
\end{array}$

\end{document}

enter image description here

share|improve this answer

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.