3

can someone explain me, why the gap between the caption and the table is so huge?

\documentclass[a4paper,12pt]{scrartcl} 
\usepackage[ngerman]{babel} 
\usepackage[utf8]{inputenc} 
\usepackage[T1]{fontenc} 
\usepackage{ltablex}
\usepackage{siunitx}
\usepackage{booktabs}
\keepXColumns% Bitte in der Anleitung nachlesen!
\usepackage{caption}
\usepackage{mwe}

\begin{document}

\section{Symbolverzeichnis}
\blindtext[2]

% Manuell zentrierte Überschrift
\begin{center}
    \captionof{table}{Symbolverzeichnis}
\end{center}
\begin{tabularx}{\textwidth}{ll>{\raggedright\arraybackslash}X} 
    \toprule
    \textbf{Symbol} & \textbf{Einheit} & \textbf{Bedeutung} \\
    \midrule
    $A$ & \si{\mm\squared} & Fläche \\
    $\Delta p$ & \si{\kg\meter\per\second} & Impulsunschärfe eines Elektrons \\
    $l$ & lal & Gelaber \blindtext \\
    $L$ & klal & großer Gelaber \blindtext \\
    \bottomrule
\end{tabularx}

\end{document}

enter image description here

7
  • tabularx with package ltablex are long tables. Therefore the \caption{…} should be inside the environment. See at least the example in the user manual of ltablex. But I would also recommend to read the longtable user manual and the tabularx user manual as well.
    – cabohah
    Commented Jun 17 at 9:34
  • 5
    do not put a center enviroment around it. Commented Jun 17 at 9:34
  • BTW: ltablex has not been updated since 1995. I'm not sure if it is really compatible with up-to-date versions of longtable, tabularx and array. And to avoid confusion because of changing tabularx into a long table, I meanwhile prefer either xltabular or tabularray. Both define their own environments for long tables, so tabularx is still untouched and a tabular environment similar to tabular and tabular*. But this is more an opinion than a real reason not to use ltablex.
    – cabohah
    Commented Jun 17 at 9:39
  • 1
    @cabohah ltablex is loaded by xltabular. Commented Jun 17 at 9:46
  • 2
    @cabohah yes, but if ltablex breaks something in a current LaTeX, it will also break xltabular (unless they overwrite that again ...) (imho it will at least break the tagging support we added for longtable, but I didn't test). Commented Jun 17 at 10:20

2 Answers 2

3

I would use longtblr of tabularray package. Using it the code for table is simpler and shorter:

\documentclass[a4paper,12pt]{scrartcl} 
\usepackage[ngerman]{babel} 
\usepackage[T1]{fontenc} 
\usepackage[skip=1ex,
            font=small,
            labelfont = bf]{caption}
\usepackage{tabularray}
\usepackage{tblr-extras}       
\UseTblrLibrary{booktabs,
                caption, 
                siunitx}

\usepackage{mwe}

\begin{document}

\section{Symbolverzeichnis}
\blindtext[2]

% Manuell zentrierte Überschrift
\begin{longtblr}[
caption = {Symbolverzeichnis},
  label = {tab:symbols}
                ]{colspec = {@{} Q[l, mode=math] l X[j] @{}},
                  row{1}  = {mode=text, font=\bfseries},
                  rowhead = 1
                  } 

    \toprule
Symbol  &   Einheit &   Bedeutung                   \\
    \midrule
A           & \unit{\mm\squared} 
                    &   Fläche                      \\
\Delta p    & \unit{\kg\meter\per\second} 
                    &   Impulsunschärfe eines Elektrons \\
l           & lal   &   Gelaber \blindtext \\
L           & klal  &   großer Gelaber \blindtext \\
    \bottomrule
\end{longtblr}
\end{document}

enter image description here

2

I recommend you employ an xltabular environment, which combines the capabilities of the tabularx and longtable environments.

enter image description here

\documentclass[a4paper,12pt]{scrartcl} 
\usepackage[ngerman]{babel} 
%\usepackage[utf8]{inputenc} % that's the default nowadays
\usepackage[T1]{fontenc} 

\usepackage{siunitx}
\usepackage{booktabs}
\usepackage{xltabular}
\usepacakge{ragged2e}  % for '\RaggedRight' macro
\keepXColumns
\usepackage[skip=0.5\baselineskip]{caption}
\usepackage{mwe}

\begin{document}

\section{Symbolverzeichnis}

\blindtext[2]

\begin{xltabular}{\textwidth}{@{} l l >{\RaggedRight}X @{}}

    %% headers and footers
    
    \caption{Symbolverzeichnis}\\
    \toprule
    \textbf{Symbol}  & 
    \textbf{Einheit} & 
    \textbf{Bedeutung} \\
    \midrule
    \endfirsthead
    
    \multicolumn{3}{@{}l}{Table \thetable, continued}\\[1ex]
    \toprule
    \textbf{Symbol} & \textbf{Einheit} & \textbf{Bedeutung} \\
    \midrule
    \endhead  
    
    \midrule
    \multicolumn{3}{r@{}}{\footnotesize (continued on next page)}\\
    \endfoot
    
    \bottomrule
    \endlastfoot
    
    
    %% body of table
    
    $A$ & \unit{\mm\squared} & Fläche \\
    $\Delta p$ & \unit{\kg\meter\per\second} & Impulsunschärfe eines Elektrons \\
    $l$ & lal & Gelaber \blindtext \\
    $L$ & klal & großer Gelaber \blindtext \\

\end{xltabular}

\end{document}

You must log in to answer this question.

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