2

When using David Carlisle's answer (thank you!) to Balancing long table inside multicol in LaTeX, I stumble upon "Overfull \vbox" error when there is some non-multicol text before the table, and the table is long enough to begin wrapping around into the second column.

Here's the code:

\documentclass[11pt, a4paper]{article}
\usepackage[margin=3cm]{geometry}
\usepackage{longtable}
\usepackage{multicol}

\newsavebox\ltmcbox

\def\shortlipsum{\par Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna. Donec vehicula augue eu neque.\par}

\newcounter{entryno}
\setcounter{entryno}{1}
\def\tabline{Test & \the\value{entryno} & Description\addtocounter{entryno}{1}\\}
\def\tablines{\tabline\tabline\tabline\tabline\tabline}

\begin{document}

\shortlipsum
\shortlipsum
\shortlipsum
\shortlipsum

\begin{multicols}{2}
  \medskip
  \setbox\ltmcbox\vbox{
    \makeatletter\col@number\@ne
    \begin{longtable}{|l|l|l|}
      \tablines\tablines\tablines\tablines\tablines\tablines
      \tablines\tablines\tablines\tablines\tablines\tablines
      \tablines\tablines\tablines\tablines\tablines\tablines
      \tablines\tablines\tablines\tablines\tablines\tablines
      \tablines\tablines\tablines\tablines\tablines\tablines
    \end{longtable}
    \unskip
    \unpenalty
    \unpenalty
  }
  \unvbox\ltmcbox
  \medskip
\end{multicols}

\shortlipsum

\end{document}

And here's what I get:

columns not aligning

Ideally, I'd like the first part of the table (on the first page) to properly wrap into the second column, however, I am not savvy enough to figure this one out myself. How can this be done?

1 Answer 1

3

you can try to set the longtable outside the multicol environment:

\documentclass[11pt, a4paper]{article}
\usepackage[margin=3cm]{geometry}
\usepackage{longtable}
\usepackage{multicol}

\newsavebox\ltmcbox

\def\shortlipsum{\par Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna. Donec vehicula augue eu neque.\par}

\newcounter{entryno}
\setcounter{entryno}{1}
\def\tabline{Test & \the\value{entryno} & Description\addtocounter{entryno}{1}\\}
\def\tablines{\tabline\tabline\tabline\tabline\tabline}

\begin{document}

\shortlipsum
\shortlipsum
\shortlipsum
\shortlipsum

\setbox\ltmcbox\vbox{\hsize=\dimexpr 0.5\textwidth-0.5\columnsep\relax%
    \begin{longtable}{|l|l|l|}
      \tablines\tablines\tablines\tablines\tablines\tablines
      \tablines\tablines\tablines\tablines\tablines\tablines
      \tablines\tablines\tablines\tablines\tablines\tablines
      \tablines\tablines\tablines\tablines\tablines\tablines
      \tablines\tablines\tablines\tablines\tablines\tablines
    \end{longtable}
    \unskip
    \unpenalty
    \unpenalty
  }

\begin{multicols}{2}
  \medskip
  \unvbox\ltmcbox
  \medskip
\end{multicols}

\shortlipsum

\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 .