Graphics, Figures & TablesHow to generate tables like in scientific journals

Information and discussion about graphics, figures & tables in LaTeX documents.
Isopropyl
Posts: 29
Joined: Thu Sep 24, 2009 10:49 pm

How to generate tables like in scientific journals

Post by Isopropyl »

Hi there,

sorry to bother you with my table questions, but I have always wondered how one could generate in LaTeX a table with a bottomrule under the tablenotes (well, in fact I would like to make such a table). I have included a screenshot of a journal article to serve as example. I had to pixelize it because it is probably copyrighted material, but I think one can still make out the general structure. The table has a short rule above the footnotes (labeled a and b) and a heavy rule beneath them. Is it possible to generate such a table with LaTeX?
Attachments
Table.png
Table.png (22.11 KiB) Viewed 11711 times

Recommended reading 2024:

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

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

Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

How to generate tables like in scientific journals

Post by Stefan Kottwitz »

Hi,

I recommend to use the booktabs package for that purpose, have a look at its documentation.

Stefan
LaTeX.org admin
Isopropyl
Posts: 29
Joined: Thu Sep 24, 2009 10:49 pm

Re: How to generate tables like in scientific journals

Post by Isopropyl »

Hi,

thank you for your reply. I am already using the booktabs package but what I do not know is how to actually get the footnotes into the table. I am using treeparttable to generate tablenotes and can only get them under the table...
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

How to generate tables like in scientific journals

Post by localghost »

I'm not aware of a package or something similar. So I did a manual approach.

Code: Select all

\documentclass[11pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage[font=small,labelfont={bf,sf},tableposition=top]{caption}
\usepackage{booktabs}

\begin{document}
  \begin{table}[!ht]
    \caption{Table caption}\label{tab:notes}
    \centering
    \begin{tabular}{lccccc}\toprule
      Item & n & Mean & Median & Minimum & Maximum \\ 
      An item & 1 & Value\textsuperscript{1} & Value\textsuperscript{2} & Value\textsuperscript{3} & Value\textsuperscript{4} \\ \cmidrule{1-2}
      \multicolumn{6}{l}{\footnotesize \textsuperscript{1}\,Footnote inside a table} \\
      \multicolumn{6}{l}{\footnotesize \textsuperscript{2}\,Footnote inside a table} \\
      \multicolumn{6}{l}{\footnotesize \textsuperscript{3}\,Footnote inside a table} \\
      \multicolumn{6}{l}{\footnotesize \textsuperscript{4}\,Footnote inside a table} \\ \bottomrule
    \end{tabular}
  \end{table}
\end{document}
Consider this as a very basic structure. Some enhancements may be done with tabularx.


Best regards
Thorsten
Isopropyl
Posts: 29
Joined: Thu Sep 24, 2009 10:49 pm

Re: How to generate tables like in scientific journals

Post by Isopropyl »

Thank you very much, Thorsten. I will try this!
Isopropyl
Posts: 29
Joined: Thu Sep 24, 2009 10:49 pm

Re: How to generate tables like in scientific journals

Post by Isopropyl »

Ah, I just tried it and I discovered a small problem. If I do my tablenotes by hand, how can I make sure the second and further lines of a longer note will align with the beginning of the first line (excluding the number)? At the moment I am adding an indent to the first line in order to have some space between the tablenote number and the text. But the since the note is long it will linewrap and start the second line directly under the tablenote number...
Isopropyl
Posts: 29
Joined: Thu Sep 24, 2009 10:49 pm

How to generate tables like in scientific journals

Post by Isopropyl »

Okay, so I tried to do a workaround by defining a new list environment like this:

Code: Select all

\newenvironment{TableNotes}[1]
{\begin{list}{}%
 {\renewcommand\makelabel[1]{\textsuperscript{##1}\hfill}%
 \singlespacing
 \setlength\topsep{0pt}
 \setlength\itemsep{0pt}
 \setlength\parsep{0pt}
 \setlength\partopsep{0pt}
 \settowidth\labelwidth{\makelabel{#1}}%
 \setlength\leftmargin{\labelwidth+\labelsep}}}%
{\end{list}}%
Unfortunately, while the spacing of the items themselves is fine, I still get a huge white space above and below the single multicolumn containing my notes. Is there any way to reduce the whitespace around an environment?
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

How to generate tables like in scientific journals

Post by localghost »

The idea with the list environment looks good and I will take a look on that later. In the meantime I had an idea with two tables and the above mentioned tabularx.

Code: Select all

\documentclass[11pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage[font=small,labelfont={bf,sf},tableposition=top]{caption}
\usepackage{booktabs,tabularx}

\begin{document}
  \begin{table}[!ht]
    \caption{Table caption}\label{tab:notes}
    \centering
    \begin{tabularx}{\linewidth}{Xccccc}\toprule
      Item & n & Mean & Median & Minimum & Maximum \\ \midrule
      An item & 1 & Value\textsuperscript{1} & Value\textsuperscript{2} & Value\textsuperscript{3} & Value\textsuperscript{4} \\
      An item & 2 & Value & Value & Value & Value \\
      An item & 3 & Value & Value & Value & Value \\ \addlinespace
    \end{tabularx}
    \footnoterule
    \footnotesize
    \begin{tabularx}{\linewidth}{@{}l@{\,}X@{}}
      \textsuperscript{1}& Footnote inside a table. Footnote inside a table. Footnote inside a table. Footnote inside a table. \\
      \textsuperscript{2}& Footnote inside a table. Footnote inside a table. Footnote inside a table. Footnote inside a table. \\
      \textsuperscript{3}& Footnote inside a table. Footnote inside a table. Footnote inside a table. Footnote inside a table. \\
      \textsuperscript{4}& Footnote inside a table. Footnote inside a table. Footnote inside a table. Footnote inside a table. \\ \bottomrule
    \end{tabularx}
  \end{table}
\end{document}
Isopropyl
Posts: 29
Joined: Thu Sep 24, 2009 10:49 pm

Re: How to generate tables like in scientific journals

Post by Isopropyl »

Hi Thorsten,

thank you very much for that idea. That also looks good, but I will first have to have a look at the tabularx package to be able to understand what it does ;-)

In the meantime I also came up with a nasty solution for the space problem, which is adding \vspace*{-2em} before and \vspace*{-1.25em} after the list environment. Does the job, but can't really be the way to do it, can it?
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

How to generate tables like in scientific journals

Post by localghost »

Isopropyl wrote:[...] In the meantime I also came up with a nasty solution for the space problem, which is adding \vspace*{-2em} before and \vspace*{-1.25em} after the list environment. Does the job, but can't really be the way to do it, can it?
It can't do any harm if you provide a minimal working example (MWE) where you show your idea. That would be something to tinker.

In the meantime I modified my example once more and added features of the array package (loaded by tabularx) to get a higher degree of automatism concerning the table notes.

Code: Select all

\documentclass[11pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage[font=small,labelfont={bf,sf},tableposition=top]{caption}
\usepackage{booktabs,tabularx}

\begin{document}
  \begin{table}[!ht]
    \caption{Table caption}\label{tab:notes}
    \centering
    \begin{tabularx}{\linewidth}{Xccccc}\toprule
      Item & n & Mean & Median & Minimum & Maximum \\ \midrule
      An item & 1 & Value\textsuperscript{1} & Value\textsuperscript{2} & Value\textsuperscript{3} & Value\textsuperscript{4} \\
      An item & 2 & Value & Value & Value & Value \\
      An item & 3 & Value & Value & Value & Value \\ \addlinespace
    \end{tabularx}
    \footnoterule
    \footnotesize
    \newcounter{tabnote}
    \begin{tabularx}{\linewidth}{@{}>{\stepcounter{tabnote}\textsuperscript{\thetabnote}}l@{\,}X@{}}
      & Footnote inside a table. Footnote inside a table. Footnote inside a table. Footnote inside a table. \\
      & Footnote inside a table. Footnote inside a table. Footnote inside a table. Footnote inside a table. \\
      & Footnote inside a table. Footnote inside a table. Footnote inside a table. Footnote inside a table. \\
      & Footnote inside a table. Footnote inside a table. Footnote inside a table. Footnote inside a table. \\ \bottomrule
    \end{tabularx}
  \end{table}
\end{document}
Note that you now only have to enter the footnote text in the second column of the nether table.
Post Reply