[Tex/LaTex] Caption spacing – table vs longtable

captionslongtabletables

if I use both table and longtable in one document, the spacing between the caption and the table (the empty space after the caption) is different for table and longtable.

I would prefer minimal (and indeed identical) spacing after the caption in both cases.
Thank you.

Example:

\documentclass[12pt]{article}
\usepackage{longtable, booktabs, graphicx}
\begin{document}

\begin{table}
\caption{This is the first caption}
\begin{center}
\resizebox{1\textwidth}{!}{
\begin{tabular}{@{}llllll@{}}
\toprule
\textbf{Name} & \textbf{Description} & \textbf{Unit} & \textbf{Data source} & \textbf{Time frame} & \textbf{Frequency} \\
\midrule  
Name & Description & Unit & Data source & Time frame & Frequency \\
\bottomrule  
\end{tabular}}
\end{center}
\end{table}

\begin{center} 
\begin{longtable}{@{}p{2cm}p{1.5cm}p{3.6cm}p{1.2cm}p{1.5cm}p{1.5cm}@{}}
\caption{This is the second caption} \\
\toprule 
\textbf{Author(s)} & \textbf{Area} & \textbf{Estimated relationship} & \textbf{Time frame}  & \textbf{Scope}  & \textbf{type} \\
\midrule 
\endfirsthead
\multicolumn{6}{c}{\tablename\ \thetable\ -- \textit{Continued from previous page}} \\
\toprule 
\textbf{Author(s)} & \textbf{Area} & \textbf{Estimated relationship} & \textbf{Time frame}  & \textbf{Scope}  & \textbf{ type} \\ 
\midrule 
\endhead
\midrule 
\multicolumn{6}{r}{\textit{Continued on next page}} \\ 
\endfoot 
\bottomrule 
\endlastfoot
name & area & relationship & time & scope &  type \\
\end{longtable} 
\end{center}
\end{document}

Best Answer

Load the caption package:

\documentclass[12pt]{article}
\usepackage{longtable, booktabs, graphicx, caption}
\captionsetup[table]{position=above}
\begin{document}

\begin{table}
\caption{This is the first caption}
\centering
\begin{tabular}{@{}llllll@{}}
\toprule
\textbf{Name} & \textbf{Description} & \textbf{Unit} & \textbf{Data source} & \textbf{Time frame} & \textbf{Frequency} \\
\midrule  
Name & Description & Unit & Data source & Time frame & Frequency \\
\bottomrule  
\end{tabular}
\end{table}

\begin{longtable}{@{}p{2cm}p{1.5cm}p{3.6cm}p{1.2cm}p{1.5cm}p{1.5cm}@{}}
\caption{This is the second caption} \\
\toprule 
\textbf{Author(s)} & \textbf{Area} & \textbf{Estimated relationship} & \textbf{Time frame}  & \textbf{Scope}  & \textbf{type} \\
\midrule 
\endfirsthead
\multicolumn{6}{c}{\tablename\ \thetable\ -- \textit{Continued from previous page}} \\
\toprule 
\textbf{Author(s)} & \textbf{Area} & \textbf{Estimated relationship} & \textbf{Time frame}  & \textbf{Scope}  & \textbf{ type} \\ 
\midrule 
\endhead
\midrule 
\multicolumn{6}{r}{\textit{Continued on next page}} \\ 
\endfoot 
\bottomrule 
\endlastfoot
name & area & relationship & time & scope &  type \\
\end{longtable} 
\end{document}
  1. Don't use the center environment inside table, but \centering
  2. Don't use the center environment around longtable: the table will appear centered by default
  3. Use \resizebox only as a last resort
  4. Narrow p columns may be better handled if you add \raggedright, which you can do with the array package:

    >{\raggedright\arraybackslash}p{3.6cm}
    

    would be a good declaration for your third longtable column (add \usepackage{array} to your preamble.

enter image description here

Related Question