2

I'm having a spacing issue in longtable, where the use of multicolumn elongates the last column. Example posted below.

The solution suggested to this question does not appear to work for me (\fill threw up an error), but I suspect the issue is similar.

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

\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}b{#1}}

\begin{document}
\begin{center}
\begin{longtable}{@{\extracolsep{6pt}}*{5}{L{1.75cm}}}
\toprule\multicolumn{3}{l}{\textbf{Survey Code}} & \multicolumn{2}{r}{\textbf{Month/Year (Sample Size)}} \\ \midrule 
\endfirsthead

\multicolumn{5}{c}%
{{\bfseries \tablename\ \thetable{} -- continued from previous page}} \\
\toprule\multicolumn{1}{l}{\textbf{Survey Code}} & \multicolumn{4}{r}{\textbf{Month/Year (Sample Size)}} \\ \midrule 
\endhead

\midrule\multicolumn{5}{l}{{Continued on next page}} \\\bottomrule
\endfoot

\bottomrule
\endlastfoot

\multicolumn{3}{l}{Polling Organization} & \multicolumn{2}{r}{(Mo./Yr.) ($N=XXXX$)} \\[1em]
\multicolumn{5}{p{\textwidth}}{\footnotesize \emph{Survey question text goes here.}} \\[1em]
\\[.25em]

\multicolumn{1}{L{2cm}}{Response 1} & \multicolumn{1}{L{2cm}}{Response 2} & \multicolumn{1}{L{2cm}}{Response 3} & \multicolumn{1}{L{2cm}}{Response 4} & \multicolumn{1}{L{2cm}}{Response 5}\\\cmidrule{1-1}\cmidrule{2-2}\cmidrule{3-3}\cmidrule{4-4}\cmidrule{5-5}
\nopagebreak
\multicolumn{1}{p{2cm}}{20\%} & \multicolumn{1}{p{2cm}}{56\%} & \multicolumn{1}{p{2cm}}{6\%} & \multicolumn{1}{p{2cm}}{8\%} & \multicolumn{1}{p{2cm}}{10\%} \\[2em]
\end{longtable}
\end{center}
\end{document}

enter image description here

3
  • Are your table is multi page long? If not, than is better to use ordinary tabular environment. Can you add some more rows, that we can see size of numbers in columns. – Zarko Feb 20 '20 at 0:35
  • It's multi-page, but I reduced the example to a single "entry," in order to make it more manageable. – ironchefsakai Feb 20 '20 at 0:49
  • You could use \multicolumn{1}{L{0.2\textwidth-2\tabcolsep}}{Response 1} – leandriis Feb 20 '20 at 6:31
0

If I correctly understood your question, than you like to have the following table (unfortunately it is not clear, what is in the not showing rows, ore there only numbers?):

enter image description here

(red lines indicate text borders)

  • table has equal width of columns determined with p{\dimexpr0.2\textwidth-2\tabcolsep}
  • for \multicolumns are defined shortnes with use of the xparse package
\documentclass{article}
\usepackage{booktabs, longtable, makecell}

\usepackage{xparse}
\NewExpandableDocumentCommand\mcl{O{1}m}
    {\multicolumn{#1}{l}{#2}}
\NewExpandableDocumentCommand\mcr{O{1}m}
    {\multicolumn{#1}{r}{#2}}
\newcommand\mcp[1]{\multicolumn{1}{p{0.16\linewidth}}{#1}}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{lipsum}

\begin{document}
\begingroup
\begin{longtable}{ *{5}{p{\dimexpr0.2\textwidth-2\tabcolsep}} 
                 } 
    \caption{Caption on the first page of the table}
    \label{tab:longtable}                               \\
    \toprule
\mcl[2]{\textbf{Survey Code}}
            & \mcr[3]{\textbf{Month/Year (Sample Size)}} \\
    \midrule
\endfirsthead
    \caption[]{Caption on the first page of the table}  \\
    \toprule
\mcl[2]{\textbf{Survey Code}}
            & \mcr[3]{\textbf{Month/Year (Sample Size)}} \\
    \midrule
\endhead
    \midrule[\heavyrulewidth]
\mcr[5]{r}{\small\textit{Continued on next page}}       \\
\endfoot
    \bottomrule
\endlastfoot
%%%% table body
\mcl[2]{Polling Organization}
            & \mcr[3]{(Mo./Yr.) ($N=XXXX$)}             \\
    \midrule
    \addlinespace
\multicolumn{5}{>{\small}p{\dimexpr\linewidth-2\tabcolsep}}{\emph{Survey question text goes here.}

        \medskip
        \lipsum[11]}                                    \\ % dummy text
    \addlinespace
{Response 1}
        & {Response 2}
                    & {Response 3}
                            & {Response 4}
                                    & {Response 5}      \\
    \cmidrule(r){1-1}\cmidrule(r){2-2}
    \cmidrule(r){3-3}\cmidrule(r){4-4}\cmidrule{5-5}
20\,\%  & 56\,\%    & 6\,\% & 8\,\% & 10\,\%            \\
   \end{longtable}
\endgroup
\end{document}
    \end{longtable}
\endgroup
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.