Discussion:
xcolor's \rowcolors extends beyond table borders
(too old to reply)
Randy Yates
2004-10-26 15:39:08 UTC
Permalink
Hi,

I'm trying to fancy up my tables a bit by adding color and I've run
into a snag. If I use the standard \rowcolors command, the result
is that the color extends outside my black ruled borders. I know
the reason - my "borders" are not really border but rules in a
column in which I've suppressed the intercolumn spacing with @{}.

I can't see a way to get both colors and vertical border rules.
Suggestions would be welcomed.

Here's a short LaTeX source file illustrating the problem:




\documentclass[10pt]{article}
\usepackage{colortbl}
\usepackage{xcolor}

% Fat and skinny vertical and horizontal rules, for tables that need lines
\newlength{\fattablelinesize}
\setlength{\fattablelinesize}{1.5pt}
\newlength{\skinnytablelinesize}
\setlength{\skinnytablelinesize}{0.3pt}
\newcommand{\Vr}{\vrule width \fattablelinesize}
\newcommand{\vr}{\vrule width \skinnytablelinesize}
\newcommand{\Hr}{\noalign{\hrule height \fattablelinesize}}
\newcommand{\hr}{\noalign{\hrule height \skinnytablelinesize}}

\begin{document}

\section{Colored Table Test}

\rowcolors[\hr]{2}{green!25}{red!25}
\begin{table}[htb]
\vskip\smallskipamount
\begin{center}
\leavevmode
\begin{tabular}{@{}l@{\hspace{\tabcolsep}}c@{\hspace{\tabcolsep}}c@{\hspace{\tabcolsep}}cl@{}}
\noalign{\hrule height 1.5pt}
\Vr & {\bf Root Index} & \Vr & {\bf Root} & \Vr \\
\Hr
\Vr & 1 & \vr & 1.00 & \Vr \\
\hr
\Vr & 2 & \vr & 2.03 & \Vr \\
\hr
\Vr & 3 & \vr & 3.20 & \Vr \\
\hr
\Vr & 4 & \vr & 8.09 & \Vr \\
\Hr
\end{tabular}
\end{center}
\end{table}

\end{document}
--
Randy Yates
Sony Ericsson Mobile Communications
Research Triangle Park, NC, USA
***@sonyericsson.com, 919-472-1124
Randy Yates
2004-10-26 15:47:37 UTC
Permalink
Post by Randy Yates
[...]
I can't see a way to get both colors and vertical border rules.
Actually, I can't see a way to get both colors and border rules
that have different thicknesses for vertical rules and horizontal
rules in the same row. This (if I'm deducing correctly) is the
reason I went to the technique of using a separate column for the
vertical rules instead of using "|" in the specification and \hline,
since these both depend on \arrarulewidth.
--
Randy Yates
Sony Ericsson Mobile Communications
Research Triangle Park, NC, USA
***@sonyericsson.com, 919-472-1124
Herbert Voss
2004-10-26 16:16:14 UTC
Permalink
Post by Randy Yates
\documentclass[10pt]{article}
\usepackage{colortbl}
\usepackage{xcolor}
% Fat and skinny vertical and horizontal rules, for tables that need lines
\newlength{\fattablelinesize}
\setlength{\fattablelinesize}{1.5pt}
\newlength{\skinnytablelinesize}
\setlength{\skinnytablelinesize}{0.3pt}
\newcommand{\Vr}{\vrule width \fattablelinesize}
\newcommand{\vr}{\vrule width \skinnytablelinesize}
\newcommand{\Hr}{\noalign{\hrule height \fattablelinesize}}
\newcommand{\hr}{\noalign{\hrule height \skinnytablelinesize}}
\begin{document}
\section{Colored Table Test}
\rowcolors*[\hr]{2}{green!25}{red!25}
\begin{table}[htb]
\vskip\smallskipamount
\begin{center}
\begin{tabular}{!{\Vr}ccc!{\Vr}}\Hr
{\bf Root Index} & \Vr & {\bf Root}\\\Hr
1 & \vr & 1.00 \\\hr
2 & \vr & 2.03 \\\hr
3 & \vr & 3.20 \\\hr
4 & \vr & 8.09 \\\Hr
\end{tabular}
\end{center}
\end{table}


Herbert
--
http://TeXnik.de/
http://PSTricks.de/
ftp://ftp.dante.de/tex-archive/info/math/voss/Voss-Mathmode.pdf
http://www.dante.de/faq/de-tex-faq/
http://www.tex.ac.uk/cgi-bin/texfaq2html?introduction=yes
Randy Yates
2004-10-26 22:08:05 UTC
Permalink
Post by Herbert Voss
Post by Randy Yates
\documentclass[10pt]{article}
\usepackage{colortbl}
\usepackage{xcolor}
% Fat and skinny vertical and horizontal rules, for tables that need lines
\newlength{\fattablelinesize}
\setlength{\fattablelinesize}{1.5pt}
\newlength{\skinnytablelinesize}
\setlength{\skinnytablelinesize}{0.3pt}
\newcommand{\Vr}{\vrule width \fattablelinesize}
\newcommand{\vr}{\vrule width \skinnytablelinesize}
\newcommand{\Hr}{\noalign{\hrule height \fattablelinesize}}
\newcommand{\hr}{\noalign{\hrule height \skinnytablelinesize}}
\begin{document}
\section{Colored Table Test}
\rowcolors*[\hr]{2}{green!25}{red!25}
\begin{table}[htb]
\vskip\smallskipamount
\begin{center}
\begin{tabular}{!{\Vr}ccc!{\Vr}}\Hr
{\bf Root Index} & \Vr & {\bf Root}\\\Hr
1 & \vr & 1.00 \\\hr
2 & \vr & 2.03 \\\hr
3 & \vr & 3.20 \\\hr
4 & \vr & 8.09 \\\Hr
\end{tabular}
\end{center}
\end{table}
Thanks again Herbert! I had to reinsert the @{\hspace{\tabcolsep}} to
get the spacing right, but otherwise this was the solution.

Say, I could not find the "!{}" syntax for the tabular specification in my
Lamport book. Is this new?
--
Randy Yates
Sony Ericsson Mobile Communications
Research Triangle Park, NC, USA
***@sonyericsson.com, 919-472-1124
Herbert Voss
2004-10-27 04:46:17 UTC
Permalink
Post by Randy Yates
Say, I could not find the "!{}" syntax for the tabular specification in my
Lamport book. Is this new?
no, defined in package array.sty

Herbert
--
http://TeXnik.de/
http://PSTricks.de/
ftp://ftp.dante.de/tex-archive/info/math/voss/Voss-Mathmode.pdf
http://www.dante.de/faq/de-tex-faq/
http://www.tex.ac.uk/cgi-bin/texfaq2html?introduction=yes
Loading...