Graphics, Figures & TablesExcel-like tables of experimental data

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

Excel-like tables of experimental data

Post by Cham »

I'm not used with tables in LaTeX. Because of my work place, I usually use Excel.
However, I would like to define in LaTeX a typical table as made with Excel. The only basic example I made is this one, which is compiling fine, but have several issues :

Code: Select all

Code, edit and compile here:
\documentclass[10pt,twoside]{revtex4}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage{microtype}
\usepackage{amsmath}
\usepackage[separate-uncertainty=true]{siunitx}
\sisetup{output-decimal-marker = {,}}
\begin{document}
\section*{A table of results}
\begin{center}
\begin{tabular}{|c|c|c|}
\hline
\multicolumn{3}{|c|}{Tableau 1. Le titre du tableau} \\
\hline
$M$ & $L$ & $\rho$ \\ \hline
$\SI{}{\g}$ & $\SI{}{\cm}$ & $\SI{}{\kg/\m^3}$ \\ \hline
0,2 & 0,5 & – \\ \hline\hline
24,7 & 15,3 & 7,89 \\ \hline
45,2 & 24,0 & 9,65 \\ \hline
49,9 & 28,7 & 6,90 \\ \hline
51,6 & 27,9 & 7,05 \\ \hline
68,1 & 12,6 & 7,46 \\ \hline
72,0 & 16,8 & 6,45 \\ \hline
79,5 & 18,0 & 8,93 \\ \hline
83,2 & 22,1 & 7,12 \\ \hline
88,0 & 34,0 & 7,09 \\ \hline
94,6 & 44,7 & 8,40 \\ \hline
\end{tabular}
\end{center}
\end{document}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Here's a preview :
table.jpg
table.jpg (27.51 KiB) Viewed 9744 times
I don't like this output.

1. The three columns should have an equal horizontal size under the title.
2. The vertical space is too small on each line (see especially the units).
3. The division between the head and the data should not be a gap, but a double line, closed at the ends, like what we could do with Excel.
4. I would like to add a small closed legend under the table, moved to the left of the main table, to add some comments about $M$, $L$ and $\rho$.

So how should I do these things ?

Recommended reading 2024:

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

NEW: TikZ book now 40% off at Amazon.com for a short time.

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Excel-like tables of experimental data

Post by Johannes_B »

That can be done, but the result is pretty ugly.

I added an alternative, which is a bit more simple, avoiding the disturbing grid. Are you numbering your tables by hand? That way, you don't have the advantage of referencing.

Code: Select all

Code, edit and compile here:
\documentclass[10pt,twoside]{revtex4}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage{microtype}
\usepackage{hhline}
\usepackage{booktabs}
\usepackage{caption}
\captionsetup[table]{position=above}
\usepackage{amsmath}
\usepackage[separate-uncertainty=true]{siunitx}
\sisetup{output-decimal-marker = {,}}
\begin{document}
\section*{A table of results}
\begin{center}
\renewcommand{\arraystretch}{1.5}
\begin{tabular}{|S|S|S|}
\hline
\multicolumn{3}{|c|}{Tableau 1. Le titre du tableau} \\
\hline
\multicolumn{1}{|>{\centering}p{6em}}{$M$} & \multicolumn{1}{|>{\centering}p{6em}}{$L$} & \multicolumn{1}{|>{\centering}p{6em}|}{$\rho$} \\ \hline
\si{\g} & \si{\cm} & \si{\kg/\m^3} \\ \hline
0,2 & 0,5 & – \\ \hhline{|=|=|=|}
24,7 & 15,3 & 7,89 \\ \hline
45,2 & 24,0 & 9,65 \\ \hline
49,9 & 28,7 & 6,90 \\ \hline
51,6 & 27,9 & 7,05 \\ \hline
68,1 & 12,6 & 7,46 \\ \hline
72,0 & 16,8 & 6,45 \\ \hline
79,5 & 18,0 & 8,93 \\ \hline
83,2 & 22,1 & 7,12 \\ \hline
88,0 & 34,0 & 7,09 \\ \hline
94,6 & 44,7 & 8,40 \\ \hline
\end{tabular}
\end{center}
\begin{flushleft}
$M$ is the mass\par
$L$ i the length\par
 
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Re: Excel-like tables of experimental data

Post by cgnieder »

A bit off-topic but do you really need/want that layout? excel mostly is a program for doing calculations with tabulated data. There framed cells do make sense. The excel layout isn't really meant for print (which is probably one of the reasons why IIRC you have to actively add frames if you want them in the print version of an excel table).

For tables in documents the question of layout is completely different. Mostly people actually try to avoid horizontal lines as they don't add to readability very much. Vertical often even are distracting since the data usually are arranged in rows rather than columns and hence the tables are read in rows rather than columns…

Best
site moderator & package author
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Excel-like tables of experimental data

Post by Cham »

Johannes_B, thanks a lot. I'll study your solution.

cgnieder, it is not exactly off-topic. I may have a lot to say about this. Firstly, I don't think that this Excel-like table is ugly. I think that on the contrary it is pretty. Of course, this is just a matter of personal taste.

Secondly, in some work places, we don't have much choice because of some standard procedures and conventions. Where I work, Excel is defining a standard of presentation, even if we don't like it. So I don't have a choice here.

Thirdly, I do prefer the LaTeX presentation style for some kind of data. For example, this table below :
table2.jpg
table2.jpg (64.87 KiB) Viewed 9708 times
This data would be horrible in an Excel style.

Then, I think that the table style depends of the type of data.
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Re: Excel-like tables of experimental data

Post by Cham »

Johannes_B,

what I meant for the legend, is a small table inside a frame with title ("Legend"), that should be just under the main table, with the left side aligned. How would you modify your code above to add this feature ?

Also, the numbers aren't exacly centered into their columns. They seem to be aligned with the comma.
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Excel-like tables of experimental data

Post by Cham »

I now have 3 problems with this table :

Code: Select all

Code, edit and compile here:
\documentclass[10pt,twoside]{revtex4}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage{microtype}
\usepackage{hhline}
\usepackage{amsmath}
\usepackage[separate-uncertainty=true]{siunitx}
\sisetup{output-decimal-marker = {,}}
\begin{document}
\section*{A table of results}
\begin{center}
\renewcommand{\arraystretch}{1.5}
\begin{tabular}{|S|S|S|S|}
\hline
\multicolumn{4}{|c|}{Tableau 1. Le titre du tableau} \\ \hline
\multicolumn{1}{|>{\centering}p{6em}}{$m$} & \multicolumn{1}{|>{\centering}p{6em}}{$\ell$} & \multicolumn{1}{|>{\centering}p{6em}}{$\rho$} & \multicolumn{1}{|>{\centering}p{6em}|}{$\Delta\rho$} \\ \hline
\si{\g} & \si{\cm} & \multicolumn{2}{c|}{\si{\kg/\m^3}} \\ \hline
0,2 & 0,5 & \multicolumn{2}{c|}{–} \\ \hhline{|=|=|==|}
24,7 & 15,3 & 7,89 & 0,03 \\ \hline
45,2 & 24,0 & 9,65 & 0,04 \\ \hline
49,9 & 28,7 & 6,90 & 0,01 \\ \hline
51,6 & 27,9 & 7,05 & 0,07 \\ \hline
68,1 & 12,6 & 7,46 & 0,08 \\ \hline
72,0 & 16,8 & 6,45 & 0,02 \\ \hline
79,5 & 18,0 & 8,93 & 0,05 \\ \hline
83,2 & 22,1 & 7,12 & 0,03 \\ \hline
88,0 & 34,0 & 7,09 & 0,02 \\ \hline
94,6 & 44,7 & 8,40 & 0,04 \\ \hline
\end{tabular}
\end{center}
\end{document}
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1. The vertical lines aren't properly aligned. Something is wrong in the code above.
2. Everything should be centered inside their columns. Currently, there is a bit more space on one side than the other side, in the numbers columns. How to fix that ?
3. I need to add a legend below the table, as a small table with a frame and a title. That small table should be left-aligned with the main table.
table3.jpg
table3.jpg (45.02 KiB) Viewed 9707 times
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Excel-like tables of experimental data

Post by Cham »

I have solved the centering problem of the numbers. But I still have the vertical lines not properly aligned, and a missing legend under the main table.

Also, the three instrument names should be flushed to the left in their column, and I need to remove the "a" cells, and vertically center the mass in this example :

Code: Select all

Code, edit and compile here:
\documentclass[10pt,twoside]{revtex4}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage{microtype}
\usepackage{hhline}
\usepackage{amsmath}
\usepackage[separate-uncertainty=true]{siunitx}
\sisetup{output-decimal-marker = {,}}
\begin{document}
\section*{A table of results}
\begin{center}
\renewcommand{\arraystretch}{1.5}
\begin{tabular}{|c|c|c|c|c|c|}
\hline
\multicolumn{6}{|c|}{Tableau 2. Caractéristiques physiques d'un petit cylindre de métal} \\ \hline
\multicolumn{1}{|>{\centering}p{6em}}{Instrument} & \multicolumn{1}{|>{\centering}p{6em}}{$d$} & \multicolumn{1}{|>{\centering}p{6em}}{$\Delta d$} & \multicolumn{1}{|>{\centering}p{6em}}{$\ell$} & \multicolumn{1}{|>{\centering}p{6em}}{$\Delta\ell$} & \multicolumn{1}{|>{\centering}p{6em}|}{$m$} \\ \hline
– & \multicolumn{2}{c|}{\si{\mm}} & \multicolumn{2}{c|}{\si{\mm}} & \si{\g} \\ \hline
– & \multicolumn{2}{c|}{–} & \multicolumn{2}{c|}{–} & 0,1 \\ \hhline{|=|==|==|=|}
\text{Règle} & 15 & 1 & 22 & 1 & 49,3 \\ \hline
\text{Pied à coulisse} & 15,4 & 0,1 & 22,6 & 0,1 & a \\ \hline
\text{Palmer} & 15,42 & 0,03 & 22,57 & 0,02 & a \\ \hline
\end{tabular}
\end{center}
\end{document}
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Preview :
table4.jpg
table4.jpg (40.71 KiB) Viewed 9706 times
This table would be a bit better looking, I think :
table5.jpg
table5.jpg (40.79 KiB) Viewed 9705 times
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Excel-like tables of experimental data

Post by Cham »

Ah ! This table is almost perfect ! :)

There is still a glitch, however, and I need help on this :

Code: Select all

Code, edit and compile here:
\documentclass[10pt,twoside]{revtex4}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage{microtype}
%\usepackage{hhline}
\usepackage{multirow}
\usepackage{amsmath}
\usepackage[separate-uncertainty=true]{siunitx}
\sisetup{output-decimal-marker = {,}}
\begin{document}
\section*{A table of results}
\begin{center}
\renewcommand{\arraystretch}{1.5}
\begin{tabular}{l|c|c|c|c|c|}
\cline{2-6}
& \multicolumn{5}{c|}{Tableau 2. Caractéristiques physiques d'un petit cylindre de métal} \\ \cline{2-6}
& \multicolumn{1}{>{\centering}p{6em}|}{$d$}
& \multicolumn{1}{>{\centering}p{6em}|}{$\Delta d$}
& \multicolumn{1}{>{\centering}p{6em}|}{$\ell$}
& \multicolumn{1}{>{\centering}p{6em}|}{$\Delta\ell$}
& \multicolumn{1}{>{\centering}p{6em}|}{$m$}
\\ \cline{2-6}
& \multicolumn{2}{c|}{\si{\mm}}
& \multicolumn{2}{c|}{\si{\mm}}
& \si{\g}
\\ \cline{2-6}
& \multicolumn{2}{c|}{–}
& \multicolumn{2}{c|}{–}
& 0,1
\\ \hline\hline
\multicolumn{1}{|l|}{Règle} & 15 & 1 & 22 & 1 & \multirow{3}{*}{49,3} \\ \cline{1-5}
\multicolumn{1}{|l|}{Pied à coulisse} & 15,4 & 0,1 & 22,6 & 0,1 & \\ \cline{1-5}
\multicolumn{1}{|l|}{Palmer} & 15,42 & 0,03 & 22,57 & 0,02 & \\ \hline
\end{tabular}
\end{center}
\end{document}
 
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Preview :
table6.jpg
table6.jpg (33.08 KiB) Viewed 9702 times
The double line shouldn't start at the left. It should start one coloumn to the right instead.

Also, I need to add a legend (with a frame and a title) under the main table, to the left.
I don't know how to do this.

Please help ! I'm almost there ! :oops: :|
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Excel-like tables of experimental data

Post by Cham »

I got the legend. But I need to know if this is the proper way of doing it.

I also need to fix that double-line (please HELP ! This one appears to be hard) :

Code: Select all

Code, edit and compile here:
\documentclass[10pt,twoside]{revtex4}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage{microtype}
%\usepackage{hhline}
\usepackage{multirow}
\usepackage{amsmath}
\usepackage[separate-uncertainty=true]{siunitx}
\sisetup{output-decimal-marker = {,}}
\begin{document}
\section*{A table of results}
\begin{align*}
&
\renewcommand{\arraystretch}{1.5}
\begin{tabular}{l|c|c|c|c|c|}
\cline{2-6}
& \multicolumn{5}{c|}{Tableau 2. Caractéristiques physiques d'un petit cylindre de métal} \\ \cline{2-6}
& \multicolumn{1}{>{\centering}p{6em}|}{$d$}
& \multicolumn{1}{>{\centering}p{6em}|}{$\Delta d$}
& \multicolumn{1}{>{\centering}p{6em}|}{$\ell$}
& \multicolumn{1}{>{\centering}p{6em}|}{$\Delta\ell$}
& \multicolumn{1}{>{\centering}p{6em}|}{$m$}
\\ \cline{2-6}
& \multicolumn{2}{c|}{\si{\mm}}
& \multicolumn{2}{c|}{\si{\mm}}
& \si{\g}
\\ \cline{2-6}
& \multicolumn{2}{c|}{–}
& \multicolumn{2}{c|}{–}
& 0,1
\\ \hline\hline
\multicolumn{1}{|l|}{Règle} & 15 & 1 & 22 & 1 & \multirow{3}{*}{49,3} \\ \cline{1-5}
\multicolumn{1}{|l|}{Pied à coulisse} & 15,4 & 0,1 & 22,6 & 0,1 & \\ \cline{1-5}
\multicolumn{1}{|l|}{Palmer} & 15,42 & 0,03 & 22,57 & 0,02 & \\ \hline
\end{tabular} \\[10pt]
&
\renewcommand{\arraystretch}{1.5}
 
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Preview :
table7.jpg
table7.jpg (39.92 KiB) Viewed 9694 times
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Excel-like tables of experimental data

Post by Johannes_B »

The amount of posts getting to the solution and your urgent request for help tells me one thing: You are terribly stuck. Look at my signature, keep calm, take a break, drink a cup of tea or coffee. When the mind thinks that stuff is complicated, it is harder to find a solution.

Package hhline gives you all you need.
\hhline{b-=====}

Is there a reason for using the align environment? Better put that whole thing into a minipage.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Post Reply