# Adding borders to an entire row in a table

I have a table with multiple rows (a regression table). I would like to add a coloured border highlighting one particular variable. I have found a way to border one cell at a time but is there a way to add a border around an entire row?

EDIT: Here is some detail on my table:

\begin{tabular}{rcccccccc|cccccccc}

&                                                       \multicolumn{ 8}{c}{section 1} &                                                           \multicolumn{ 8}{c}{section 2} \\

&            &            &            &            &            &            &            &            &            &            &            &            &            &            &            &            \\

&        (1) &        (2) &        (3) &        (4) &        (5) &        (6) &        (7) &        (8) &        (9) &       (10) &       (11) &       (12) &       (13) &       (14) &       (15) &       (16) \\

&            &            &            &            &            &            &            &            &            &            &            &            &            &            &            &            \\

regression coef 1 &         no &         no &         no &         no &         no &             no &         no &         no &         no &         no &         no &         no &         no &         no &         no &         no \\

&            &            &            &            &            &            &            &            &            &            &            &            &            &            &            &            \\

regression coef 2 & {\bf 1234} & {\bf 1234} & {\bf 1234} & {\bf 1234} & {\bf 1234} & {\bf 1234} & {\bf 1234} & {\bf 1234} &            &            &            &            &            &            &            &            \\

& {\bf [2]} & {\bf [2]} & {\bf [2]} & {\bf [2]} & {\bf [2]} & {\bf [2]} & {\bf [2]} & {\bf [2]} &            &            &            &            &            &            &            &            \\

\end{tabular}

-
which row would you like to highlight? –  cmhughes Oct 27 '12 at 19:00
how about regression coef 2 –  Alex Oct 27 '12 at 19:02
Not an answer to your question but I would suggest using \begin{tabular}{r*8c|*8c} instead of \begin{tabular}{rcccccccc|cccccccc}. –  mythealias Oct 27 '12 at 19:29
that doesn't seem to work? –  Alex Oct 31 '12 at 21:25
nevermind, it's \begin{tabular}{r*{8}{c}} –  Alex Oct 31 '12 at 22:04

You can use \tikzmark to place some marks at the desired locations and then draw the frame using the marks; a little example:

\documentclass{article}
\usepackage{tikz}
\usepackage{pdflscape}

\newcommand\tikzmark[1]{%
\tikz[remember picture,overlay] \node (#1) {};}

\begin{document}

\begin{landscape}
\begin{tabular}{rcccccccc|cccccccc}
& \multicolumn{ 8}{c}{section 1} & \multicolumn{ 8}{c}{section 2} \\
&            &            &            &            &            &            &            &            &            &            &            &            &            &            &            &            \\
&        (1) &        (2) &        (3) &        (4) &        (5) &        (6) &        (7) &        (8) &        (9) &       (10) &       (11) &       (12) &       (13) &       (14) &       (15) &       (16) \\
&            &            &            &            &            &            &            &            &            &            &            &            &            &            &            &            \\
regression coef 1 &         no &         no &         no &         no &         no &             no &         no &         no &         no &         no &         no &         no &         no &         no &         no &         no \\
&            &            &            &            &            &            &            &            &            &            &            &            &            &            &            &            \\
\tikzmark{a}regression coef 2 & \bfseries 1234 & \bfseries 1234 & \bfseries 1234 & \bfseries 1234 & \bfseries 1234 & \bfseries 1234 & \bfseries 1234 & \bfseries 1234 &            &            &            &            &            &            &            &  \\
& \bfseries [2] & \bfseries [2] & \bfseries [2] & \bfseries [2] & \bfseries [2] & \bfseries [2] & \bfseries [2] & \bfseries [2] &            &            &            &            &            &            &            & \phantom{noo}\tikzmark{b} \\
\end{tabular}

\begin{tikzpicture}[remember picture,overlay]
\draw[line width=1pt,draw=orange!70!black,rounded corners=4pt]
([xshift=-3pt,yshift=7pt]a.north) rectangle ([xshift=3pt,yshift=-5pt]b.south);
\end{tikzpicture}
\end{landscape}

\end{document}


The code needs two runs to stabilize.

As a side note, \bf is a deprecated command; you should use \bfseries instead. Also, the table cells define groups so you don't need to explicitly group using braces.

-
when i do this i get the following error: LaTeX Error: Option clash for package xcolor. –  Alex Oct 27 '12 at 20:19
@Alex simply load xcolor before tikz. –  Gonzalo Medina Oct 27 '12 at 20:25
Ahh ok, let me give that a try. I am very new to latex, could you explain to me what that error means? –  Alex Oct 27 '12 at 20:31
@Alex of course, tikz internally loads xcolor without options; attempting to load xcolor with options after tikz will trigger the error you mentioned; the solution is just to load xcolor with options before tikz. –  Gonzalo Medina Oct 27 '12 at 20:33

You can get fancier borders using tikz but the classic way is to us \hline

\documentclass{article}
\usepackage{pdflscape}

\begin{document}

\begin{landscape}
\begin{tabular}{rcccccccc|cccccccc}
& \multicolumn{ 8}{c}{section 1} & \multicolumn{ 8}{c}{section 2} \\
&            &            &            &            &            &            &            &            &            &            &            &            &            &            &            &            \\
&        (1) &        (2) &        (3) &        (4) &        (5) &        (6) &        (7) &        (8) &        (9) &       (10) &       (11) &       (12) &       (13) &       (14) &       (15) &       (16) \\
&            &            &            &            &            &            &            &            &            &            &            &            &            &            &            &            \\
regression coef 1 &         no &         no &         no &         no &         no &             no &         no &         no &         no &         no &         no &         no &         no &         no &         no &         no \\
&            &            &            &            &            &            &            &            &            &            &            &            &            &            &            &            \\
\hline
\multicolumn{1}{|r}{regression coef 2 }& \bfseries 1234 & \bfseries 1234 & \bfseries 1234 & \bfseries 1234 & \bfseries 1234 & \bfseries 1234 & \bfseries 1234 & \bfseries 1234 &            &            &            &            &            &            &            &\multicolumn{1}{c|}{}  \\
\hline
& \bfseries [2] & \bfseries [2] & \bfseries [2] & \bfseries [2] & \bfseries [2] & \bfseries [2] & \bfseries [2] & \bfseries [2] &            &            &            &            &            &            &            &
\end{tabular}

\end{landscape}

\end{document}

-
thanks! great way to do it but i was hoping to get the color –  Alex Oct 27 '12 at 20:50
you can set hline colous using arrayrulecolor from colortbl and/or hhline packages –  David Carlisle Oct 27 '12 at 21:00