1

I am having some problems with longtable.

\documentclass{article}
\usepackage[utf8]{inputenc}

\title{Test}


\usepackage{tabu}

\usepackage{longtable}
\usepackage{multirow}
\usepackage{multicol}


\begin{document}

\begin{longtable}{|l|l|l|l|l|}
\hline 
\textbf{Sensor} & \textbf{Erfassung} & \textbf{Typ} & \textbf{Spule} & \textbf{Erfassendes Steuerger\"{a}t} \\ 
\hline
B13.1 & Testwelle & Induktiv & - & ESO9 + CRA \\ 
\hline
B13.2 & Testwelle & Induktiv & - & ESO9 + MSI6 \\ 
\hline
\multirow{2}{}{B1} & \multirow{2}{}{Testwelle} & \multirow{2}{}{Induktiv Doppelspule} & 1 & ESO9 + CRA \\ 
 \cline{4-5}
 &  &  & 2 & MSI6 \\ 
\hline

\end{longtable}\label{tab:table1}

\end{document}

enter image description here

As you can see in the last column the size of the third cell is wrong. The word Doppelspule is overflowing.

Is there a way to fix this without changing the table type or setting the cell size manually?

5
  • Do you get any error messages from the code?
    – leandriis
    Dec 10, 2019 at 16:29
  • Missing number, treated as zero. <to be read again> \let l.24 \multirow{2}{}{B1} & \multirow{2}{}{Testwelle} & \multirow{2}{}{Indukti...
    – Moone
    Dec 10, 2019 at 16:37
  • Ah, OK. In that case, don't even look at the "output" you get, but fix the error first. In your case, the second argument of the multirow command can not be empty (as it is in your example code). Try using either = or * as the second argument.
    – leandriis
    Dec 10, 2019 at 16:38
  • Ah that was the Problem i missed * in \multirow{2}{*}
    – Moone
    Dec 10, 2019 at 16:38
  • if you get any error the pdf output (if any is made) is at best a possible debugging aid. tex makes no attempt to make usable output after an error. It's best to ask about the error message rather than about the output. Dec 10, 2019 at 16:43

2 Answers 2

1

You use wrong syntax for multirow cells. Missed are * or width of cells. For example: correct syntax is \multirow{2}{*}{B1}, not \multirow{2}{}{B1} etc. Complete MWE:

\documentclass{article}
\usepackage{longtable, makecell, multirow}
\renewcommand\theadfont{\small\bfseries}
\renewcommand\theadgape{}

\title{Test}

\begin{document}
    \begin{longtable}{|l|l|l|l|l|}
\hline
\thead{Sensor}  & \thead{Erfassung} & \thead{Typ}   
                        & \thead{Spule}     & \thead{Erfassendes Steuerger\"{a}t}   \\
    \hline
B13.1               & Testwelle         & Induktiv 
                    & --                & ESO9 + CRA        \\
    \hline
B13.2               & Testwelle         & Induktiv 
                    & --                & ESO9 + MSI6       \\
    \hline
\multirow{2}{*}{B1} & \multirow{2}{*}{Testwelle} & \multirow{2}{5em}{Induktiv Doppelspule}
                    & 1                 & ESO9 + CRA        \\
    \cline{4-5}
                    &   &                   & 2 & MSI6      \\
    \hline
\end{longtable}
\label{tab:table1}  % <--- wrong position!
\end{document}

enter image description here

Note: \label for table should be inside or after the caption, and caption has ti be located inside the table or longtable environment. Since you are not providing any information from which will be clear are you really need longtable, maybe you need to add to your table the following preamble:

    \begin{longtable}{|l|l|l|l|l|}
    \caption{My long table}
    \label{tab:table1}                  \\
    \hline
\thead{Sensor}  & \thead{Erfassung} & \thead{Typ}
                & \thead{Spule}     & \thead{Erfassendes Steuerger\"{a}t}   \\
    \hline
\endfirsthead
    \caption[]{My long table (cont.)}   \\
    \hline
\thead{Sensor}  & \thead{Erfassung} & \thead{Typ}
                & \thead{Spule}     & \thead{Erfassendes Steuerger\"{a}t}   \\
    \hline
\thead{Sensor}  & \thead{Erfassung} & \thead{Typ}
                & \thead{Spule}     & \thead{Erfassendes Steuerger\"{a}t}   \\
    \hline
\endhead
    \hline
    \multicolumn{5}{r}{\footnotesize\textit{Continue on the next page}}
\endfoot
    \hline
\endlastfoot
% table body

Using longtable, you need to compile your document at least two times, before the table line up correctly.

2
  • @Sveinung, thank you very much!
    – Zarko
    Dec 10, 2019 at 19:42
  • My pleasure ! :)
    – Sveinung
    Dec 10, 2019 at 19:51
1

I suggest setting the tabular using booktabs rules and nested tabular instead of multirow. Also, I use \parbox inside the cells to break the lines. If you have an updated array package, you can use fixed width columns to easily line up complicated multispanning rows:

enter image description here

\documentclass{article}
\usepackage{longtable, booktabs, array}

\title{Test}

\begin{document}
    \begin{longtable}{@{}*{3}{l}wc{1.25cm}wl{2.2cm}@{}}
\caption{Long table \label{tab:table1}}\\

\toprule
\small\bfseries Sensor   & \small\bfseries Erfassung & \small\bfseries Typ   & 
\small\bfseries Spule     & \parbox{2cm}{\small\bfseries Erfassendes\par Steuergerät}\\
\midrule
\endhead
B13.1   & Testwelle   & Induktiv  & --   & ESO9 + CRA        \\
B13.2   & Testwelle   & Induktiv  & --   & ESO9 + MSI6       \\
\midrule
B1 & Testwelle & \parbox{2cm}{Induktiv \par Doppelspule} &
     \multicolumn{2}{@{}wl{3.45cm}}{%
     \begin{tabular}{@{}wc{1.25cm}l@{}}
     1 & ESO9 + CRA  \\ \midrule
     2 & MSI6\end{tabular}}\\
    \bottomrule
\end{longtable}
\end{document}

You must log in to answer this question.

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