GeneralI need to add some color to tables

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
User avatar
tripwire45
Posts: 129
Joined: Thu Apr 10, 2008 4:35 am

I need to add some color to tables

Post by tripwire45 »

I'm in the process of re-creating existing Word documentation for a company in LaTeX. I'd like to keep the presentation as close to the originals as possible. This includes tables with a very specific formatting. I've been Googling all morning long, and while I've solved some problems, other solutions aren't presenting themselves.

I have succeeded in finding a way to color alternating rows in a table but I need to find a way to also color the text and the horizontal lines that make up the table. I also can't seem to find a way to create a header row and bold the (ideally colored) text in that row. Here's what I have so far:

In the preamble, I added:

Code: Select all

\usepackage[table ]{ xcolor}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The table itself is as follows:

Code: Select all

Code, edit and compile here:
\begin{table}[hbp]
\rowcolors{2}{purple!15}{}
\begin{tabular}{c p{12cm}p{12cm}|}
\hline
Item & Details \\
\hline
A & Sample text for the first row \\
B & Sample text for the second row and blah blah blah blah blah blah blah blah blah blah blah blah blah \\
C & Sample text for the third row and blah blah blah blah blah blah blah blah blah blah blah blah blah \\
\hline
\end{tabular}
\end{table}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
I know this probably isn't as sophisticated as it could be, but I've been working with LaTeX for less than a week and am just figuring out how to do things. I'm working in Kile, if that makes any difference.

Thanks.

-Trip

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX books
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

I need to add some color to tables

Post by localghost »

Your descriptions are good, but for the last details it could be helpful to have a screen shot to figure out how the tables really look like. You can post that as an attachment here. For the present I can provide a table with coloured text and nice looking horizontal lines.

Code: Select all

Code, edit and compile here:
\documentclass[BCOR13mm,DIV15]{scrartcl}
\usepackage{fixltx2e}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{array,booktabs}
\usepackage[table]{xcolor}
\begin{document}
\centering
\begin{table}[!ht]
\rowcolors{2}{purple!15}{}
\begin{tabular}{c>{\color{blue!50}}m{12cm}} \toprule
Item & Details \\ \midrule
A & Sample text for the first row \\
B & Sample text for the second row and blah blah blah blah blah blah blah blah blah blah blah blah blah \\
C & Sample text for the third row and blah blah blah blah blah blah blah blah blah blah blah blah blah \\ \bottomrule
\end{tabular}
\caption{A table with several colours}\label{tab:colortable}
\end{table}
\end{document}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The used document classes and packages and their documentations can be found on CTAN, in the TeX Catalogue Online or on your local machine via shell

Code: Select all

texdoc booktabs
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Best regards
Thorsten¹
User avatar
tripwire45
Posts: 129
Joined: Thu Apr 10, 2008 4:35 am

I need to add some color to tables

Post by tripwire45 »

Thanks. I'll have a look at how your source works in a minute. In the meantime, another issue came up. I thought I had the issue of wrapping text in a table cell worked out but apparently not, as my next example will illustrate. I also want the first column not to be as wide as the second, but changing the "p" values doesn't seem to yield the desired effect.

Before getting into that, the attachment "table.png" will illustrate the result of the source I previously posted. The attachment table2.png will illustrate the result of the source to follow:

Code: Select all

Code, edit and compile here:
\begin{table}[hbp]
\rowcolors{1}{purple!15}{}
\begin{tabular}{c p{12cm}p{12cm}|}
\hline
\multicolumn{2}{l}{Summary of This and That} \\
\hline
Sample text for the first row and blah & Sample text for the first row, second column and blah blah blah blah blah blah blah blah blah blah blah blah blah \\
LB & Lucus Radebe \\
DC & Michael Duberry \\
DC & Dominic Matteo \\
RB & Didier Domi \\
MC & David Batty \\
MC & Eirik Bakke \\
MC & Jody Morris \\
FW & Jamie McMaster \\
ST & Alan Smith \\
ST & Mark Viduka \\
\multicolumn{2}{c}{For more information see such and thus} \\
\hline
\end{tabular}
\end{table}
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Thanks again.

EDIT: What you posted is very close to what I need, but I would like to make *all* of the text in the table the same color. Thanks.
Attachments
table2.png
table2.png (30.41 KiB) Viewed 7485 times
table.png
table.png (13.1 KiB) Viewed 7489 times
User avatar
tripwire45
Posts: 129
Joined: Thu Apr 10, 2008 4:35 am

Re: I need to add some color to tables

Post by tripwire45 »

:bump:

I've been looking at the source you provided Thorsten, but I can't see how to make all of the text take on the same color, rather than just the right column. If I could apply the color to *all* of the text, that would be perfect. Thanks.
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

I need to add some color to tables

Post by gmedina »

The part responsible for the colored text in the right column is >{\color{blue!50}} just before the m{12cm} specifier in the table format declaration. Apply >{\color{blue!50}} just before the c specifier for the first column.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
User avatar
tripwire45
Posts: 129
Joined: Thu Apr 10, 2008 4:35 am

I need to add some color to tables

Post by tripwire45 »

Close. Very close. Here's my adaptation:

Code: Select all

Code, edit and compile here:
\begin{table}[!hbp]
\rowcolors{2}{purple!15}{}
\begin{tabular}{>{\color{purple!95}}c>{\color{purple!95}}m{6cm}p{6cm}} \toprule
\multicolumn{2}{l}{Summary of Nonsense Requirements} \\ \midrule
\multirow{2}{*}{Build and maintain a nonsense word} & Requirement 1: Install and maintain a nonsense configuration to protect nonsense \\
& Requirement 2: Install and maintain a nonsense configuration to protect nonsense \\
\multirow{2}{*}{Build and maintain a nonsense word} & Requirement 3: Install and maintain a nonsense configuration to protect nonsense \\
& Requirement 4: Install and maintain a nonsense configuration to protect nonsense \\
\multirow{2}{*}{Build and maintain a nonsense word} & Requirement 5: Install and maintain a nonsense configuration to protect nonsense \\
& Requirement 6: Install and maintain a nonsense configuration to protect nonsense \\
\multirow{3}{*}{Build and maintain a nonsense word} & Requirement 7: Install and maintain a nonsense configuration to protect nonsense \\
& Requirement 8: Install and maintain a nonsense configuration to protect nonsense \\
& Requirement 9: Install and maintain a nonsense configuration to protect nonsense \\
\hline
\multicolumn{2}{c}{For more information on blah blah blah, visit the such and thus website at} \\
\multicolumn{2}{c}{http://www.suchandthusbogus.org} \\
\bottomrule
\end{tabular}
\caption{Summary of blah blah blah}\label{tab:Summary of blah blah blah}
\end{table}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
What I need is to also color the text in the "header and "footer" rows the same color (\multicolumn). I've tried several combinations, but just end up breaking the compile process. I'm attaching a screen capture for reference.

Thanks...progress is being made.
Attachments
table3.png
table3.png (67.16 KiB) Viewed 7433 times
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

I need to add some color to tables

Post by gmedina »

Following my last suggestion, you could use

Code: Select all

\multicolumn{2}{>{\color{purple!95}}l}{Summary of Nonsense Requirements}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Another option would be

Code: Select all

\multicolumn{2}{l}{\textcolor{purple!95}{Summary of Nonsense Requirements}}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Post Reply