# multicols breaking in middle causing out of ordered matrix

The following example shows that multicols treats pagebreaks as separate orderings.

\documentclass{article}

\usepackage[margin=0.5in]{geometry}\geometry{a4paper}
\usepackage{multicol,tikz}
\scrollmode

\begin{document}
\newcommand{\drawrect}[1]{\begin{tikzpicture} \draw (-1.5,-1.5) rectangle (1.5,1.5); \node at (0,0) {#1}; \end{tikzpicture}}

\begin{multicols}{3}\raggedright
\drawrect{1}
\drawrect{2}
\drawrect{3}
\drawrect{4}
\drawrect{5}
\drawrect{6}
\drawrect{7}
\drawrect{8}
\drawrect{9}
\drawrect{10}
\drawrect{11}
\drawrect{12}
\end{multicols}

\renewcommand{\drawrect}[1]{\begin{tikzpicture} \draw (-2.5,-3.5) rectangle (2.5,3.5); \node at (0,0) {#1}; \end{tikzpicture}}

\begin{multicols}{3}\raggedright
\drawrect{1}
\drawrect{2}
\drawrect{3}
\drawrect{4}
\drawrect{5}
\drawrect{6}
\drawrect{7}
\drawrect{8}
\drawrect{9}
\drawrect{10}
\drawrect{11}
\drawrect{12}
\end{multicols}

\end{document}


I want the 2nd ordering to be exactly like the first.

Example using parcolumns:

\documentclass{article}

\usepackage[margin=0.5in]{geometry}\geometry{a4paper}
\usepackage{multicol,tikz}
\usepackage{parcolumns}
\scrollmode

\begin{document}
\newcommand{\drawrect}[1]{\begin{tikzpicture} \draw (-1.5,-1.5) rectangle (1.5,1.5); \node at (0,0) {#1}; \end{tikzpicture}}

\begin{parcolumns}[nofirstindent]{3}
\colchunk{
\drawrect{1}
\drawrect{2}
\drawrect{3}
\drawrect{4}}
\colchunk{
\drawrect{5}
\drawrect{6}
\drawrect{7}
\drawrect{8}}
\colchunk{
\drawrect{9}
\drawrect{10}
\drawrect{11}
\drawrect{12}}
\end{parcolumns}

\renewcommand{\drawrect}[1]{\begin{tikzpicture} \draw (-2.5,-3.5) rectangle (2.5,3.5); \node at (0,0) {#1}; \end{tikzpicture}}

\begin{parcolumns}[nofirstindent]{3}
\colchunk{
\drawrect{1}
\drawrect{2}
\drawrect{3}
\drawrect{4}}
\colchunk{
\drawrect{5}
\drawrect{6}
\drawrect{7}
\drawrect{8}}
\colchunk{
\drawrect{9}
\drawrect{10}
\drawrect{11}
\drawrect{12}}
\end{parcolumns}

\end{document}

-
Your MWE generates undefined command errors so it is hard to know if what we are seeing is what you intended. But multicol (as in most TeX) is designed to shipout each page as it comes, it can not wait until the end of the environment and back up after allocating the first n entries to the first column of each page, which is I think what you want. If your real case is distributing fixed large units such as tikz pictures and you know how many fit on a page, you can of course sort them in the source file to the correct order. Or if you want to force all out each picture in a longtable cell. –  David Carlisle May 9 '12 at 20:13
@DavidCarlisle I removed adjustwidth which was causing the problem. Your first solution is useless though as any changes to that may change the multicol could cause the order to change. (e.g., if it was on a page and you added stuff before and pushed it to fall on a break then the order would change... it would be extremely difficult to maintain). Unfortunately in my current case if I force them to all be on the same page I end up with a lot of wasted whitespace that could be utilized. –  Uiy May 9 '12 at 20:21
You should consider using the parcolumns package then, although your code would have to manually distinguish between the columns. That is, the process is not as well-automated as in multicol. –  Werner May 9 '12 at 20:24
@Werner parcolumns does solve the order issue but now has alignment issues. It doesn't seem to properly align things though. I've attached an MWE using parcolumns. In my real case the code looks much better than the MWE though but it seems to center each element instead of left justify. –  Uiy May 9 '12 at 20:47

multicols is an environment to cut textual material into columns "for reading", and reading means restarting the process on the next page. So your example shows exactly what it should show. If that is not what you want then clearly multicols is not the solution for you.
What you seem to desire is to produce a table or a matrix (perhaps of non-textual material?) that should be allowed to break across pages. For this you could try longtable or supertabular they provide the structure over page boundaries, but then the input is horizontal while your ordering is still vertical (or so it seems).