继续为什么 \samepage 不设置 \predisplaypenalty (为 \@M 或任何其他值)?,假设我们想修补 LaTeX 的
\DeclareRobustCommand\samepage{\interlinepenalty\@M
\postdisplaypenalty\@M
\interdisplaylinepenalty\@M
\@beginparpenalty\@M
\@endparpenalty\@M
\@itempenalty\@M
\@secpenalty\@M
\interfootnotelinepenalty\@M}
通过在\predisplaypenalty\@M
某处添加(例如,因为您的类或包(比如,svmono.cls)设置\predisplaypenalty
为小于的值\@M
。)我们不打算\samepage
直接使用而是\begin{samepage}…\end{samepage}
采用哪种方式?
我的尝试到目前为止都失败了。以下是一个失败的例子:
\documentclass{svmono}% version 5.10 (08-Sep-21); cf. http://www.springer.com/gp/authors-editors/book-authors-editors/your-publication-journey/manuscript-preparation#toc-49268 or http://resource-cms.springernature.com/springer-cms/rest/v1/content/20566/data/monographs
% at this spot we wish to redefine the samepage environment, but this one doesn't work:
\usepackage{etoolbox}
\makeatletter
\patchcmd{\samepage}{\interfootnotelinepenalty\@M}{\interfootnotelinepenalty\@M\predisplaypenalty\@M}{}{\typeout{samepage could not be redefined}}
\makeatother
\usepackage{amssymb,mathtools,cleveref}
\begin{document}
\begin{samepage}
\strut\vskip120ex
\begin{remark}[A remark name]\label[remark]{label}
\[
\text{a formula}
\]
\begin{center}%
Table caption\\%%% probably better \nopagebreak\\ instead of \\, but anyway, samepage should better do all the job itself.
\hbox to \hsize{\hfill
\begin{tabular}[b]{|c|}
\hline
Some table\\
\hline
\end{tabular}%
\hfill\llap{$\square$}}%
\end{center}%
\end{remark}%
\end{samepage}
\end{document}
产量
无法重新定义 samepage
在日志中并在备注中分页:
如何正确™ 扩展或重新定义samepage
环境,以便我们不会在评论中出现分页符?
答案1
etoolbox
无法修补使用 定义的命令\DeclareRobustCommand
。您可以使用包xpatch
将代码附加到带有 的强大命令中\xapptocmd
。在这里您可以看到,补丁被使用了:
\documentclass{svmono}% version 5.10 (08-Sep-21); cf. http://www.springer.com/gp/authors-editors/book-authors-editors/your-publication-journey/manuscript-preparation#toc-49268 or http://resource-cms.springernature.com/springer-cms/rest/v1/content/20566/data/monographs
% at this spot we wish to redefine the samepage environment, but this one doesn't work:
\usepackage{xpatch}
\makeatletter
\xapptocmd{\samepage}{\predisplaypenalty\@M}{}{\PatchFailure}
\makeatother
\usepackage{amssymb,mathtools,cleveref}
\begin{document}
\begin{samepage}
\strut\vskip120ex
\begin{remark}[A remark name]\label[remark]{label}
\verb|\predisplaypenalty| is \the\predisplaypenalty
\[
\text{a formula}
\]
\begin{center}%
A table\\%%% probably better \nopagebreak\\ instead of \\, but anyway, samepage should better do all the job itself.
\hbox to \hsize{\hfill
\begin{tabular}[b]{|c|}
\hline
Some table\\
\hline
\end{tabular}%
\hfill\llap{$\square$}}%
\end{center}%
\end{remark}%
\end{samepage}
\end{document}
但是如果你看一下整个内容,你还会发现,这并不能阻止头部之后的分页符remark
:
甚至,如果你模式\begin{samepage}
后 \strut\vskip120ex
你会得到相同的结果
所以你的问题的根源不是\predisplaypentalty
。如果你真的不想在里面分页remark
,我建议使用minipage
:
\documentclass{svmono}% version 5.10 (08-Sep-21); cf. http://www.springer.com/gp/authors-editors/book-authors-editors/your-publication-journey/manuscript-preparation#toc-49268 or http://resource-cms.springernature.com/springer-cms/rest/v1/content/20566/data/monographs
% at this spot we wish to redefine the samepage environment, but this one doesn't work:
\usepackage{amssymb,mathtools,cleveref}
\begin{document}
\strut\vskip120ex
\noindent\begin{minipage}{\textwidth}
\begin{remark}[A remark name]\label[remark]{label}
\[
\text{a formula}
\]
\begin{center}%
A table\\%%% probably better \nopagebreak\\ instead of \\, but anyway, samepage should better do all the job itself.
\hbox to \hsize{\hfill
\begin{tabular}[b]{|c|}
\hline
Some table\\
\hline
\end{tabular}%
\hfill\llap{$\square$}}%
\end{center}%
\end{remark}%
\end{minipage}
\end{document}
如果您只是不想在开头有分页符remark
,请使用包needspace
。