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.

In LyX I am using this table as an ERT addition:

\begin{tabular}{l rlrl }

& \multicolumn{2}{c}{Model 1}
& \multicolumn{2}{c@{}}{Model 2}
\midrule
\midrule

Variable Variable Variable 1 (Variable) Variable & 17.122 & * &   3.481 &* 
Variable Variable Variable 2 (Variable) Variable & 76.48 & * &   0.441 &* 
Variable Variable Variable 3 (Variable) Variable & 117.132 & * &   9.216 &* 

\end{tabular}

How can I put a box around the entire Variable 1 row and a box just around the two results for Variable 1

share|improve this question
    
You could perhaps adapt Caramdir's solution to Highlighting table cells –  Torbjørn T. Mar 19 '13 at 16:01

1 Answer 1

table with highlighted rows and cells

This solution uses the colortbl package. The spacing in the first example is not perfect. In the second example this is corrected by using \mystrut. The second example shows also other ideas like \textbf and line breaking in a cell are shown.

The LaTeX code is shown below. For LyX, just copy the marked part to the LyX Preamble (you can set a default color and rule width!) and edit your table according to these examples...

\documentclass{article}
\usepackage{booktabs}

%%% add following to LyX Preamble...
\usepackage{xcolor}
\usepackage{array}
\usepackage{colortbl}

\newcommand{\highlightcolor}{red}  %set default color of the box
\setlength\arrayrulewidth{3pt}     %set default rule width of the box
\newcommand{\mystrut}[2]{\vrule height #1 depth #2 width 0pt}
\newcommand{\coloredhline}{\arrayrulecolor{\highlightcolor}\hline}
%%% ...until here

\begin{document}
\centering

%%% as ERT in LyX
\begin{tabular}{@{\hskip\tabcolsep\hskip\arrayrulewidth}l rlrl }
Table 1&\multicolumn{2}{c}{Model 1} &\multicolumn{2}{c@{}}{Model 2}\\
\midrule \midrule
\coloredhline
\multicolumn{1}{|l}{Variable Variable Variable 1 (Variable) Variable} &17.122 &* &3.481 &\multicolumn{1}{l|}{*}\\
\coloredhline
Variable Variable Variable 2 (Variable) Variable & 76.48 &* &0.441 &* \\
\cline{2-5}
\mystrut{12pt}{0pt}Variable Variable Variable 3 (Variable) Variable &\multicolumn{1}{|l}{117.132} &* &9.216 &\multicolumn{1}{l|}{*} \\
\cline{2-5}
\arrayrulecolor{black}\bottomrule
\end{tabular}

\bigskip

%%% as ERT in LyX: configure color and rulewidth of box
\renewcommand{\highlightcolor}{blue}
\setlength\arrayrulewidth{5pt}
\begin{tabular}{@{\hskip\tabcolsep\hskip\arrayrulewidth}p{5cm} rlrl }
Table 2&\multicolumn{2}{c}{Model 1} &\multicolumn{2}{c@{}}{Model 2}\\
\midrule \midrule \addlinespace[0pt]
\coloredhline
\multicolumn{1}{|p{5cm}}{\mystrut{10pt}{0pt}Variable Variable Variable 1 (Variable) Variable} &17.122 &* &3.481 &\multicolumn{1}{l|}{*}\\
\rowcolor{lightgray}
\multicolumn{1}{|p{5cm}}{Variable Variable Variable 2 (Variable) Variable} & 76.48 &* &0.441 &\multicolumn{1}{l|}{*}\\
\coloredhline
\arrayrulecolor{black}\addlinespace[0pt]\midrule
\textbf{Variable Variable Variable 3 (Variable) Variable} & 117.132 & * & 9.216 &* \\
\bottomrule
\end{tabular}
\end{document}
share|improve this answer

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.