1

I'm trying to set up a longtable header using multirow elements (all within a landscape environment) in order to place units below the column labels, and despite everything I've tried, I cannot get it to work.

Originally, I had found a question on here that provided me with a template (I cannot find it for the life of me now), but it failed to work properly. I sought the package documentation, thinking the issue was with the * option, and it offered the following insight:

text is the actual text of the construct. If the width was set explicitly, the text will be set in a \parbox of that width; you can use \\ to force linebreaks where you like.

The documentation also seems to suggest that the = option within \multirow also sets a \parbox (and would thus allow for the use of \\ within the text body, but it fails to change the state of the error messages.

Here is the MWE:

\documentclass[10pt,titlepage]{report}
\usepackage[utf8]{inputenc}
\usepackage{geometry}
\usepackage{graphicx}
\usepackage{xstring}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{lscape}
\usepackage{multirow}

\begin{document}
    \begin{landscape}
        \begin{longtable}[c]{lllrrrrrrrrr}
            % Set up caption and label
            \caption{An example of badness}
            \label{tab:table}
            % First page head
            \hline
            \multirow{2}{=}{\textbf{A}}                 & \multirow{2}{=}{\textbf{B}}               & \multirow{2}{=}{\textbf{C}} 
            & \multirow{2}{=}{\textbf{D} \\ [kg]}       & \multirow{2}{=}{\textbf{E} \\ [kg]}       & \multirow{2}{=}{\textbf{F} \\ [kg]} 
            & \multirow{2}{=}{\textbf{G} \\ [kg]}       & \multirow{2}{=}{\textbf{H} \\ [kg]}       & \multirow{2}{=}{$\mathbf{\alpha}$ \\ [\%]} 
            & \multirow{2}{=}{$\mathbf{\beta}$ \\ [\%]} & \multirow{2}{=}{$\mathbf{\gamma}$ \\ [s]} & \multirow{2}{=}{$\mathbf{\Delta}$ \\ [m/s]} \\
            \hline
            \endfirsthead
            \hline
            \multirow{2}{=}{\textbf{A}}                 & \multirow{2}{=}{\textbf{B}}              & \multirow{2}{=}{\textbf{C}} 
            & \multirow{2}{=}{\textbf{D} \\ [kg]}       & \multirow{2}{=}{\textbf{E} \\ [kg]}      & \multirow{2}{=}{\textbf{F} \\ [kg]} 
            & \multirow{2}{=}{\textbf{G} \\ [kg]}       & \multirow{2}{=}{\textbf{H} \\ [kg]}      & \multirow{2}{=}{$\mathbf{\alpha}$ \\ [\%]} 
            & \multirow{2}{=}{$\mathbf{\beta}$ \\ [\%]} & \multirow{2}{=}{$\mathbf{\gamma}$ \\ [s]} & \multirow{2}{=}{$\mathbf{\Delta}$ \\ [m/s]} \\
            \hline
            \endhead
            A & B & C & D & E & F & G & H & I & 1 & 2 & 3 \\
            A & B & C & D & E & F & G & H & I & 1 & 2 & 3 \\
            A & B & C & D & E & F & G & H & I & 1 & 2 & 3 \\
            A & B & C & D & E & F & G & H & I & 1 & 2 & 3 \\
            A & B & C & D & E & F & G & H & I & 1 & 2 & 3 \\
            A & B & C & D & E & F & G & H & I & 1 & 2 & 3 \\
            A & B & C & D & E & F & G & H & I & 1 & 2 & 3 \\
            \hline
        \end{longtable}
    \end{landscape}
\end{document}

It basically causes LaTeX to vomit any number of error messages, as shown below. While I'm mostly clueless to many of the "programmatic" aspects of LaTeX, I can tell that many of these errors seem generic.

Misplaced \noalign. \hline
Misplaced \omit. \multirow
Extra alignment tab has been changed to \cr. \multirow
Missing number, treated as zero. & \multirow{2}{=}{\textbf{D} \\ [kg]}
Illegal unit of measure (pt inserted). & \multirow{2}{=}{\textbf{D} \\ [kg]}
Missing number, treated as zero. ... & \multirow{2}{=}{\textbf{E} \\ [kg]}
Illegal unit of measure (pt inserted). ... & \multirow{2}{=}{\textbf{E} \\ [kg]}
Missing number, treated as zero. ... & \multirow{2}{=}{\textbf{F} \\ [kg]}
Illegal unit of measure (pt inserted). ... & \multirow{2}{=}{\textbf{F} \\ [kg]}
Missing number, treated as zero. & \multirow{2}{=}{\textbf{G} \\ [kg]}
Illegal unit of measure (pt inserted). & \multirow{2}{=}{\textbf{G} \\ [kg]}
Missing number, treated as zero. ... & \multirow{2}{=}{\textbf{H} \\ [kg]}
Illegal unit of measure (pt inserted). ... & \multirow{2}{=}{\textbf{H} \\ [kg]}
Illegal unit of measure (pt inserted). ...\multirow{2}{=}{$\mathbf{\alpha}$ \\ [\%]}
Illegal unit of measure (pt inserted). ... \multirow{2}{=}{$\mathbf{\beta}$ \\ [\%]}
Missing number, treated as zero. ... \multirow{2}{=}{$\mathbf{\gamma}$ \\ [s]}
Illegal unit of measure (pt inserted). ... \multirow{2}{=}{$\mathbf{\gamma}$ \\ [s]}
Missing number, treated as zero. ...multirow{2}{=}{$\mathbf{\Delta}$ \\ [m/s]}
Illegal unit of measure (pt inserted). ...multirow{2}{=}{$\mathbf{\Delta}$ \\ [m/s]}
Missing number, treated as zero. & \multirow{2}{=}{\textbf{D} \\ [kg]}
Illegal unit of measure (pt inserted). & \multirow{2}{=}{\textbf{D} \\ [kg]}
Missing number, treated as zero. ... & \multirow{2}{=}{\textbf{E} \\ [kg]}
Illegal unit of measure (pt inserted). ... & \multirow{2}{=}{\textbf{E} \\ [kg]}
Missing number, treated as zero. ... & \multirow{2}{=}{\textbf{F} \\ [kg]}
Illegal unit of measure (pt inserted). ... & \multirow{2}{=}{\textbf{F} \\ [kg]}
Missing number, treated as zero. & \multirow{2}{=}{\textbf{G} \\ [kg]}
Illegal unit of measure (pt inserted). & \multirow{2}{=}{\textbf{G} \\ [kg]}
Missing number, treated as zero. ... & \multirow{2}{=}{\textbf{H} \\ [kg]}
Illegal unit of measure (pt inserted). ... & \multirow{2}{=}{\textbf{H} \\ [kg]}
Illegal unit of measure (pt inserted). ...\multirow{2}{=}{$\mathbf{\alpha}$ \\ [\%]}
Illegal unit of measure (pt inserted). ... \multirow{2}{=}{$\mathbf{\beta}$ \\ [\%]}
Missing number, treated as zero. ... \multirow{2}{=}{$\mathbf{\gamma}$ \\ [s]}
Illegal unit of measure (pt inserted). ... \multirow{2}{=}{$\mathbf{\gamma}$ \\ [s]}
Missing number, treated as zero. ...multirow{2}{=}{$\mathbf{\Delta}$ \\ [m/s]}
Illegal unit of measure (pt inserted). ...multirow{2}{=}{$\mathbf{\Delta}$ \\ [m/s]}
No file texstudio_tEAINe.aux.
Overfull \vbox (12.0pt too high) detected
Overfull \vbox (12.0pt too high) detected
Overfull \vbox (12.0pt too high) detected
Overfull \vbox (12.0pt too high) detected
Overfull \vbox (12.0pt too high) detected
Overfull \vbox (37.0pt too high) detected
Overfull \vbox (37.0pt too high) detected
Overfull \vbox (12.0pt too high) detected
Overfull \vbox (12.0pt too high) detected
Overfull \hbox (6265.24237pt too wide) in alignment
Overfull \vbox (12.0pt too high) detected
Overfull \vbox (12.0pt too high) detected
Overfull \vbox (12.0pt too high) detected
Overfull \vbox (12.0pt too high) detected
Overfull \vbox (12.0pt too high) detected
Overfull \vbox (37.0pt too high) detected
Overfull \vbox (37.0pt too high) detected
Overfull \vbox (12.0pt too high) detected
Overfull \vbox (12.0pt too high) detected
Overfull \hbox (6265.24237pt too wide) in alignment
Overfull \hbox (6265.24237pt too wide) in alignment
Label(s) may have changed. Rerun to get cross-references right.

I'm amenable to any solution which gets this table properly working (i.e. a longtable with per-page headers in landscape format). During some of my homework for this question, I found some solutions such as this one using \thead with line breaks that would seem to address the issue, but after a night of debugging one approach I'm wary of trying another without some assistance first.

Thanks for any help anyone can provide.

2 Answers 2

3
  • Your use of multirow cells are wrong. Instead them you should use thead macro defined in makecell package
  • code line with \caption had to be terminated by \\

Corrected and completed MWE is:

\documentclass[titlepage]{report}
\usepackage{geometry}
\usepackage{longtable, makecell}
\renewcommand\theadfont{\bfseries}
\usepackage{pdflscape}

\begin{document}
    \begin{landscape}
\begin{longtable}[c]{lllrrrrrrrrr}
    % Set up caption and label
\caption{An example of badness}
\label{tab:table}           \\  % <--- missed
    % First page head
    \hline
\thead{A}   & \thead{B} & \thead{C} & \thead{D \\ {[kg]}}
            & \thead{E \\ {[kg]}}     & \thead{F \\ {[kg]}}
            & \thead{G \\ {[kg]}}     & \thead{H \\ {[kg]}}
                & \thead{$\mathbf{\alpha}$ \\ {[\%]}}
                & \thead{$\mathbf{\beta}$  \\ {[\%]}}
                & \thead{$\mathbf{\gamma}$ \\ {[s]}}
                & \thead{$\mathbf{\Delta}$ \\ {[m/s]}} \\
    \hline
    \endfirsthead
\caption[]{An example of badness (cont.)}\\  % <--- added
    \hline
\thead{A}   & \thead{B} & \thead{C} & \thead{D \\ {[kg]}}
            & \thead{E \\ {[kg]}}     & \thead{F \\ {[kg]}}
            & \thead{G \\ {[kg]}}     & \thead{H \\ {[kg]}}
                & \thead{$\mathbf{\alpha}$ \\ {[\%]}}
                & \thead{$\mathbf{\beta}$  \\ {[\%]}}
                & \thead{$\mathbf{\gamma}$ \\ {[s]}}
                & \thead{$\mathbf{\Delta}$ \\ {[m/s]}} \\
    \hline
\endhead
    \multicolumn{12}{r}{\small\textit{Continued on next page}}   \\
\endfoot        % <--- added
    \hline
\endlastfoot    % <--- added
% table body
    A & B & C & D & E & F & G & H & I & 1 & 2 & 3 \\
    A & B & C & D & E & F & G & H & I & 1 & 2 & 3 \\
    A & B & C & D & E & F & G & H & I & 1 & 2 & 3 \\
    A & B & C & D & E & F & G & H & I & 1 & 2 & 3 \\
    A & B & C & D & E & F & G & H & I & 1 & 2 & 3 \\
    A & B & C & D & E & F & G & H & I & 1 & 2 & 3 \\
    A & B & C & D & E & F & G & H & I & 1 & 2 & 3 \\
    \hline
\end{longtable}
    \end{landscape}
\end{document}

enter image description here

If the table content is very close to the real one, table can be fit in portrait oriented pages.

Addendum: Simpler and much shorter table code with nicer result you can get with use of the tabularray package.

Edit: improved layout of table:

\documentclass[titlepage]{report}
\usepackage{geometry}

\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}
  \ExplSyntaxOn
\NewChildSelector{eachtwo}
  {
    \int_step_inline:nnnn {2}{2}{\l_tblr_childs_total_tl}
      { \clist_put_right:Nn \l_tblr_childs_clist {##1} }
  }
\ExplSyntaxOff

\usepackage{pdflscape}
%---------------- Show page layout. Don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{lipsum}% For dummy text. Don't use in a real document

\begin{document}
\lipsum[1-5]
%    \begin{landscape}
\begin{longtblr}[
caption = {An example of badness},
  label = {tab:table}
                ]{
    rowhead = 1,
     row{1} = {font=\small\bfseries},
   row{2-Z} = {rowsep=-0.5pt},
    row{eachtwo} = {abovesep=1ex},
    colspec = {*{3}{l} *{9}{Q[r,m]} }
                }
    \toprule
A   & B & C & {D \\ {[\si{\kilo\gram}]}}
                & {E \\ {[\si{\kilo\gram}]}}
                    & {F \\ {[\si{\kilo\gram}]}}
                        & {G \\ {[\si{\kilo\gram}]}}
                            & {H \\ {[\si{\kilo\gram}]}}
                                & {$\mathbf{\alpha}$ \\ {[\si{\kilo\gram}]}}
                                    & {$\mathbf{\beta}$ \\ {[\si{\kilo\gram}]}}
                                        & {$\mathbf{\gamma}$ \\ {[\si{\kilo\gram}]}}
                                            & {$\mathbf{\Delta}$ \\ {[\si{\kilo\gram}]}} \\
    \midrule
% table body
A   & B & C & D & E & F & G & H & I & 1 & 2 & 3 \\
A   & B & C & D & E & F & G & H & I & 1 & 2 & 3 \\
A   & B & C & D & E & F & G & H & I & 1 & 2 & 3 \\
A   & B & C & D & E & F & G & H & I & 1 & 2 & 3 \\
A   & B & C & D & E & F & G & H & I & 1 & 2 & 3 \\
A   & B & C & D & E & F & G & H & I & 1 & 2 & 3 \\
A   & B & C & D & E & F & G & H & I & 1 & 2 & 3 \\
A   & B & C & D & E & F & G & H & I & 1 & 2 & 3 \\
    \bottomrule
\end{longtblr}
%    \end{landscape}
\end{document}

enter image description here

(red lines indicate page layout)

1
  • @ecfedele, see edited addendum in answer!
    – Zarko
    Dec 15, 2021 at 7:20
0

Just to understand what is happening: there are three problems in your document.

  1. The {=} in \multirow only works properly with p{} type columns.
  2. There should be a \\ after the \label.
  3. All the constructions of the form \\ [kg] are wrong, because the [kg] is taken as the optional argument of \\. That would be the same outside the \multirow. Either place all these inside braces {[kg]} or use \newline [kg] instead. Of course this also applies to the other units in brackets.

This is my diagnosis. I think the other solutions with makecell or tabularray are the easiest way to solve these problems (they also use the {[...]} construct).

You must log in to answer this question.

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