确保环境的内容包含偶数页

确保环境的内容包含偶数页

假设我有一个名为 的环境test,我如何确保 的打印内容test始终包含偶数页(这样,如果我双面打印文档,我永远不会在最后一个测试环境末尾的背面看到一个测试环境的开头)。即,如果它只占用奇数页,则在当前测​​试环境的末尾插入一个空白页。lualatex 解决方案也可以。

\documentclass{article}

\usepackage{lipsum}

\newcounter{counttest}
\setcounter{counttest}{0}

\newenvironment{test}{
\newpage % Start test on a newpage
\refstepcounter{counttest}

\textbf{Test Environment No. \arabic{counttest}}\\

Some pretext \newline
}
{
Some Post text
\label{end}
%%Some code to ensure that test occupies an even number of pages, maybe insert a newpage
}


\begin{document}
\lipsum[1]
\begin{test}
\lipsum[2-6]
\end{test}

\begin{test}
\lipsum[6-10]
\end{test}

\begin{test}
\lipsum[10-14]
\end{test}

\end{document}

也许可以以某种方式获取当前测试环境开始的第一个文档页面的页码以及结束的页码。根据这些数字之间的差异是奇数还是偶数,它会添加或不添加空白页。

答案1

尝试这个:

   \documentclass[twoside]{article}
    \usepackage[margin=2in]{geometry}% to have the same margin left and right (actually all 4 margins, but you can define them individually, see the documentation)
    \usepackage{lipsum}
    
    \newcounter{counttest}
    \setcounter{counttest}{0}
    
    \newenvironment{test}{
    \cleardoublepage% instead of \newpage % Start test on a newpage
    \refstepcounter{counttest}
    
    \textbf{Test Environment No. \arabic{counttest}}\\
    
    Some pretext \newline
    }
    {
    Some Post text
    \label{end}
    %%Some code to ensure that test occupies an even number of pages, maybe insert a newpage
    }
    
    
    \begin{document}
    \lipsum[1]
    \begin{test}
    \lipsum[2-6]
    \end{test}
    \begin{test}
    \lipsum[6-10]
    \end{test}
    \begin{test}
    \lipsum[10-13]
    \end{test}
    \begin{test}
    \lipsum[10-14]
    \end{test}
    \end{document}

相关内容