multicols
当从包中使用时multicol
,可以执行以下操作:
\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}
我需要在更复杂的设置中使用它,因此仅仅使用两个多列环境是不够的。
编辑: 更“复杂”的设置似乎在这里更相关,因此我尝试为我的实际用例提供一个最小的例子:
\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) 的解决方案无法在此设置下编译。
答案1
关闭multicols
环境,待环境恢复后再重新打开。
我使用该etoolbox
命令\BeforeBeginEnvironment
在打开的组\begin{escapemulticol}
开始之前执行某些操作,并在完成\aftergroup
后延迟执行某些操作。\end{escapemulticol}
\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}
答案2
基于扩展 MWE 的新答案
\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}
原始答案
\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}
或者:
\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}