Page break with a longtable in multicolumn

1,002

It seems to work better if one set the longtable outside the multicols environment

\documentclass[10pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{multicol}
   \setlength{\columnseprule}{.4pt}
\usepackage{longtable}
\usepackage{lipsum}
%\usepackage{showframe}

\begin{document}

\lipsum[1-4]

\newsavebox\ltmcbox
\setbox\ltmcbox\vbox{\hsize=\dimexpr0.5\textwidth-0.5\columnsep
\makeatletter\col@number\@ne\makeatother
\begin{longtable}{lll}
col 1 & col 2 & col 3 \\
col 1 & col 2 & col 3 \\
col 1 & col 2 & col 3 \\
col 1 & col 2 & col 3 \\
col 1 & col 2 & col 3 \\
col 1 & col 2 & col 3 \\
col 1 & col 2 & col 3 \\
col 1 & col 2 & col 3 \\
col 1 & col 2 & col 3 \\
col 1 & col 2 & col 3
\end{longtable}
\unskip
\unpenalty
\unpenalty}

\begin{multicols}{2}


\unvbox\ltmcbox

\end{multicols}

\lipsum[1]

\end{document}

enter image description here

(David's answer in Balancing long table inside multicol in LaTeX has the same problem if one add enough text before the multicols.)

Share:
1,002

Related videos on Youtube

gwenj
Author by

gwenj

Updated on August 01, 2022

Comments

  • gwenj
    gwenj over 1 year

    I am trying to reproduce a book which contains many tables printed on two columns to save some vertical space. The text before & after the tables is not concerned by this multi-column style.

    I could typeset the tables in a “two small tables side to side in a bigger one” way, but that would not really separate content and design.

    This answer solves the first part of the problem, displaying the (long) table on two columns.

    The tables are not meant to float like in this case and that seems to bring the same problem of page breaking back: the text after the table does not break, nor the table if it is too long.

    Here is an example:

    \documentclass[10pt]{article}
    \usepackage[T1]{fontenc}
    \usepackage[utf8]{inputenc}
    
    \usepackage{multicol}
       \setlength{\columnseprule}{.4pt}
    \usepackage{longtable}
    \usepackage{lipsum}
    %\usepackage{showframe}
    
    \begin{document}
    
    \lipsum[1-4]
    
    \begin{multicols}{2}
    
    \newsavebox\ltmcbox
    \setbox\ltmcbox\vbox{
    \makeatletter\col@number\@ne\makeatother
    \begin{longtable}{lll}
    col 1 & col 2 & col 3 \\
    col 1 & col 2 & col 3 \\
    col 1 & col 2 & col 3 \\
    col 1 & col 2 & col 3 \\
    col 1 & col 2 & col 3 \\
    col 1 & col 2 & col 3 \\
    col 1 & col 2 & col 3 \\
    col 1 & col 2 & col 3 \\
    col 1 & col 2 & col 3 \\
    col 1 & col 2 & col 3
    \end{longtable}
    \unskip
    \unpenalty
    \unpenalty}
    \unvbox\ltmcbox
    
    \end{multicols}
    
    \lipsum[1]
    
    \end{document}
    

    Thank you for your help.

  • John Kormylo
    John Kormylo over 6 years
    The manual says that longtable will not work in twocolumn or multicolumn mode. No clue as to why that should be.
  • Ulrike Fischer
    Ulrike Fischer over 6 years
    @JohnKormylo: Sure and I would avoid it. But it is David who suggested the code to make it working nevertheless in some cases.
  • gwenj
    gwenj over 6 years
    @Ulrike Fischer: thank you for your answer. Extracting the box from the multicols environment solves the text page breaking. It does not seem to solve the problem if the table needs to break though. I think I’ll consider using the paste program to build my tables before typesetting them, as suggested David Carlisle there: tex.stackexchange.com/questions/193390/…