以下小示例文档显示了使用 LaTeX 钩子对 \ShipoutBox 的操作(镜像为例)。背景未镜像,因为它还不是框的一部分。这是一个预期的问题(请参阅“ltshipout-doc”文档)。我如何设法最小化包括前景和背景在内的完整框?是否缺少 LaTeX 钩子?
\listfiles
\documentclass[a4paper,oneside]{article}
\usepackage{blindtext,xcolor,pict2e,graphicx}
\usepackage[left=30mm,right=30mm]{geometry}
\setlength\parindent{0pt}
%\pagestyle{empty}
\AddToHook{shipout/background}{%
\put(0,0){\color{red!30}\circle*{2\paperwidth}}%
}
\AddToHook{shipout/before}{%
\setbox\ShipoutBox=\vbox{\moveright1in\box\ShipoutBox}%
\setbox\ShipoutBox=\hbox to\paperwidth{\box\ShipoutBox\hss}%
\setbox\ShipoutBox=\hbox{\reflectbox{\box\ShipoutBox}}%
\setbox\ShipoutBox=\vbox{\moveleft1in\box\ShipoutBox}%
}
\begin{document}
\rule{\textwidth}{1mm} \par
\blindtext \par \vfill \blindtext
\newpage
\rule{\textwidth}{1mm} \par
\blindtext \par \vfill \blindtext
\end{document}
附录: 下面的示例展示了如何镜像页面(包括背景)。虽然可以这样工作,但我希望有一个直接基于 LaTeX 钩子的解决方案。
\listfiles
\documentclass[a4paper,oneside]{article}
\usepackage{blindtext,xcolor,pict2e,graphicx}
\usepackage[left=30mm,right=30mm]{geometry}
\setlength\parindent{0pt}
\usepackage{atbegshi}
\AtBeginShipout{%
\AtBeginShipoutUpperLeft{%
\put(0,0){\color{red!30}\circle*{2\paperwidth}}%
}%
}
\AtBeginShipout{%
\setbox\AtBeginShipoutBox=\vbox{\moveright1in\box\AtBeginShipoutBox}%
\setbox\AtBeginShipoutBox=\hbox to\paperwidth{\box\AtBeginShipoutBox\hss}%
\setbox\AtBeginShipoutBox=\hbox{\reflectbox{\box\AtBeginShipoutBox}}%
\setbox\AtBeginShipoutBox=\vbox{\moveleft1in\box\AtBeginShipoutBox}%
}
\begin{document}
\rule{\textwidth}{1mm} \par
\blindtext \par \vfill \blindtext
\newpage
\rule{\textwidth}{1mm} \par
\blindtext \par \vfill \blindtext
\end{document}
答案1
2023 年 6 月的 LaTeX 版本提供了新的钩子“shipout”。它为该问题提供了通用解决方案(请参阅texdoc ltshipout
):
\listfiles
\documentclass[a4paper,oneside]{article}
\usepackage{blindtext,xcolor,pict2e,graphicx}
\usepackage[left=30mm,right=30mm]{geometry}
\setlength\parindent{0pt}
\AddToHook{shipout/background}{%
\put(0,0){\color{red!30}\circle*{2\paperwidth}}%
}
\AddToHook{shipout}{%
\setbox\ShipoutBox=\vbox{\moveright1in\box\ShipoutBox}%
\setbox\ShipoutBox=\hbox to\paperwidth{\box\ShipoutBox\hss}%
\setbox\ShipoutBox=\hbox{\reflectbox{\box\ShipoutBox}}%
\setbox\ShipoutBox=\vbox{\moveleft1in\box\ShipoutBox}%
}
\begin{document} \Large
\blindtext\par \vfill \blindtext
\newpage
\blindtext\par \vfill \blindtext
\end{document}