# Adding a different colored line to each row of a table

It is possible to get colored \hlines with the example provided below. However, there are several issues with this implementation:

1. It needs a \newcommand for every color, which then has to be used as a replacement for the \\ normally found at the end of each table row.
2. The color set globally with \arrayrulecolor is required to be copied into each \newcommand to reset the color back.

What other options are available to locally set the \hline color of a longtable or tabular?

\documentclass[a4paper]{book}
\usepackage{xcolor}             %need xcolor because otherwise color definitions won't work
\usepackage{colortbl}
\usepackage{longtable}
\usepackage{rotating}

%tables: change color of table lines
\arrayrulecolor{gray!50}
%update the newline command to have a line at each row
\newcommand\tgln{\tabularnewline\hline}
%update the newline command to have a blue line at each row
\newcommand\tbln{\tabularnewline\arrayrulecolor{blue!30}\hline\arrayrulecolor{gray!50}}

\newcommand{\bs}{\begin{sideways}}
\newcommand{\es}{\end{sideways}}

\begin{document}
\scriptsize
\begin{longtable}{|p{2.2cm}cp{2cm}c|p{0.15cm}p{0.15cm}p{0.15cm}p{0.15cm}p{0.15cm}p{0.15cm}p{0.15cm}|}
\caption{Overview of a table with a lot of numbers.}\label{tbl:numbers} \\
\hline
Name &  &Location   &Number 1   & \multicolumn{7}{c|}{Items} \\
&   &                   &               &\bs Item 1 \es &\bs Item 2 \es &\bs Item 3 \es &\bs Item 4 \es &\bs Item 5 \es &\bs Item 6 \es &\bs Item 7 \es \\
\hline \endfoot
\hline \endlastfoot
Some name    &Sometext   &Sometext  &100    &   &x  &   &   &   &   &\tgln
Some name    &Sometext   &Sometext  &100    &   &x  &   &   &   &   &\tgln
Some name    &Sometext   &Sometext  &100    &   &x  &   &   &   &   &\tgln
Some name    &Sometext   &Sometext  &100    &   &x  &   &   &   &   &\tgln
Some name    &Sometext   &Sometext  &100    &   &x  &   &   &   &   &\tgln
\end{longtable}

\begin{longtable}{|p{2.2cm}cp{2cm}c|p{0.15cm}p{0.15cm}p{0.15cm}p{0.15cm}p{0.15cm}p{0.15cm}p{0.15cm}|}
\caption{Overview of a table with a lot of numbers.}\label{tbl:numbers} \\
\hline
Name &  &Location   &Number 1   & \multicolumn{7}{c|}{Items} \\
&   &                   &               &\bs Item 1 \es &\bs Item 2 \es &\bs Item 3 \es &\bs Item 4 \es &\bs Item 5 \es &\bs Item 6 \es &\bs Item 7 \es \\
\hline \endfoot
\hline \endlastfoot
Some name    &Sometext   &Sometext  &100    &   &x  &   &   &   &   &\tbln
Some name    &Sometext   &Sometext  &100    &   &x  &   &   &   &   &\tbln
Some name    &Sometext   &Sometext  &100    &   &x  &   &   &   &   &\tbln
Some name    &Sometext   &Sometext  &100    &   &x  &   &   &   &   &\tbln
Some name    &Sometext   &Sometext  &100    &   &x  &   &   &   &   &\tbln
\end{longtable}

\end{document}

• The tabu package might help. – Malipivo Apr 10 '15 at 10:29
• It isn't really clear what your question is. You could obviously re-arrange the syntax of your locally defined commands, but any definitions are going to have to set the parameter for each table, so the top level syntax is just a matter of personal choice. – David Carlisle Apr 10 '15 at 10:37
• @DavidCarlisle. The question is now reformatted so the intention of it is clear. The tabu package was unknown to me, so that is indeed one of the options. – DoubleYou Apr 11 '15 at 23:26

\newcommand\tln[1]{\tabularnewline\arrayrulecolor{#1}\hline}

Some name    &Sometext   &Sometext  &100    &   &x  &   &   &   &   &\tln{green}