August 23rd, 2011 by Stefan Kottwitz
Eddy asked on TeX.SX:
How to color the font of a single row in a table?
I have a table and I want to make the font color red for just one row (not the background). How do I do that? Here’s my table:
\begin{tabular}{ l | l l l l }
& 1 & 2 & 3 & 4 \\
\hline
1 & A & B & C & D \\
2 & A & B & C & D \\
3 & A & B & C & D \\
4 & A & B & C & D \\
\end{tabular}
Answer:
You could use the tabu environment of the tabu package with the command \rowfont, for example:
\documentclass{article}
\usepackage{tabu}
\usepackage{xcolor}
\begin{document}
\begin{tabu}{ l | l l l l }
\rowfont{\color{red}}
& 1 & 2 & 3 & 4 \\
\hline
1 & A & B & C & D \\
2 & A & B & C & D \\
3 & A & B & C & D \\
4 & A & B & C & D \\
\end{tabu}
\end{document}
Category: Tables |
No Comments »
Juli 12th, 2011 by Stefan Kottwitz
BrettHarry asked on TeX.SX:
How to merge columns in a table?
I have this table, but wanted to format the first row. I like to match the two columns of first row, and last two columns of the same first row. Any suggestion on how to do that?
\begin{table}[!h]
\caption{Comparison of percentages.}
\begin{tabular}{lclclclclc}
\hline
\hline
Mode & Var & Cum\\
\hline
{} & EF & CHF & EF2 & CHF2\\
1 & 17.5 & 19.1 & 17.5 & 19.1\\
2 & 11.8 & 12.7 & 29.3 & 31.9\\
3 & 6.6 & 5.6 & 35.9 & 37.4\\
\hline
\end{tabular}
\end{table}
Answer:
An example, how it can be done using \multicolum, with some improvements using booktabs:
\documentclass{article}
\usepackage{array}
\usepackage{booktabs}
\setlength{\heavyrulewidth}{1.5pt}
\setlength{\abovetopsep}{4pt}
\begin{document}
\begin{table}[!htbp]
\centering
\caption{Comparison of percentages.}
\begin{tabular}{*5c}
\toprule
Mode & \multicolumn{2}{c}{Var} & \multicolumn{2}{c}{Cum}\\
\midrule
{} & EF & CHF & EF2 & CHF2\\
1 & 17.5 & 19.1 & 17.5 & 19.1\\
2 & 11.8 & 12.7 & 29.3 & 31.9\\
3 & 6.6 & 5.6 & 35.9 & 37.4\\
\bottomrule
\end{tabular}
\end{table}
\end{document}
Category: Tables |
No Comments »