0

I have got a latex related problem:

Consider the following code including the preamble. It should be possible to run it standalone, provided all packages are available.

I'd like to have both longtables have the same spacing between the last \hline and the caption as an ordinary table. Therefore I'm using the caption package and the \captionsetup command (with 10pt). However, the first caption is located not below but on the \hline.

When removing one of the table "rows" (a set of three lines), the caption is displayed correctly. Maybe it has thus to do with the length of the table. However, I am using similarly-styled tables with more than 600 elements in my document as well, where the caption spacing works.

I am not sure whether Problem with caption when using longtable could give an answer to my question, but I would like to keep the caption below the table if possible.

Any ideas on how to resolve this (\\ before the \caption works, but the spacing is a bit too large) and why this problem occurs?

Thank you in advance!

\documentclass{article}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{float}
\usepackage{parskip}
\usepackage{longtable}
\usepackage{upgreek}
\usepackage{rotating}
\usepackage{url}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[left=2.2cm,top=2cm,right=2.2cm,
bottom=2.0cm,bindingoffset=0.5cm,headsep=5pt]{geometry}
\usepackage{caption} 
\usepackage{titlesec}

\captionsetup[table]{skip=10pt}
\titleformat*{\section}{\LARGE\bfseries}
\titleformat*{\subsection}{\Large\bfseries}
\titleformat*{\subsubsection}{\large\bfseries}
\LTcapwidth=\textwidth

\begin{document}

  \tiny
  \begin{longtable}{@{}l@{\hspace{1pt}}l@{\hspace{1pt}}
  l@{\hspace{1pt}}l@{\hspace{1pt}}r@{\hspace{1pt}}r@{\hspace{1pt}}
  r@{\hspace{1pt}}r@{\hspace{1pt}}r@{\hspace{1pt}}r@{\hspace{1pt}}
  r@{\hspace{1pt}}r@{\hspace{1pt}}r@{\hspace{1pt}}r@{\hspace{1pt}}
  r@{}}
    XXX & XXX & XXX & XXX & XXX & XXX & XXX & XXX & XXX & XXX & XXX & XXX & XXX & XXX & XXX \\
\hline
XXX & XXX & XXX & single & 6100 & 1.6 & 0.30 & 4.9 & 0.32 & 0.25 & 0.38 & 0.32 & 0.31 & 0.34 & 0.31 \\
 & & & & & & & & 0.34 & 0.36 & 0.34 & 0.24 & 0.44 & 0.38 & 0.30 \\
 & & & & & & & & 0.33 & 0.30 & 0.36 & 0.28 & 0.38 & 0.36 & 0.31 \\
XXX & XXX & XXX & single & 4750 & 1.1 & 0.10 & 4.8 & 0.10 & 0.03 & 0.20 & 0.10 & 0.11 & 0.13 & 0.08 \\
 & & & & & & & & 0.12 & 0.21 & 0.04 & 0.01 & 0.25 & 0.14 & 0.11 \\
 & & & & & & & & 0.11 & 0.12 & 0.12 & 0.05 & 0.18 & 0.13 & 0.10 \\
XXX & XXX & XXX & single & 5450 & 1.3 & -0.10 & 3.6 & -0.12 & -0.22 & -0.04 & -0.10 & -0.14 & -0.09 & -0.16 \\
 & & & & & & & & 0.14 & -0.12 & -0.15 & -0.25 & -0.01 & -0.01 & -0.21 \\
 & & & & & & & & 0.13 & -0.17 & -0.09 & -0.18 & -0.08 & -0.05 & -0.18 \\
XXX & XXX & XXX & red & 5500 & 1.5 & -0.05 & 4.9 & -0.04 & -0.11 & 0.05 & -0.02 & -0.04 & -0.02 & -0.05 \\
 & & & & & & & & 0.05 & -0.03 & -0.06 & -0.17 & 0.08 & 0.03 & -0.10 \\
 & & & & & & & & 0.04 & -0.07 & -0.01 & -0.09 & 0.02 & 0.01 & -0.08 \\
XXX & XXX & XXX & red & 5850 & 1.2 & 0.10 & 3.1 & 0.15 & 0.07 & 0.21 & 0.16 & 0.13 & 0.20 & 0.13 \\
 & & & & & & & & 0.13 & 0.13 & 0.13 & 0.02 & 0.24 & 0.21 & 0.01 \\
 & & & & & & & & 0.14 & 0.10 & 0.17 & 0.09 & 0.19 & 0.21 & 0.07 \\
XXX & XXX & XXX & red & 5600 & 1.5 & 0.05 & 3.6 & 0.03 & -0.05 & 0.11 & 0.05 & 0.02 & 0.06 & 0.01 \\
 & & & & & & & & 0.05 & 0.09 & 0.02 & -0.06 & 0.16 & 0.13 & -0.04 \\
 & & & & & & & & 0.04 & 0.02 & 0.06 & -0.01 & 0.09 & 0.10 & -0.01 \\
XXX & XXX & XXX & red & 5200 & 1.7 & -0.05 & 4.9 & -0.06 & -0.15 & 0.02 & -0.06 & -0.07 & -0.04 & -0.07 \\
 & & & & & & & & 0.04 & 0.00 & -0.07 & -0.17 & 0.10 & 0.06 & -0.10 \\
 & & & & & & & & 0.05 & -0.07 & -0.03 & -0.11 & 0.02 & 0.01 & -0.08 \\
XXX & XXX & XXX & red & 5100 & 1.0 & 0.10 & 4.9 & 0.12 & 0.03 & 0.20 & 0.14 & 0.11 & 0.14 & 0.11 \\
 & & & & & & & & 0.14 & 0.16 & 0.09 & 0.02 & 0.27 & 0.22 & 0.12 \\
 & & & & & & & & 0.13 & 0.09 & 0.14 & 0.08 & 0.19 & 0.18 & 0.12 \\
XXX & XXX & XXX & red & 5150 & 0.8 & 0.05 & 4.9 & 0.07 & -0.02 & 0.15 & 0.08 & 0.05 & 0.08 & 0.06 \\
 & & & & & & & & 0.08 & 0.14 & 0.04 & -0.03 & 0.20 & 0.10 & 0.06 \\
 & & & & & & & & 0.07 & 0.06 & 0.09 & 0.03 & 0.13 & 0.09 & 0.06 \\
XXX & XXX & XXX & red & 6300 & 2.0 & -0.05 & 3.5 & 0.01 & -0.05 & 0.08 & 0.02 & 0.01 & 0.06 & -0.01 \\
 & & & & & & & & 0.08 & -0.06 & -0.07 & -0.19 & -0.08 & -0.01 & -0.14 \\
 & & & & & & & & 0.03 & -0.05 & 0.00 & -0.08 & -0.03 & 0.02 & -0.08 \\
XXX & XXX & XXX & single & 5600 & 1.5 & -0.15 & 4.9 & -0.17 & -0.24 & -0.09 & -0.15 & -0.18 & -0.16 & -0.18 \\
 & & & & & & & & 0.18 & -0.17 & -0.18 & -0.29 & -0.06 & -0.11 & -0.22 \\
 & & & & & & & & 0.17 & -0.20 & -0.13 & -0.22 & -0.12 & -0.13 & -0.20 \\
XXX & XXX & XXX & single & 5550 & 1.3 & -0.20 & 4.9 & -0.18 & -0.27 & -0.10 & -0.16 & -0.20 & -0.17 & -0.19 \\
 & & & & & & & & 0.20 & -0.19 & -0.21 & -0.31 & -0.09 & -0.12 & -0.27 \\
 & & & & & & & & 0.19 & -0.23 & -0.16 & -0.24 & -0.14 & -0.14 & -0.23 \\
XXX & XXX & XXX & single & 6450 & 1.5 & 0.20 & 2.0 & 0.20 & 0.14 & 0.26 & 0.23 & 0.18 & 0.25 & 0.14 \\
 & & & & & & & & 0.19 & 0.17 & 0.21 & 0.10 & 0.28 & 0.21 & -0.02 \\
 & & & & & & & & 0.19 & 0.15 & 0.23 & 0.16 & 0.23 & 0.23 & 0.06 \\
\hline
\caption[CapXXX1]{Test caption.\label{allsensitivity}}
\end{longtable}
\setlength\LTleft{\fill}
\setlength\LTright{\fill}
\large

\vspace{12cm}

  \normalsize
  \begin{longtable}{llrrrrr}
XXX & XXX & XXX & XXX & XXX & XXX & XXX\\
\hline
XXX & XXX & 1 & - & - & - & 1 \\
XXX & XXX & 3 & - & - & - & 3 \\
XXX & XXX & 1 & - & - & - & 1 \\
XXX & XXX & 3 & - & - & - & 3 \\
XXX & XXX & 4 & - & - & - & 4 \\
XXX & XXX & 2 & 26 & - & 24 & 52 \\
XXX & XXX & 8 & - & 2 & - & 10 \\
XXX & XXX & 2 & - & 2 & - & 4 \\
XXX & XXX & - & - & 3 & - & 3 \\
XXX & XXX & - & - & 8 & - & 8 \\
XXX & XXX & - & - & 3 & - & 3 \\
\hline
\caption[CapXXX2]{Test caption 2.\label{XXX2}}
\end{longtable}
\large

\end{document}
  • 1
    since longtable is not a float, \caption is redefined within it. From documentation: The caption is \multicolumn{\LT@cols}{c}{⟨a parbox with the table’s caption⟩} – Runar Sep 5 '16 at 16:51
  • Is there a reason for using lots of @{\hspace{1pt}} directives? Why not just execute \setlength\tabcolsep{0.5pt and omit all @{\hspace{1pt}} instructions? – Mico Sep 5 '16 at 19:08
1

It's absurd to have a long table caption at the end of the table: you'd have to read a several pages long table before knowing what it's about. The tradition for tables, contrary to figures, is to have captions above tables, precisely for this reason.

The caption for long tables, which are not floats, have to be put in the \endfirsthead/\endhead sections of the table (label only in the first head section). If you insist having caption at the end of the table, put it in the endfoot/\endlastfoot sections.

I also suggest loading siunitx and using the S column type, to have an alignment on the decimal dot. Not seeing why you used such a small font size in the table, and such a small separator between columns, I changed them to values that make the table more readable, but, of course, I don't know the real contents of your table. However, note that tiny font size is almost unreadable. If the real table really require tiny, it might be worth considering a landscape table with a larger font size.

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[hmargin=2.2cm, vmargin=2.0cm,bindingoffset=0.5cm,headsep=5pt, showframe]{geometry}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{array, rotating, graphicx}
\usepackage{float}
\usepackage{parskip}
\usepackage{longtable, booktabs}
\usepackage{upgreek}
\usepackage{url}
\usepackage{caption}
\usepackage{titlesec}
\usepackage{siunitx} %
\captionsetup[table]{skip=10pt}
\titleformat*{\section}{\LARGE\bfseries}
\titleformat*{\subsection}{\Large\bfseries}
\titleformat*{\subsubsection}{\large\bfseries}
\LTcapwidth=\textwidth

\begin{document}

\footnotesize\setlength\tabcolsep{3.5pt}
\sisetup{table-format=-1.2}
\begin{longtable}{@{}*{4}{l}rrSr*{7}{S}@{}}

  \caption[CapXXX1]{Test caption.\label{allsensitivity}}\\
  \toprule%
  XXX & XXX & XXX & XXX & XXX & XXX & {XXX} & XXX & {XXX} & {XXX} & {XXX} & {XXX} & {XXX} & {XXX} & {XXX} \\
  \midrule
  \endfirsthead%
  %
  \caption[CapXXX1]{Test caption (continued).}\\
  \toprule%
  XXX & XXX & XXX & XXX & XXX & XXX & {XXX} & XXX & {XXX} & {XXX} & {XXX} & {XXX} & {XXX} & {XXX} & {XXX} \\
  \midrule
  \endhead%
  %
  \bottomrule
  \endfoot
  XXX & XXX & XXX & single & 6100 & 1.6 & 0.30 & 4.9 & 0.32 & 0.25 & 0.38 & 0.32 & 0.31 & 0.34 & 0.31 \\
      & & & & & & & & 0.34 & 0.36 & 0.34 & 0.24 & 0.44 & 0.38 & 0.30 \\
      & & & & & & & & 0.33 & 0.30 & 0.36 & 0.28 & 0.38 & 0.36 & 0.31 \\
  XXX & XXX & XXX & single & 4750 & 1.1 & 0.10 & 4.8 & 0.10 & 0.03 & 0.20 & 0.10 & 0.11 & 0.13 & 0.08 \\
      & & & & & & & & 0.12 & 0.21 & 0.04 & 0.01 & 0.25 & 0.14 & 0.11 \\
      & & & & & & & & 0.11 & 0.12 & 0.12 & 0.05 & 0.18 & 0.13 & 0.10 \\
  XXX & XXX & XXX & single & 5450 & 1.3 & -0.10 & 3.6 & -0.12 & -0.22 & -0.04 & -0.10 & -0.14 & -0.09 & -0.16 \\
      & & & & & & & & 0.14 & -0.12 & -0.15 & -0.25 & -0.01 & -0.01 & -0.21 \\
      & & & & & & & & 0.13 & -0.17 & -0.09 & -0.18 & -0.08 & -0.05 & -0.18 \\
  XXX & XXX & XXX & red & 5500 & 1.5 & -0.05 & 4.9 & -0.04 & -0.11 & 0.05 & -0.02 & -0.04 & -0.02 & -0.05 \\
      & & & & & & & & 0.05 & -0.03 & -0.06 & -0.17 & 0.08 & 0.03 & -0.10 \\
      & & & & & & & & 0.04 & -0.07 & -0.01 & -0.09 & 0.02 & 0.01 & -0.08 \\
  XXX & XXX & XXX & red & 5850 & 1.2 & 0.10 & 3.1 & 0.15 & 0.07 & 0.21 & 0.16 & 0.13 & 0.20 & 0.13 \\
      & & & & & & & & 0.13 & 0.13 & 0.13 & 0.02 & 0.24 & 0.21 & 0.01 \\
      & & & & & & & & 0.14 & 0.10 & 0.17 & 0.09 & 0.19 & 0.21 & 0.07 \\
  XXX & XXX & XXX & red & 5600 & 1.5 & 0.05 & 3.6 & 0.03 & -0.05 & 0.11 & 0.05 & 0.02 & 0.06 & 0.01 \\
      & & & & & & & & 0.05 & 0.09 & 0.02 & -0.06 & 0.16 & 0.13 & -0.04 \\
      & & & & & & & & 0.04 & 0.02 & 0.06 & -0.01 & 0.09 & 0.10 & -0.01 \\
  XXX & XXX & XXX & red & 5200 & 1.7 & -0.05 & 4.9 & -0.06 & -0.15 & 0.02 & -0.06 & -0.07 & -0.04 & -0.07 \\
      & & & & & & & & 0.04 & 0.00 & -0.07 & -0.17 & 0.10 & 0.06 & -0.10 \\
      & & & & & & & & 0.05 & -0.07 & -0.03 & -0.11 & 0.02 & 0.01 & -0.08 \\
  XXX & XXX & XXX & red & 5100 & 1.0 & 0.10 & 4.9 & 0.12 & 0.03 & 0.20 & 0.14 & 0.11 & 0.14 & 0.11 \\
      & & & & & & & & 0.14 & 0.16 & 0.09 & 0.02 & 0.27 & 0.22 & 0.12 \\
      & & & & & & & & 0.13 & 0.09 & 0.14 & 0.08 & 0.19 & 0.18 & 0.12 \\
  XXX & XXX & XXX & red & 5150 & 0.8 & 0.05 & 4.9 & 0.07 & -0.02 & 0.15 & 0.08 & 0.05 & 0.08 & 0.06 \\
      & & & & & & & & 0.08 & 0.14 & 0.04 & -0.03 & 0.20 & 0.10 & 0.06 \\
      & & & & & & & & 0.07 & 0.06 & 0.09 & 0.03 & 0.13 & 0.09 & 0.06 \\
  XXX & XXX & XXX & red & 6300 & 2.0 & -0.05 & 3.5 & 0.01 & -0.05 & 0.08 & 0.02 & 0.01 & 0.06 & -0.01 \\
      & & & & & & & & 0.08 & -0.06 & -0.07 & -0.19 & -0.08 & -0.01 & -0.14 \\
      & & & & & & & & 0.03 & -0.05 & 0.00 & -0.08 & -0.03 & 0.02 & -0.08 \\
  XXX & XXX & XXX & single & 5600 & 1.5 & -0.15 & 4.9 & -0.17 & -0.24 & -0.09 & -0.15 & -0.18 & -0.16 & -0.18 \\
      & & & & & & & & 0.18 & -0.17 & -0.18 & -0.29 & -0.06 & -0.11 & -0.22 \\
      & & & & & & & & 0.17 & -0.20 & -0.13 & -0.22 & -0.12 & -0.13 & -0.20 \\
  XXX & XXX & XXX & single & 5550 & 1.3 & -0.20 & 4.9 & -0.18 & -0.27 & -0.10 & -0.16 & -0.20 & -0.17 & -0.19 \\
      & & & & & & & & 0.20 & -0.19 & -0.21 & -0.31 & -0.09 & -0.12 & -0.27 \\
      & & & & & & & & 0.19 & -0.23 & -0.16 & -0.24 & -0.14 & -0.14 & -0.23 \\
  XXX & XXX & XXX & single & 6450 & 1.5 & 0.20 & 2.0 & 0.20 & 0.14 & 0.26 & 0.23 & 0.18 & 0.25 & 0.14 \\
      & & & & & & & & 0.19 & 0.17 & 0.21 & 0.10 & 0.28 & 0.21 & -0.02 \\
      & & & & & & & & 0.19 & 0.15 & 0.23 & 0.16 & 0.23 & 0.23 & 0.06
\end{longtable}
%\setlength\LTleft{\fill}
%\setlength\LTright{\fill}
\large

\vspace{3cm}

\normalsize
\begin{longtable}{llrrrrr}
  \caption[CapXXX2]{Test caption 2.\label{XXX2}} \\
  \toprule
  XXX & XXX & XXX & XXX & XXX & XXX & XXX \\
  \midrule
  \endfirsthead
  %
  \caption[CapXXX2]{Test caption 2 (continued).} \\
  \toprule
  XXX & XXX & XXX & XXX & XXX & XXX & XXX \\
  \midrule
  \endhead
  %
  \midrule
  \endfoot
  %
  \bottomrule
  \endlastfoot
  XXX & XXX & 1 & - & - & - & 1 \\
  XXX & XXX & 3 & - & - & - & 3 \\
  XXX & XXX & 1 & - & - & - & 1 \\
  XXX & XXX & 3 & - & - & - & 3 \\
  XXX & XXX & 4 & - & - & - & 4 \\
  XXX & XXX & 2 & 26 & - & 24 & 52 \\
  XXX & XXX & 8 & - & 2 & - & 10 \\
  XXX & XXX & 2 & - & 2 & - & 4 \\
  XXX & XXX & - & - & 3 & - & 3 \\
  XXX & XXX & - & - & 8 & - & 8 \\
  XXX & XXX & - & - & 3 & - & 3 \\
  XXX & XXX & 1 & - & - & - & 1 \\
  XXX & XXX & 3 & - & - & - & 3 \\
  XXX & XXX & 1 & - & - & - & 1 \\
  XXX & XXX & 3 & - & - & - & 3 \\
  XXX & XXX & 4 & - & - & - & 4 \\
  XXX & XXX & 2 & 26 & - & 24 & 52 \\
  XXX & XXX & 8 & - & 2 & - & 10 \\
  XXX & XXX & 2 & - & 2 & - & 4 \\
  XXX & XXX & - & - & 3 & - & 3 \\
  XXX & XXX & - & - & 8 & - & 8 \\
  XXX & XXX & - & - & 3 & - & 3
\end{longtable}

\end{document} 

enter image description here enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.