6

Possible Duplicate:
Color entire table

How can I color the background of a tabular environment?

\documentclass{scrartcl}
\usepackage[ngerman]{babel}
\usepackage{color}

\begin{document}

\mbox{}\hfill\begin{tabular}{|lp{10cm}|}
\hline
\multicolumn{2}{|c|}{\textbf{Test}}\\
\hline
Test: & Test\\
Test: & Test\\
\hline
\end{tabular}\hfill\mbox{}

\end{document}
2

1 Answer 1

4

Xcolor

Try xcolor You can even set alternating colors

\documentclass[table]{scrartcl}
\usepackage[ngerman]{babel}
\usepackage{xcolor}

\begin{document}
\colorbox{red}{
 \begin{tabular}{|lp{10cm}|}
  \hline
  \multicolumn{2}{|c|}{\textbf{Test}}\\
  \hline
   Test: & Test\\
   Test: & Test\\
  \hline
 \end{tabular}
 }

\rowcolors*{1}{red}{red}
\begin{tabular}{|lp{10cm}|}
\hline
\multicolumn{2}{|c|}{\textbf{Test}}\\
\hline
Test: & Test\\
Test: & Test\\
\hline
\end{tabular}

\end{document}

enter image description here

(Just for my sake i'd like to say that typographically spoken vertical rules are odd. Avoid them. And i stripped \mbox{}.. cause i can't see the purpose. )

Tabu

The tabu Package provides you with some more convenient commands

\documentclass[table]{scrartcl}
\usepackage{xcolor}
\usepackage{tabu}

\begin{document}




\taburowcolors [1] 7 {green .. brown}

\begin{tabu}{|lp{10cm}|}
\hline
\multicolumn{2}{|c|}{\textbf{Test}}\\
\hline
Test: & Test\\
Test: & Test\\
Test: & Test\\
Test: & Test\\
Test: & Test\\
Test: & Test\\
\hline
\end{tabu}


\end{document}

enter image description here

2
  • I get the error: "LaTeX Error: File `colortbl.sty' not found."
    – guest
    Commented Dec 12, 2012 at 15:04
  • Ok, I guess the [table] option belongs to xcolor.
    – guest
    Commented Dec 12, 2012 at 15:07

Not the answer you're looking for? Browse other questions tagged .