Take the 2-minute tour ×
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.

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}
share|improve this question
    
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
3  
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
add comment

2 Answers 2

up vote 10 down vote accepted

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}

enter image description here

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.

share|improve this answer
    
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
1  
@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
add comment

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

enter image description here

\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}
share|improve this answer
    
thanks! great way to do it but i was hoping to get the color –  Alex Oct 27 '12 at 20:50
1  
you can set hline colous using arrayrulecolor from colortbl and/or hhline packages –  David Carlisle Oct 27 '12 at 21:00
add comment

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.