如何强制 LateX 环境从新页面开始

如何强制 LateX 环境从新页面开始

在此示例中,如何使用\breakbox强制下面定义的示例环境在新页面上继续?

这里有一个例子来说明:

\begin{document}
\maketitle
\section{test}
\begin{exemple}
\LR{Example!}
$$
\vdots
$$
 \breakbox
 $$
\vdots
$$
\LR{How can I force this box to start on a new page?
}
\end{exemple}
\end{document}

输出如下: 在此处输入图片描述

以下是模板中环境的定义:

%%%%%%%%%%% Environnement "exemple"

\newsavebox{\ex@box}
\newenvironment{exemple}[1][]
{%
    \setcounter{break@box}{0}
    \setcounter{type@box}{1}
    \typebox{ex}
    \def\titletext{مثال}
    \ifx#1\@empty\xdef\pluriel@ex{}\else\xdef\pluriel@ex{#1}\fi
    \itemclass{extitle@bg@color}{\extitle@font}
    \begin{lrbox}{\ex@box}
    \begin{minipage}{\dimexpr\linewidth-\marginleft}
}
{%
    \end{minipage}
    \end{lrbox}
    \vspace*{\spacebeforeex}
    \begin{tikzpicture}
    \node[fill=ex@bg@color] (texte) {\usebox{\ex@box}};
    \node[fill=extitle@bg@color,text=extitle@color,below right,draw=extitle@bg@color,very thick,text width={\dimexpr\marginleft-2mm},align=center] at ($(texte.north east)+(0pt,0)$) { \large\bf\titletext\pluriel@ex \ifnum\thebreak@box>0\par(suite)\fi};
    \end{tikzpicture}
}

以及 breakbox 定义:

    %%%%%%%%%%%%% \breakbox

\def\typebox#1{%
\expandafter\def\csname spacebefore\endcsname{\expandafter\csname spacebefore#1\endcsname}%
\expandafter\def\csname stylebox\endcsname{\expandafter\csname#1@box\endcsname}%
\expandafter\def\csname titlefont\endcsname{\expandafter\csname#1title@font\endcsname}%
\expandafter\def\csname pluriel\endcsname{\expandafter\csname pluriel@#1\endcsname}%
\ifnum\thetype@box=0\setlength{\spacebottom}{\expandafter\csname spacebottom#1\endcsname}\fi
\expandafter\def\csname fillbg\endcsname{#1@bg@color}
\expandafter\def\csname titlecolor\endcsname{#1title@color}
\expandafter\def\csname titlebgcolor\endcsname{#1title@bg@color}
}
\newcounter{break@box}
\newcounter{type@box}
\newcommand*{\breakbox}
{%
    
        \ifnum\thetype@box=0 % pour "rem" ou "meth" ou "new"
        \end{minipage}
            \end{lrbox}
            \vspace*{\spacebefore}
            \stepcounter{break@box}
            \begin{tikzpicture}
            \node (texte) {\usebox{\stylebox}\vspace*{\spacebottom}};
            \fill[fill=shadow@color] ($(texte.south west)+(1pt,-1pt)$) -- ($(texte.north west)+(1pt,-1pt)$) -- ($(texte.north east)+(1pt,-1pt)$) -- ($(texte.south east)+(0,6.5pt)+(1pt,-2pt)$) .. controls ($(texte.south east)+(-2pt,2pt)+(1pt,-1pt)$) and ($(texte.south east)+(-3pt,1pt)+(1pt,-1pt)$) .. ($(texte.south east)+(-6.5pt,0)+(1pt,-1pt)$) -- cycle;
            \fill[fill=\fillbg] (texte.south west) -- (texte.north west) -- (texte.north east) -- ($(texte.south east)+(0,5pt)$) -- ($(texte.south east)+(-5pt,0)$) -- cycle;
            \fill[fill=shadow@color!50!black] ($(texte.south east)+(0,5pt)$) .. controls ($(texte.south east)+(-2pt,2pt)$) and ($(texte.south east)+(-3pt,1pt)$) .. ($(texte.south east)+(-5pt,0)$) .. controls ($(texte.south east)+(-4.5pt,2.5pt)$) .. ($(texte.south east)+(-5pt,5pt)$) .. controls ($(texte.south east)+(-2.5pt,4.5pt)$) .. ($(texte.south east)+(0,5pt)$);
            \node at(texte) {\usebox{\stylebox}};
            \node[rounded corners=3pt,fill=\fillbg!75,draw=\titlecolor] at ($(texte.south east)-(1,0)$) {...};
            \node[above right,fill=\titlebgcolor,text=\titlecolor] at (texte.north west) {\titlefont \titletext\pluriel};
            \end{tikzpicture}\newline
            \begin{lrbox}{\stylebox}
            \begin{minipage}{\linewidth}
        \fi
        \ifnum\thetype@box=1 % pour "def" ou "prop"
            \end{minipage}
            \end{lrbox}
            \vspace*{\spacebefore}
            \stepcounter{break@box}
            \begin{tikzpicture}
            \node[fill=\fillbg] (texte) {\usebox{\stylebox}};
            %\draw[very thick,draw=\titlebgcolor] (texte.north west) -- (texte.south west);
            \node[rounded corners=3pt,fill=\fillbg!75,draw=\titlebgcolor] at ($(texte.south east)-(13.5,0)$) {...};
            %\node[fill=deftitle@bg@color,text=deftitle@color,below left,draw=deftitle@bg@color,very thick,text width={\dimexpr\marginleft-2mm},align=center] at (texte.north west) {\deftitle@font \titletext\pluriel@def \ifnum\thebreak@box>0\par(suite)\fi};
            \node[fill=\titlebgcolor,text=\titlecolor,below right,draw=\titlebgcolor,very thick,text width={\dimexpr\marginleft-2mm},align=center] at ($(texte.north east)+(0pt,0)$) { \large\bf\titletext\pluriel};
            \end{tikzpicture}\newline
            \begin{lrbox}{\stylebox}
            \begin{minipage}{\dimexpr\linewidth-\marginleft}
        \fi
        \ifnum\thetype@box=2 % pour "dem"
            \vskip-1em\hfill{\demtitle@font(...)}
            \end{minipage}
            \end{lrbox}
            \vspace*{\spacebefore}
            \begin{tikzpicture}
            \node[fill=dem@bg@color] (texte) {\usebox{\dem@box}};
            \ifnum\indic=1
                \draw[thick,draw=dem@border@color,decorate, decoration={random steps, segment length=3pt,amplitude=1pt}] (texte.north west) -- (texte.south west);
            \else
                \ifnum\indic=2
                    \draw[thick,draw=dem@border@color,decorate, decoration={random steps, segment length=3pt,amplitude=1pt}] (texte.north west) -- (texte.south west) -- (texte.south east);
                \else
                    \ifnum\indic=3
                        \draw[thick,draw=dem@border@color,decorate, decoration={random steps, segment length=3pt,amplitude=1pt}] (texte.north west) -- (texte.south west);
                        \draw[thick,draw=dem@border@color,decorate, decoration={random steps, segment length=3pt,amplitude=1pt}] (texte.north east) -- (texte.south east);
                    \else
                        \ifnum\indic=4
                            \draw[thick,draw=dem@border@color,decorate, decoration={random steps, segment length=3pt,amplitude=1pt}] (texte.north east) -- (texte.north west) -- (texte.south west);
                        \else
                            \ifnum\indic=5
                                \draw[thick,draw=dem@border@color,decorate, decoration={random steps, segment length=3pt,amplitude=1pt}] (texte.north west) -- (texte.south west) -- (texte.south east) -- (texte.north east) -- cycle;
                            \fi
                        \fi
                    \fi
                \fi
            \fi
            \node[below left,minimum width=0.5\marginleft] at (texte.north west) {\phantom{-}};
            \end{tikzpicture}\newline
            \begin{lrbox}{\dem@box}
            \begin{minipage}{\dimexpr\linewidth-0.5\marginleft}
            {\demtitle@font \titletext~(suite)}\par\medskip%
        \fi
}

注意:\LR{} 用于从左到右书写文本,与问题无关。

我使用这个模板:https://www.overleaf.com/latex/templates/nice-arabic-book-template/qttfgxhqbwkc

答案1

我在它们之间添加了 \par,并且另一个框会自动打印在另一页上,以防我感兴趣。

该解决方案基于@John Kormylo 的提示

 %%%%%%%%%%%%% \breakbox
    
    \def\typebox#1{%
    \expandafter\def\csname spacebefore\endcsname{\expandafter\csname spacebefore#1\endcsname}%
    \expandafter\def\csname stylebox\endcsname{\expandafter\csname#1@box\endcsname}%
    \expandafter\def\csname titlefont\endcsname{\expandafter\csname#1title@font\endcsname}%
    \expandafter\def\csname pluriel\endcsname{\expandafter\csname pluriel@#1\endcsname}%
    \ifnum\thetype@box=0\setlength{\spacebottom}{\expandafter\csname spacebottom#1\endcsname}\fi
    \expandafter\def\csname fillbg\endcsname{#1@bg@color}
    \expandafter\def\csname titlecolor\endcsname{#1title@color}
    \expandafter\def\csname titlebgcolor\endcsname{#1title@bg@color}
    }
    \newcounter{break@box}
    \newcounter{type@box}
    \newcommand*{\breakbox}
    {%
        
            \ifnum\thetype@box=0 % pour "rem" ou "meth" ou "new"
            \end{minipage}
                \end{lrbox}
                \vspace*{\spacebefore}
                \stepcounter{break@box}
                \begin{tikzpicture}
                \node (texte) {\usebox{\stylebox}\vspace*{\spacebottom}};
                \fill[fill=shadow@color] ($(texte.south west)+(1pt,-1pt)$) -- ($(texte.north west)+(1pt,-1pt)$) -- ($(texte.north east)+(1pt,-1pt)$) -- ($(texte.south east)+(0,6.5pt)+(1pt,-2pt)$) .. controls ($(texte.south east)+(-2pt,2pt)+(1pt,-1pt)$) and ($(texte.south east)+(-3pt,1pt)+(1pt,-1pt)$) .. ($(texte.south east)+(-6.5pt,0)+(1pt,-1pt)$) -- cycle;
                \fill[fill=\fillbg] (texte.south west) -- (texte.north west) -- (texte.north east) -- ($(texte.south east)+(0,5pt)$) -- ($(texte.south east)+(-5pt,0)$) -- cycle;
                \fill[fill=shadow@color!50!black] ($(texte.south east)+(0,5pt)$) .. controls ($(texte.south east)+(-2pt,2pt)$) and ($(texte.south east)+(-3pt,1pt)$) .. ($(texte.south east)+(-5pt,0)$) .. controls ($(texte.south east)+(-4.5pt,2.5pt)$) .. ($(texte.south east)+(-5pt,5pt)$) .. controls ($(texte.south east)+(-2.5pt,4.5pt)$) .. ($(texte.south east)+(0,5pt)$);
                \node at(texte) {\usebox{\stylebox}};
                \node[rounded corners=3pt,fill=\fillbg!75,draw=\titlecolor] at ($(texte.south east)-(1,0)$) {...};
                \node[above right,fill=\titlebgcolor,text=\titlecolor] at (texte.north west) {\titlefont \titletext\pluriel};
                \end{tikzpicture}\newline
                    \par%%%%%%%%%%%%%my edit
                \begin{lrbox}{\stylebox}
                \begin{minipage}{\linewidth}
            \fi
            \ifnum\thetype@box=1 % pour "def" ou "prop"
                \end{minipage}
                \end{lrbox}
                \vspace*{\spacebefore}
                \stepcounter{break@box}
                \begin{tikzpicture}
                \node[fill=\fillbg] (texte) {\usebox{\stylebox}};
                %\draw[very thick,draw=\titlebgcolor] (texte.north west) -- (texte.south west);
                \node[rounded corners=3pt,fill=\fillbg!75,draw=\titlebgcolor] at ($(texte.south east)-(13.5,0)$) {...};
                %\node[fill=deftitle@bg@color,text=deftitle@color,below left,draw=deftitle@bg@color,very thick,text width={\dimexpr\marginleft-2mm},align=center] at (texte.north west) {\deftitle@font \titletext\pluriel@def \ifnum\thebreak@box>0\par(suite)\fi};
                \node[fill=\titlebgcolor,text=\titlecolor,below right,draw=\titlebgcolor,very thick,text width={\dimexpr\marginleft-2mm},align=center] at ($(texte.north east)+(0pt,0)$) { \large\bf\titletext\pluriel};
                \end{tikzpicture}\newline
                    \par%%%%%%%%%%%%%my edit
    
                \begin{lrbox}{\stylebox}
                \begin{minipage}{\dimexpr\linewidth-\marginleft}
            \fi
            \ifnum\thetype@box=2 % pour "dem"
                \vskip-1em\hfill{\demtitle@font(...)}
                \end{minipage}
                \end{lrbox}
                \vspace*{\spacebefore}
                \begin{tikzpicture}
                \node[fill=dem@bg@color] (texte) {\usebox{\dem@box}};
                \ifnum\indic=1
                    \draw[thick,draw=dem@border@color,decorate, decoration={random steps, segment length=3pt,amplitude=1pt}] (texte.north west) -- (texte.south west);
                \else
                    \ifnum\indic=2
                        \draw[thick,draw=dem@border@color,decorate, decoration={random steps, segment length=3pt,amplitude=1pt}] (texte.north west) -- (texte.south west) -- (texte.south east);
                    \else
                        \ifnum\indic=3
                            \draw[thick,draw=dem@border@color,decorate, decoration={random steps, segment length=3pt,amplitude=1pt}] (texte.north west) -- (texte.south west);
                            \draw[thick,draw=dem@border@color,decorate, decoration={random steps, segment length=3pt,amplitude=1pt}] (texte.north east) -- (texte.south east);
                        \else
                            \ifnum\indic=4
                                \draw[thick,draw=dem@border@color,decorate, decoration={random steps, segment length=3pt,amplitude=1pt}] (texte.north east) -- (texte.north west) -- (texte.south west);
                            \else
                                \ifnum\indic=5
                                    \draw[thick,draw=dem@border@color,decorate, decoration={random steps, segment length=3pt,amplitude=1pt}] (texte.north west) -- (texte.south west) -- (texte.south east) -- (texte.north east) -- cycle;
                                \fi
                            \fi
                        \fi
                    \fi
                \fi
                \node[below left,minimum width=0.5\marginleft] at (texte.north west) {\phantom{-}};
                \end{tikzpicture}\newline
                    \par%%%%%%%%%%%%%my edit
    
                \begin{lrbox}{\dem@box}
                \begin{minipage}{\dimexpr\linewidth-0.5\marginleft}
                {\demtitle@font \titletext~(suite)}\par\medskip%
            \fi
    }

相关内容