3

When using multicols from the multicol package, is is possible to do something like this:

\begin{multicols}{2}

Some text
\begin{escapemulticol}
Some large image or formula spanning the whole page width but stay in place (horizontally). 
\end{escapemulticol}

Some other text

\end{multicols}

I need this in a more complicated setting so it is not enough simply to use two multicol environments.

Edit: The more "complicated" setting seems to be more relevant here, so I try to give a minimal example for my actual use case:

\documentclass{article}

\usepackage{etoolbox}
\usepackage{environ}


\newtheorem{pr}{Problem}
\newtheorem{solinn}{ad Problem}

\newtoks\prsoltoks

\NewEnviron{Solution}{%
  \global\prsoltoks=\expandafter{\the\prsoltoks\begin{solinn}}%
    \global\prsoltoks=\expandafter{\the\expandafter\prsoltoks\BODY\end{solinn}}%
}


\usepackage{multicol}
\AtEndDocument{\clearpage\begin{center}\Large Solutions \end{center}
  \setcounter{pr}{0}
  \begin{multicols}{2}
    \the\prsoltoks
  \end{multicols}
}

\begin{document}

\begin{pr}
A Problem. 
\end{pr}
\begin{Solution}~

\def\x{Some text }
\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x

% \end{multicols}
% \fbox{Some large image or formula spanning the whole page width. }
% \begin{multicols}{2}
% \begin{escapemulticol}
% Some large image or formula spanning the whole page width. 
% \end{escapemulticol}


\def\y{Some other text Some other text Some other text Some other text }
\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y

More: \y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y

and more still \y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y

\end{Solution}

\end{document}

David Carlisle's solution doesn't compile in this setting.

student
  • 29,003

2 Answers2

5

New answer based on extended MWE

enter image description here

\documentclass{article}

\usepackage{etoolbox}
\usepackage{environ}


\newtheorem{pr}{Problem}
\newtheorem{solinn}{ad Problem}

\newtoks\prsoltoks

\NewEnviron{Solution}{%
  \global\prsoltoks=\expandafter{\the\prsoltoks\begin{solinn}}%
    \global\prsoltoks=\expandafter{\the\expandafter\prsoltoks\BODY\end{solinn}}%
}


\usepackage{multicol}
\AtEndDocument{\clearpage\begin{center}\Large Solutions \end{center}
  \setcounter{pr}{0}
  \begin{multicols}{2}
    \the\prsoltoks
  \end{multicols}
}

\begin{document}
\makeatletter
\begin{pr}
A Problem. 
\end{pr}
\begin{Solution}~

\def\x{Some text }
\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x

\endsolinn\endgroup
\endmulticols\endgroup

 \fbox{Some large image or formula spanning the whole page width. }

\begingroup\def\@currenvir{multicols}\multicols{2}
\begingroup\def\@currenvir{solinn}%
\def\y{Some other text Some other text Some other text Some other text }
\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y

More: \y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y

and more still \y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y

\end{Solution}


\end{document}

Original answer

enter image description here

\documentclass{article}

\usepackage{multicol}
\begin{document}
\begin{multicols}{2}

\def\x{Some text }
\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x
\begin{figure*}
\fbox{Some large image or formula spanning the whole page width. }
\end{figure*}

\def\y{Some other text Some other text Some other text Some other text }
\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y

More: \y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y

and more still \y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y

\end{multicols}

\end{document}

Alternatively:

enter image description here

\documentclass{article}

\usepackage{multicol}
\begin{document}
\begin{multicols}{2}

\def\x{Some text }
\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x

\end{multicols}
\fbox{Some large image or formula spanning the whole page width. }
\begin{multicols}{2}

\def\y{Some other text Some other text Some other text Some other text }
\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y

More: \y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y

and more still \y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y

\end{multicols}

\end{document}
David Carlisle
  • 757,742
5

Close the multicols environment and reopen it after the environment.

I use the etoolbox command \BeforeBeginEnvironment for doing something before the group opened by \begin{escapemulticol} is started and \aftergroup for delaying something after \end{escapemulticol} is finished.

\documentclass{article}
\usepackage{multicol,lipsum,etoolbox}

\makeatletter
\newcount\saved@colnumber
\newenvironment{escapemulticol}
 {}
 {\aftergroup\restore@multicols}
\BeforeBeginEnvironment{escapemulticol}{%
  \global\saved@colnumber=\col@number
  \end{multicols}%
}
\def\restore@multicols{\begin{multicols}{\saved@colnumber}}
\makeatother

\begin{document}

\begin{multicols}{2}

\lipsum[1]

\begin{escapemulticol}
\lipsum[2]
\end{escapemulticol}

\lipsum

\end{multicols}

\end{document}

enter image description here

egreg
  • 1,121,712