Information and discussion about graphics, figures & tables in LaTeX documents.
Cham
Posts: 937 Joined: Sat Apr 02, 2011 4:06 pm
Post
by Cham » Thu Feb 16, 2012 3:31 am
I'm doing my first "standard" table, and I'm wondering about the quality output. How can I improve it ?
Here's a compilable sample :
Code: Select all
\documentclass[12pt,letterpaper,twoside]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage{amsmath}
\usepackage{tensor}
\begin{document}
\begin{tabular}{|c|l|c|c|c|c|}
\hline
\multicolumn{6}{|c|}{\bf Title (white on black ?)} \\
\hline\hline
Model & & $\tensor{\Omega}{_{\text\it mat}}$ & $\tensor{\Omega}{_{\text\it rad}}$ & $\tensor{\Omega}{_{\Lambda}}$ & $k$ \\
\hline
\hline
1 & A description & 0 & 0 & 0 & -1 \\
\hline
2 & Another small text & 1 & 0 & 0 & 0 \\
\hline
3 & Small text & 4 & 0 & 0 & 1 \\
\hline
\end{tabular}
\end{document}
There's a preview below.
I would like to have its title in
white on a black background (I already have tuned ON the
xcolor package), and the column's width should be the same for the last four columns. How ?
Also, how can I make the horizontal lines (\hline) medium gray ?
Attachments
sample.jpg (21.99 KiB) Viewed 7055 times
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide : 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook : 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ : the first book about TikZ for perfect drawings in your LaTeX thesis
Cham
Posts: 937 Joined: Sat Apr 02, 2011 4:06 pm
Post
by Cham » Thu Feb 16, 2012 5:16 am
I just discovered the
colortbl package. But I'm wondering if there are other simple ways to do this.
This table is now pretty nice
! (compilable example)
Code: Select all
\documentclass[12pt,letterpaper,twoside]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage{amsmath}
\usepackage{tensor}
\usepackage{xcolor}
\usepackage{colortbl}
\begin{document}
\begin{table}[H]
\centering
\begin{tabular}{|c|l|c|c|c|c|}
\hline
\multicolumn{6}{|>{\columncolor[gray]{0.0} \color{white}} c|}{\bf A white on black title} \\
\hline
\rowcolor[gray]{0.9} Curve & & $\tensor{\Omega}{_{\text\it mat}}$ & $\tensor{\Omega}{_{\text\it rad}}$ & $\tensor{\Omega}{_{\Lambda}}$ & $k$ \\
\hline
\hline
1 & Univers vide & 0 & 0 & 0 & $-1$ \\
%\hline
\rowcolor[gray]{0.96} 2 & Univers de poussières & 1 & 0 & 0 & $0$ \\
%\hline
3 & Univers clos & 4 & 0 & 0 & $1$ \\
%\hline
\rowcolor[gray]{0.96} 4 & Univers de radiation & 0 & 1 & 0 & $0$ \\
%\hline
5 & Univers de deSitter & 0 & 0 & 1 & $0$ \\
%\hline
\rowcolor[gray]{0.96} 6 & $\Lambda$CDM & 0.3 & 0 & 0.7 & $0$ \\
\hline
\end{tabular}
\caption{A caption.}
\end{table}
\end{document}
However, how can I tell LaTeX to give the last four columns the same width ?
A preview from the code above :
table.jpg (39.64 KiB) Viewed 7054 times
Stefan Kottwitz
Site Admin
Posts: 10350 Joined: Mon Mar 10, 2008 9:44 pm
Post
by Stefan Kottwitz » Thu Feb 16, 2012 9:41 am
Hi Cham,
Cham wrote: However, how can I tell LaTeX to give the last four columns the same width?
you could use
p
columns with a fixed width. If you also load the
array
package, this would work well:
Code: Select all
\begin{tabular}{|c|l|*4{>{\centering\arraybackslash}p{1cm}|}}
Do you expect the table to be read column for column, from top to bottom? I guess I would read such a table from left to right. In this case, vertical lines blocking the way between cells would not be so good.
Stefan
LaTeX.org admin
Cham
Posts: 937 Joined: Sat Apr 02, 2011 4:06 pm
Post
by Cham » Thu Feb 16, 2012 12:47 pm
Stefan_K wrote: you could use p
columns with a fixed width. If you also load the array
package, this would work well:
Works very well. Thanks Stefan.
About the column separations, I'm not sure yet. Yes, the table is to be read from left to right. You suggest to remove the vertical lines ?
Maybe alternate gray cells ?
EDIT : Now what about gray vertical lines ? How can I do that ?
cgnieder
Site Moderator
Posts: 2000 Joined: Sat Apr 16, 2011 7:27 pm
Post
by cgnieder » Thu Feb 16, 2012 1:09 pm
This might be a matter of taste, but I'd prefer as few horizontal lines as possible and no vertical lines and colors at all:
Code: Select all
\documentclass[12pt,letterpaper,twoside]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage{amsmath,tensor,booktabs,array}
\begin{document}
\begin{tabular}{cl*4{>{\centering\arraybackslash$}p{1cm}<{$}}}\toprule
\multicolumn{6}{c}{\bfseries Title (white on black ?)} \\ \midrule
Model & & \tensor{\Omega}{_{\text{\itshape mat}}} & \tensor{\Omega}{_{\text{\itshape rad}}} & \tensor{\Omega}{_{\Lambda}} & k \\
1 & A description & 0 & 0 & 0 & -1 \\
2 & Another small text & 1 & 0 & 0 & 0 \\
3 & Small text & 4 & 0 & 0 & 1 \\
\bottomrule
\end{tabular}
\end{document}
booktabs.png (18.18 KiB) Viewed 7044 times
Cham
Posts: 937 Joined: Sat Apr 02, 2011 4:06 pm
Post
by Cham » Thu Feb 16, 2012 1:15 pm
Hmm, I think this table is too simple.
How can I improve this one ? I'm not sure about the gray vertical lines.
Code: Select all
\documentclass[12pt,letterpaper,twoside]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage{amsmath}
\usepackage{tensor}
\usepackage{xcolor}
\usepackage{colortbl}
\begin{document}
\begin{table}[H]
\centering
\begin{tabular}{!{\color{lightgray}\vline}c!{\color{lightgray}\vline}l!{\color{lightgray}\vline}*4{>{\centering\arraybackslash}p{1cm}!{\color{lightgray}\vline}}}
\hline
\multicolumn{6}{|>{\columncolor[gray]{0.35} \color{white}} c|}{\bf A simple title} \\
\hline
\rowcolor[gray]{0.9} $\mathcal{C}$ & & $\tensor{\Omega}{_{\text\it mat}}$ & $\tensor{\Omega}{_{\text\it rad}}$ & $\tensor{\Omega}{_{\Lambda}}$ & $k$ \\
\hline
\hline
1 & Univers vide : & 0 & 0 & 0 & $-1$ \\
%\hline
\rowcolor[gray]{0.95} 2 & Univers de poussières : & 1 & 0 & 0 & $0$ \\
%\hline
3 & Univers clos : & 4 & 0 & 0 & $1$ \\
%\hline
\rowcolor[gray]{0.95} 4 & Univers de radiation : & 0 & 1 & 0 & $0$ \\
%\hline
5 & Univers de deSitter : & 0 & 0 & 1 & $0$ \\
%\hline
\rowcolor[gray]{0.95} 6 & $\Lambda$CDM : & 0.3 & 0 & 0.7 & $0$ \\
\hline
\end{tabular}
\caption{A caption.}
\end{table}
\end{document}
Preview :
table2.jpg (38.26 KiB) Viewed 7044 times
Stefan Kottwitz
Site Admin
Posts: 10350 Joined: Mon Mar 10, 2008 9:44 pm
Post
by Stefan Kottwitz » Thu Feb 16, 2012 1:19 pm
Very nice! Perhaps some additional
@{}
for removing space on the left and on the right, and if you need separation of subtitles, partial mid lines, with
\cmidrule
of
booktabs
.
Code: Select all
\begin{tabular}{@{}cl*4{>{\centering\arraybackslash$}p{1cm}<{$}}@{}}\toprule
\multicolumn{6}{c}{\bfseries Title (white on black ?)} \\ \midrule
Model & & \tensor{\Omega}{_{\text{\itshape mat}}} & \tensor{\Omega}{_{\text{\itshape rad}}} & \tensor{\Omega}{_{\Lambda}} & k \\
\cmidrule(r){1-1}\cmidrule(lr){3-3}\cmidrule(lr){4-4}\cmidrule(lr){5-5}\cmidrule(l){6-6}
1 & A description & 0 & 0 & 0 & -1 \\
2 & Another small text & 1 & 0 & 0 & 0 \\
3 & Small text & 4 & 0 & 0 & 1 \\
\bottomrule
\end{tabular}
table.png (6.52 KiB) Viewed 7045 times
Stefan
LaTeX.org admin
Cham
Posts: 937 Joined: Sat Apr 02, 2011 4:06 pm
Post
by Cham » Thu Feb 16, 2012 1:34 pm
Funny, the aesthetical choice may be much harder than what I though.
I think the first table from this code may be a good one. However, how about alternate gray/white columns, instead of gray/white lines ?
Code: Select all
\documentclass[12pt,letterpaper,twoside]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage{amsmath}
\usepackage{tensor}
\usepackage{booktabs}
\usepackage{xcolor}
\usepackage{colortbl}
\begin{document}
\begin{table}[H]
\centering
\begin{tabular}{cl*4{>{\centering\arraybackslash}p{1cm}}}
\hline
\multicolumn{6}{|>{\columncolor[gray]{0.35} \color{white}} c|}{\bf A simple title} \\
\hline
\rowcolor[gray]{0.9} $\mathcal{C}$ & & $\tensor{\Omega}{_{\text\it mat}}$ & $\tensor{\Omega}{_{\text\it rad}}$ & $\tensor{\Omega}{_{\Lambda}}$ & $k$ \\
\hline
1 & Univers vide : & 0 & 0 & 0 & $-1$ \\
%\hline
\rowcolor[gray]{0.95} 2 & Univers de poussières : & 1 & 0 & 0 & $0$ \\
%\hline
3 & Univers clos : & 4 & 0 & 0 & $1$ \\
%\hline
\rowcolor[gray]{0.95} 4 & Univers de radiation : & 0 & 1 & 0 & $0$ \\
%\hline
5 & Univers de deSitter : & 0 & 0 & 1 & $0$ \\
%\hline
\rowcolor[gray]{0.95} 6 & $\Lambda$CDM : & 0.3 & 0 & 0.7 & $0$ \\
\hline
\end{tabular}
\caption{A caption.}
\end{table}
\begin{table}[H]
\centering
\begin{tabular}{cl*4{>{\centering\arraybackslash$}p{1cm}<{$}}}
\toprule
\multicolumn{6}{c}{\bfseries Title (white on black ?)} \\
\midrule
$\mathcal{C}$ & & \tensor{\Omega}{_{\text{\itshape mat}}} & \tensor{\Omega}{_{\text{\itshape rad}}} & \tensor{\Omega}{_{\Lambda}} & k \\
1 & Univers vide : & 0 & 0 & 0 & -1 \\
2 & Univers clos : & 1 & 0 & 0 & 0 \\
3 & Small text & 4 & 0 & 0 & 1 \\
4 & Univers de radiation : & 0 & 1 & 0 & $0$ \\
5 & Univers de deSitter : & 0 & 0 & 1 & $0$ \\
6 & $\Lambda$CDM : & 0.3 & 0 & 0.7 & $0$ \\
\bottomrule
\end{tabular}
\caption{A caption.}
\end{table}
\end{document}
Preview :
table3.jpg (69.7 KiB) Viewed 7045 times
Cham
Posts: 937 Joined: Sat Apr 02, 2011 4:06 pm
Post
by Cham » Thu Feb 16, 2012 1:49 pm
Hmm, what about this version ?
table4.jpg (35.57 KiB) Viewed 7044 times
I'm not sure about the title bar, however. It's a bit too close to the second line. Any suggestion ?
Cham
Posts: 937 Joined: Sat Apr 02, 2011 4:06 pm
Post
by Cham » Thu Feb 16, 2012 2:03 pm
I'm getting closer !
It's better without the heavy title bar, especially since there's already a caption below the table.
table5.jpg (86.67 KiB) Viewed 7043 times
I'm not sure about the double rulers yet. Maybe I should add an extra vertical space below the first line...