Graphics, Figures & TablesA better table ?

Information and discussion about graphics, figures & tables in LaTeX documents.
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

A better table ?

Post by Cham »

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
sample.jpg (21.99 KiB) Viewed 7058 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

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

User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

A better table ?

Post by Cham »

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 8-) ! (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
table.jpg (39.64 KiB) Viewed 7057 times
User avatar
Stefan Kottwitz
Site Admin
Posts: 10350
Joined: Mon Mar 10, 2008 9:44 pm

A better table ?

Post by Stefan Kottwitz »

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
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

A better table ?

Post by Cham »

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 ?
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

A better table ?

Post by cgnieder »

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
booktabs.png (18.18 KiB) Viewed 7047 times
site moderator & package author
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

A better table ?

Post by Cham »

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
table2.jpg (38.26 KiB) Viewed 7047 times
User avatar
Stefan Kottwitz
Site Admin
Posts: 10350
Joined: Mon Mar 10, 2008 9:44 pm

A better table ?

Post by Stefan Kottwitz »

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
table.png (6.52 KiB) Viewed 7048 times
Stefan
LaTeX.org admin
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

A better table ?

Post by Cham »

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
table3.jpg (69.7 KiB) Viewed 7048 times
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

A better table ?

Post by Cham »

Hmm, what about this version ?
table4.jpg
table4.jpg (35.57 KiB) Viewed 7047 times
I'm not sure about the title bar, however. It's a bit too close to the second line. Any suggestion ?
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

A better table ?

Post by Cham »

I'm getting closer ! :D It's better without the heavy title bar, especially since there's already a caption below the table.
table5.jpg
table5.jpg (86.67 KiB) Viewed 7046 times
I'm not sure about the double rulers yet. Maybe I should add an extra vertical space below the first line...
Post Reply