1

I'm using both "normal" tables and longtables in my document. I only want to use longtables for longer tables that need a pagebreak, smaller tables I want to have floating to fit into the best position. I don't want all my tables breaking over pages. So far so good.

My only problem is that the caption works differently for the two types of tables. While for the longtable it basically is just another line on top of the table with the same margin as all the other lines of the table. With the "normal" tables, the caption margin is much bigger. In the picture, the first table is a "normal" table, the second one is a longtable Different caption margins Is there any good way to fix this? Thank you in advance!

EDIT Here is a minimum working example. In this case it's the other way around, but the margins are still different from each other.

\documentclass{article}
\usepackage{longtable}
\begin{document}

\begin{longtable}[c]{| c | c |}
\caption{This is a longtable}\\
\hline
Something & something else\\
\hline
\endfirsthead
\hline
Something & something else\\
\hline
\endhead
\endfoot
\hline
\endlastfoot
Lots of lines & like this\\
Lots of lines & like this\\
Lots of lines & like this\\
end{longtable}

\begin{table}[ht!]
\centering
\caption{This is a normal table}
\begin{tabular}{|c|c|}
\hline
Lots of lines & like this\\
\hline
Lots of lines & like this\\
\hline
Lots of lines & like this\\
\hline
\end{tabular}
\end{table}
 
\end{document}

2
  • Could you please provide a MWE?
    – Arne
    Dec 21, 2022 at 21:10
  • @Arne Of course. I edited the post. Dec 21, 2022 at 21:24

1 Answer 1

2

Just adding the package caption will fix the issue. Then you might setup the caption using \captionsetup[<float type>]{<options>}.

a

\documentclass{article}
\usepackage{longtable}

\usepackage{caption} % needed  <<<<<<<<<<<<<
\captionsetup[table]{labelfont=bf,textfont=it, skip= 5pt} % setup the table caption

\begin{document}
    
    \begin{longtable}[c]{| c | c |}
        \caption{This is a longtable}\\
        \hline
        Something & something else\\
        \hline
        \endfirsthead
        \hline
        Something & something else\\
        \hline
        \endhead
        \endfoot
        \hline
        \endlastfoot
        Lots of lines & like this\\
        Lots of lines & like this\\
        Lots of lines & like this\\
    \end{longtable}
        
        \begin{table}[ht!]
            \centering
            \caption{This is a normal table}
            \begin{tabular}{|c|c|}
                \hline
                Lots of lines & like this\\
                \hline
                Lots of lines & like this\\
                \hline
                Lots of lines & like this\\
                \hline
            \end{tabular}
        \end{table}
        
    \end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .