Table xcolor @{,} \rowcolor broken text

by John.Doe_876   Last Updated September 12, 2019 01:23 AM

i am using a formatted table like this:

    \documentclass[a4paper,10pt]{report}    

    \usepackage[table]{xcolor}

    \begin{document}
    \begin{tabular}{|c|[email protected]{,}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



Answers 3


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|[email protected]{,}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]}[email protected]{,}}{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]}[email protected]{,}}{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}
David Carlisle
David Carlisle
January 25, 2016 11:51 AM

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

Zarko
Zarko
January 25, 2016 12:20 PM

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

user2478
user2478
January 25, 2016 12:55 PM

Related Questions


Cancel \rowcolors for a specific cell

Updated December 04, 2017 16:23 PM



Clear rowcolor at midrule

Updated June 07, 2019 15:23 PM

\noalign caused by multirow and colors

Updated June 09, 2019 14:23 PM