Hi,
I want to create a table with a colored background. I tried looking into the colortbl package but couldn't get anything usefull out of it. I included an example of the kind of table I want to achieve. Any ideas how this can be done?
Graphics, Figures & Tables ⇒ A table in a colored box
NEW: TikZ book now 40% off at Amazon.com for a short time.

A table in a colored box
Hi,
you can use the shaded environment provided by the framed package; you have to be careful, however, since that environment doesn't cooperate with floating objects (such as thos declared by using the figure or table environments), so you cannot place your table inside a table environment. This implies that you will have to use the \captionof command (provided by the caption package) if you want a caption for your table.
The following code illustrates the above ideas:
you can use the shaded environment provided by the framed package; you have to be careful, however, since that environment doesn't cooperate with floating objects (such as thos declared by using the figure or table environments), so you cannot place your table inside a table environment. This implies that you will have to use the \captionof command (provided by the caption package) if you want a caption for your table.
The following code illustrates the above ideas:
Code: Select all
\documentclass{article}
\usepackage{xcolor}
\usepackage{caption}
\usepackage{framed}
\usepackage{booktabs}
\usepackage{lipsum} % just to generate some text
\definecolor{shadecolor}{rgb}{0.8,0.8,0.8}
\begin{document}
\lipsum[1]
\begin{shaded}
\centering
\captionof{table}{A test table inside a colored box.}
\noindent\begin{tabular}{p{.9\textwidth}}
\toprule
\lipsum[1]\\
\bottomrule
\end{tabular}
\end{shaded}
\lipsum[1]
\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Re: A table in a colored box
Many thanks,
but now I have the problem that the shaded environment can't be stretched over the entire width of the page in a two column document. For regular tables u can use the starred version of the table environment to achieve this:
\begin{table*}
But this doesn't work for the shaded environment unfortunately.
but now I have the problem that the shaded environment can't be stretched over the entire width of the page in a two column document. For regular tables u can use the starred version of the table environment to achieve this:
\begin{table*}
But this doesn't work for the shaded environment unfortunately.
A table in a colored box
Which document class are you using? and how are you setting the two column mode (by using the twocolumn class option or by using the multicol package, for example)?
The following code should do the job in one of the standard document classes using two column mode:
The following code should do the job in one of the standard document classes using two column mode:
Code: Select all
\documentclass[twocolumn]{article}
\usepackage{xcolor}
\usepackage{caption}
\usepackage{booktabs}
\usepackage{lipsum} % just to generate some text
\definecolor{shadecolor}{rgb}{0.8,0.8,0.8}
\begin{document}
\lipsum[1-10]
\begin{table*}
\caption{A test table inside a colored box.}
\colorbox{shadecolor}{
\centering
\noindent\begin{tabular}{p{.9\textwidth}}
\toprule
\lipsum[1]\\
\bottomrule
\end{tabular}}
\end{table*}
\lipsum[1-10]
\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
A table in a colored box
No I'm not using multicol, just the standard way of doing 2 columns.
The code you posted works for me when I add a minipage environment:
The code you posted works for me when I add a minipage environment:
Code: Select all
\documentclass[twocolumn]{article}
\usepackage{xcolor}
\usepackage{caption}
\usepackage{booktabs}
\usepackage{lipsum} % just to generate some text
\definecolor{shadecolor}{rgb}{0.8,0.8,0.8}
\begin{document}
\lipsum[1-10]
\begin{table*}
\caption{A test table inside a colored box.}
\colorbox{shadecolor}{
\begin{minipage}{17cm}
\centering
\noindent\begin{tabular}{p{.9\textwidth}}
\toprule
\lipsum[1]\\
\bottomrule
\end{tabular}
\end{minipage}}
\end{table*}
\lipsum[1-10]
\end{document}