允许小页面分栏但不允许分页

允许小页面分栏但不允许分页

我有一个 twocolumn包含许多部分的文档。我希望允许部分跨同一页的列拆分,但不允许部分跨页拆分。

我能找到的最密切相关的先前提出的问题是。但它不能解决我的问题。

在 MWE 中,我有一个很长的部分需要跨列才能放入页面。 minipage 环境不允许这样做,它会在新列中开始较长的部分,但会超出页面范围。点击此处查看图片

我还想防止章节标题与章节文本分离。

\documentclass[12pt,oneside,twocolumn]{article}
\columnsep=2.5cm
\raggedbottom
\newcommand{\textbox}[1]{
\framebox{\begin{minipage}{\columnwidth}\mbox{}\vspace{#1}\end{minipage}}}

\begin{document}

\section{small-length section}
\textbox{1in}

\section{epic-length section}
\textbox{12in}

\section{mid-length section}
\textbox{3in}

\section{big-length section}
\textbox{6in}

\end{document}

答案1

如果环境的结束SamePage是在不同的页面上,则会\newpage在开始之前执行。

此解决方案有两个问题。首先,文档可能需要超过 2 次运行才能稳定下来。其次,如果后续编辑释放了足够的空间让环境适合上一页,则测试它的唯一方法是删除辅助文件(清理项目)。或者,使用draft模式将禁用页面测试。

\documentclass[twocolumn]{article}
\usepackage{environ}
\usepackage{lipsum}

\newcounter{SamePage}

\newcommand{\newSamePage}[2]% #1 = index, #2 = page
{\expandafter\gdef\csname SamePage#1\endcsname{#2}}

\makeatletter
\newenvironment{SamePage}%
{\stepcounter{SamePage}%
\ifdim\overfullrule=0pt\relax% check for final mode
  \@ifundefined{SamePage\theSamePage}{}%
    {\ifnum\csname SamePage\theSamePage\endcsname>\c@page\newpage\fi}%
\fi\ignorespaces}%
{\protected@write\@auxout{}{\string\newSamePage{\theSamePage}{\arabic{page}}}%
\par}
\makeatother

\begin{document}
\begin{SamePage}
\section{First}
\lipsum[1-4]
\end{SamePage}
\begin{SamePage}
\section{Second}
\lipsum[5-8]
\end{SamePage}
\begin{SamePage}
\section{Third}
\lipsum[9]
\end{SamePage}

\end{document}

相关内容