3

For the document shown below, I get the following error:

! Extra alignment tab has been changed to \cr.

l.103 \end{longtable}

and the output is garbled. However, this only happens if either of the following is true:

  • the table actually breaks over multiple pages
  • the table resides in a \chapter and the chapter style has been re-set to fancy via \assignpagestyle{\chapter}{fancy}

The header also must contain a tabulary as shown; the problem does not occur when there's a tabular(x), \includegraphics, or anything else I could come up with.

I'm stumped, any ideas?

My document:

\documentclass[twoside,a4paper,11pt]{report}    

\usepackage{longtable}
\usepackage{tabulary}

\usepackage[pagestyles]{titlesec}
\usepackage{fancyhdr}
    
% All pages in "main matter" will get this header:
\newcommand\mainmatter{
    \fancyhead[CE,CO]{
        \begin{tabulary}{6cm}{C}
            \huge\fontencoding{T1}\fontfamily{phv}\selectfont PROJECT \\ \hline
            \large Title\\
        \end{tabulary}
    }
}

% A titlesec command I use in the "real" document overwrites the 
% chapter style, removing headers and footers. But I want those 
% also on the chapter page, so: 
\assignpagestyle{\chapter}{fancy}


\begin{document}

    % Start "main matter" part
    \mainmatter
    \chapter{Some Chapter}

    % Multi-page table
    \begin{longtable}{llll}

        \caption{Example of a problematic long table} \\

        % Header on first page
        \hline
        \textbf{Head 1}&\multicolumn{3}{l}{\textbf{Head 2}} \\ \hline
        \endfirsthead

        % Header on subsequent pages
        \multicolumn{4}{c}%
        {{\textbf { \tablename\ \thetable{} } \tiny(continued from previous page)}} \\
        \hline
        \textbf{Head 1} & \multicolumn{3}{l}{\textbf{Head 2}} \\ \hline
        \endhead

        % Footer on all ut last page
        \multicolumn{4}{r}{{\tiny{Continued on next page}}} \\ \hline
        \endfoot

        % Footer on last page
        \hline\hline
        \endlastfoot

        % Table content
        \textbf{data\_230}  & \multicolumn{3}{l}{content\_1\_60}                     \\ \hline
        \textbf{data\_240}  & \multicolumn{3}{l}{content\_1\_60}                     \\ \hline
        \textbf{data\_250}  & \multicolumn{3}{l}{content\_1\_590}                    \\ \hline
        \textbf{data\_260}  & content\_1\_80   & content\_1\_240  & content\_1\_500  \\
                            & content\_1\_110  & content\_1\_440  & content\_1\_580  \\
                            & content\_1\_160  & content\_1\_500  &                  \\ \hline
        \textbf{data\_270}  & \multicolumn{3}{l}{content\_1\_650}                    \\ \hline
        \textbf{data\_280}  & content\_1\_90   & content\_1\_180  & content\_1\_450  \\
                            & content\_1\_120  & content\_1\_250  & content\_1\_510  \\
                            & content\_1\_170  & content\_1\_260  & content\_1\_600  \\ \hline
        \textbf{data\_290}  & content\_1\_740  & content\_1\_750  &                  \\ \hline
        \textbf{data\_300}  & content\_1\_20   & content\_1\_30   & content\_1\_430  \\ \hline
        \textbf{data\_310}  & \multicolumn{3}{l}{content\_1\_730}                    \\ \hline
        \textbf{data\_530}  & content\_2\_20   & content\_2\_100  & content\_2\_130  \\
                            & content\_2\_90   & content\_2\_110  & content\_2\_260  \\ \hline
        \textbf{data\_550}  & content\_1\_550  & content\_2\_150  & content\_2\_200  \\
                            & content\_2\_80   & content\_2\_160  & content\_2\_210  \\
                            & content\_2\_120  & content\_2\_170  & content\_2\_220  \\
                            & content\_2\_130  & content\_2\_180  & content\_2\_230  \\
                            & content\_2\_140  & content\_2\_190  & content\_2\_240  \\ \hline
        \textbf{data\_560}  & content\_1\_560  & content\_2\_260  &                  \\ \hline
        \textbf{data\_580}  & content\_1\_10   & content\_2\_60   & content\_2\_320  \\
                            & content\_1\_520  & content\_2\_300  & content\_2\_330  \\
                            & content\_1\_680  & content\_2\_310  &                  \\ \hline
        \textbf{data\_600}  & content\_2\_280  & content\_2\_290  &                  \\ \hline
        \textbf{data\_610}  & \multicolumn{3}{l}{content\_2\_270}                    \\ \hline
        \textbf{data\_670}  & \multicolumn{3}{l}{content\_1\_860}                    \\ \hline
        \textbf{data\_780}  & \multicolumn{3}{l}{content\_1\_850}                    \\ \hline
        \textbf{data\_800}  & content\_1\_520  & content\_1\_700  & content\_2\_300  \\
                            & content\_1\_680  & content\_2\_60   & content\_2\_320  \\
                            & content\_1\_690  & content\_2\_300  &                  \\ \hline
        \textbf{data\_810}  & content\_1\_870  & content\_1\_890  & content\_1\_910  \\
                            & content\_1\_880  & content\_1\_900  &                  \\ \hline
        \textbf{data\_820}  & content\_1\_870  & content\_1\_890  & content\_1\_910  \\
                            & content\_1\_880  & content\_1\_900  &                  \\ \hline
        \textbf{data\_830}  & content\_1\_710  & content\_1\_840  &                  \\ \hline
        \textbf{data\_840}  & content\_2\_380  & content\_2\_520  &                  \\ \hline
        \textbf{data\_850}  & content\_2\_380  & content\_2\_390  &                  \\ \hline
        \textbf{data\_860}  & \multicolumn{3}{l}{content\_1\_760}                    \\ \hline
        \textbf{data\_860}  & \multicolumn{3}{l}{content\_1\_770}                    \\ \hline
        \textbf{data\_930}  & \multicolumn{3}{l}{content\_2\_340}                    \\ \hline
        \textbf{data\_950}  & \multicolumn{3}{l}{content\_1\_660}                    \\ \hline
        \textbf{data\_980}  & \multicolumn{3}{l}{content\_1\_670}                    \\ \hline
        \textbf{data\_990}  & \multicolumn{3}{l}{content\_1\_720}                    \\ \hline
        \textbf{data\_1000} & \multicolumn{3}{l}{content\_1\_720}                    \\ \hline

    \end{longtable}


\end{document}
11
  • Do you really need tabulary for your header? And, since you load titlesec with pagestyles option, did you try with titleps, instead of fancyhdr?
    – Bernard
    Commented Feb 14, 2017 at 18:20
  • preferably yes, that's the output of a generator I'm using to generate the document with... Commented Feb 14, 2017 at 18:22
  • I've updated my comment with a second question.
    – Bernard
    Commented Feb 14, 2017 at 18:23
  • @Bernard: no, I'll definitely give that a try. But what could be causing this? Commented Feb 14, 2017 at 18:26
  • 1
    @Bernard: sounds a bit like: "doctor, it hurts when I do this!". Doctor: "Then don't do that". :p Commented Feb 14, 2017 at 18:30

2 Answers 2

1

You can make the error go by doing the ty in a box where it is safe, although it only appears on page 1 here for some reason. Note there really is not point in a one-column tabulary it makes Tex go to a lot of work to find the columns widths so they total to 6cm but with only one column you could just have used a 6cm wide parbox.

\newsavebox\headerbox
\newcommand\mainmatter{%
    \fancyhead[CE,CO]{\usebox\headerbox}%
    }


% A titlesec command I use in the "real" document overwrites the 
% chapter style, removing headers and footers. But I want those 
% also on the chapter page, so: 
\assignpagestyle{\chapter}{fancy}


\begin{document}
\sbox\headerbox{%
\begin{tabulary}{6cm}{C}
            \huge\fontencoding{T1}\fontfamily{phv}\selectfont PROJECT \\ \hline
            \large Title\\
        \end{tabulary}}

    % Start "main matter" part
    \mainmatter
1
  • I know it's not ideal, but like I said, it's what's generated by default and not under my control. I think I'd better write some python script to correct the tool's output, because (1) of this problem, and (2) it's inefficient. Many thanks though Commented Feb 14, 2017 at 20:25
1

I propose this solution, not using tabulary, but a simple tabular and the eqparbox package, to emulate the max width of 6cm. I use titlepsto define a main page style. You can use this style on the chapter page adding \thispagestyle{main} (which can be incorporated to \titleformat). In the long table, I also replaced the \hlines with the rules from booktabs to add some padding to these lines:

\documentclass[twoside,a4paper,11pt]{report}
\usepackage[verbose, headheight = 22pt]{geometry} %
\usepackage{longtable}
\usepackage{,eqparbox, booktabs}

\usepackage[pagestyles]{titlesec}

% All pages in "main matter" will get this header:
\newcommand\mainmatter{\pagestyle{main}}%
\newpagestyle{main}{%
\headrule\eqsetmaxwidth{HDR}{6cm}
\sethead{}{\fontencoding{T1}\fontfamily{phv}\selectfont%
\begin{tabular}[b]{@{\,}c@{\,}}
\eqmakebox[HDR]{\huge PROJECT} \\ \midrule %
\eqmakebox[HDR]{\large Title\medskip}%
\end{tabular}
}{}
\setfoot{}{\thepage}{}
}%

\begin{document}

% Start "main matter" part
\mainmatter
\chapter{Some Chapter}
\thispagestyle{main}
% Multi-page table
\begin{longtable}{llll}
  \caption{Example of a problematic long table} \\
  % Header on first page
  \toprule
  \textbf{Head 1}&\multicolumn{3}{l}{\textbf{Head 2}} \\ \midrule
  \endfirsthead
  % Header on subsequent pages
  \multicolumn{4}{c}%
  {{\textbf { \tablename\ \thetable{} } \tiny(continued from previous page)}} \\
  \addlinespace[0.6ex]
  \toprule
  \textbf{Head 1} & \multicolumn{3}{l}{\textbf{Head 2}} \\ \midrule
  \endhead
  % Footer on all ut last page
  \multicolumn{4}{r}{{\tiny{Continued on next page}}} \\\midrule
  \endfoot
  % Footer on last page
  \addlinespace[-1.8\aboverulesep]
  \bottomrule
  \endlastfoot
  % Table content
  \textbf{data\_230} & \multicolumn{3}{l}{content\_1\_60} \\ \midrule
  \textbf{data\_240} & \multicolumn{3}{l}{content\_1\_60} \\ \midrule
  \textbf{data\_250} & \multicolumn{3}{l}{content\_1\_590} \\ \midrule
  \textbf{data\_260} & content\_1\_80 & content\_1\_240 & content\_1\_500 \\
                     & content\_1\_110 & content\_1\_440 & content\_1\_580 \\
                     & content\_1\_160 & content\_1\_500 & \\ \midrule
  \textbf{data\_270} & \multicolumn{3}{l}{content\_1\_650} \\ \midrule
  \textbf{data\_280} & content\_1\_90 & content\_1\_180 & content\_1\_450 \\
                     & content\_1\_120 & content\_1\_250 & content\_1\_510 \\
                     & content\_1\_170 & content\_1\_260 & content\_1\_600 \\ \midrule
  \textbf{data\_290} & content\_1\_740 & content\_1\_750 & \\ \midrule
  \textbf{data\_300} & content\_1\_20 & content\_1\_30 & content\_1\_430 \\ \midrule
  \textbf{data\_310} & \multicolumn{3}{l}{content\_1\_730} \\ \midrule
  \textbf{data\_530} & content\_2\_20 & content\_2\_100 & content\_2\_130 \\
                     & content\_2\_90 & content\_2\_110 & content\_2\_260 \\ \midrule
  \textbf{data\_550} & content\_1\_550 & content\_2\_150 & content\_2\_200 \\
                     & content\_2\_80 & content\_2\_160 & content\_2\_210 \\
                     & content\_2\_120 & content\_2\_170 & content\_2\_220 \\
                     & content\_2\_130 & content\_2\_180 & content\_2\_230 \\
                     & content\_2\_140 & content\_2\_190 & content\_2\_240 \\ \midrule
  \textbf{data\_560} & content\_1\_560 & content\_2\_260 & \\ \midrule
  \textbf{data\_580} & content\_1\_10 & content\_2\_60 & content\_2\_320 \\
                     & content\_1\_520 & content\_2\_300 & content\_2\_330 \\
                     & content\_1\_680 & content\_2\_310 & \\ \midrule
  \textbf{data\_600} & content\_2\_280 & content\_2\_290 & \\ \midrule
  \textbf{data\_610} & \multicolumn{3}{l}{content\_2\_270} \\ \midrule
  \textbf{data\_670} & \multicolumn{3}{l}{content\_1\_860} \\ \midrule
  \textbf{data\_780} & \multicolumn{3}{l}{content\_1\_850} \\ \midrule
  \textbf{data\_800} & content\_1\_520 & content\_1\_700 & content\_2\_300 \\
                     & content\_1\_680 & content\_2\_60 & content\_2\_320 \\
                     & content\_1\_690 & content\_2\_300 & \\ \midrule
  \textbf{data\_810} & content\_1\_870 & content\_1\_890 & content\_1\_910 \\
                     & content\_1\_880 & content\_1\_900 & \\ \midrule
  \textbf{data\_820} & content\_1\_870 & content\_1\_890 & content\_1\_910 \\
                     & content\_1\_880 & content\_1\_900 & \\ \midrule
  \textbf{data\_830} & content\_1\_710 & content\_1\_840 & \\ \midrule
  \textbf{data\_840} & content\_2\_380 & content\_2\_520 & \\ \midrule
  \textbf{data\_850} & content\_2\_380 & content\_2\_390 & \\ \midrule
  \textbf{data\_860} & \multicolumn{3}{l}{content\_1\_760} \\ \midrule
  \textbf{data\_860} & \multicolumn{3}{l}{content\_1\_770} \\ \midrule
  \textbf{data\_930} & \multicolumn{3}{l}{content\_2\_340} \\ \midrule
  \textbf{data\_950} & \multicolumn{3}{l}{content\_1\_660} \\ \midrule
  \textbf{data\_980} & \multicolumn{3}{l}{content\_1\_670} \\ \midrule
  \textbf{data\_990} & \multicolumn{3}{l}{content\_1\_720} \\ \midrule
  \textbf{data\_1000} & \multicolumn{3}{l}{content\_1\_720} \\ \midrule
\end{longtable}

\end{document} 

enter image description here

You must log in to answer this question.

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