有人能解释一下这里发生了什么吗?:
\documentclass[showtrims,svgnames]{memoir}
\usepackage{lipsum}
\settrimmedsize{210mm}{148mm}{*}
\setstocksize{236mm}{164mm}
\settrims{5mm}{5mm}
\setulmarginsandblock{20mm}{22mm}{*}
\setlrmarginsandblock{20mm}{30mm}{*}
\checkandfixthelayout
\trimLmarks
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[remember picture, overlay]
\draw[red] (current page.south west) rectangle
(current page.north east);
\end{tikzpicture}
\lipsum[1-4]
\end{document}
渲染(在 XeLateX 中)如下所示。
我希望更好地了解 TikZ 如何定义/确定“当前页面”节点的位置。我可以看到西南角与库存对齐,但西北角似乎是根据错误的尺寸计算的。
这是 PDF 输出的第 1 页:
答案1
尺寸是正确的,因为 TikZ/PGF 使用\paperwidth
和\paperheight
作为页面尺寸,memoir 可以正确设置而没有出血。然而,原点根本没有计算,a{0pt}{0pt}
是 pgfmoduleshapes 中的硬编码,其中current page
创建了。您可以重新定义它,但我建议创建一个名为 的新边界框memoir page
,它将剪切边距,但也会考虑奇数页和偶数页。代码如下,在 pdflatex 和 xelatex 中对我有用,但有一个问题 - 命令必须重复两次(对于 LaTeX 来说几乎没有什么特别的)。
\documentclass[showtrims,svgnames]{memoir}
\usepackage{lipsum}
\settrimmedsize{210mm}{148mm}{*}
\setstocksize{236mm}{164mm}
\settrims{5mm}{5mm}
\setulmarginsandblock{20mm}{22mm}{*}
\setlrmarginsandblock{20mm}{30mm}{*}
\checkandfixthelayout
\trimLmarks
\usepackage{tikz}
% this is the added code. Use \calculatetrims when you change page geometry
% You also have to use "memoir page" instead of "current page" in tikz
\usepackage{calc}
\makeatletter
\newlength\memoirleftodd \newlength\memoirrightodd
\newlength\memoirlefteven \newlength\memoirrighteven
\newlength\memoirtop \newlength\memoirbottom
\def\calculatetrims{
\setlength\memoirbottom{\stockheight-\paperheight-\trimtop}
\setlength\memoirleftodd{\stockwidth-\paperwidth-\trimedge}
\setlength\memoirlefteven{\trimedge}
\setlength\memoirtop{\memoirbottom+\paperheight}
\setlength\memoirrightodd{\memoirleftodd+\paperwidth}
\setlength\memoirrighteven{\memoirlefteven+\paperwidth}}
\expandafter\def\csname pgf@sh@ns@memoir page\endcsname{rectangle}
\expandafter\def\csname pgf@sh@np@memoir page\endcsname{%
\def\southwest{\checkoddpage\pgfqpoint{
\ifoddpage\memoirleftodd\else\memoirlefteven\fi}{\memoirbottom}}%
\def\northeast{\checkoddpage\pgfqpoint{
\ifoddpage\memoirrightodd\else\memoirrighteven\fi}{\memoirtop}}}
\expandafter\def\csname pgf@sh@nt@memoir page\endcsname{{1}{0}{0}{1}{0pt}{0pt}}
\expandafter\def\csname pgf@sh@pi@memoir page\endcsname{pgfpageorigin}
% (Brent's additional code goes here)
\makeatother
\begin{document}
\calculatetrims % You must write this before first overlay picture
\begin{tikzpicture}[remember picture, overlay, line width=3pt]
\draw[red] (memoir page.south west) rectangle (memoir page.north east);
\end{tikzpicture}
\lipsum[1-4]
\begin{tikzpicture}[remember picture, overlay, line width=3pt]
\draw[red] (memoir page.south west) rectangle (memoir page.north east);
\end{tikzpicture}
\end{document}
如果有人需要这样做库存,这里有一个建议,可以替代上面的代码,或者在所示位置添加:
\expandafter\def\csname pgf@sh@ns@memoir stock\endcsname{rectangle}
\expandafter\def\csname pgf@sh@np@memoir stock\endcsname{%
\def\southwest{\pgfqpoint{0pt}{0pt}}%
\def\northeast{\pgfqpoint{\stockwidth}{\stockheight}}%
}
\expandafter\def\csname pgf@sh@nt@memoir stock\endcsname{{1}{0}{0}{1}{0pt}{0pt}}
\expandafter\def\csname pgf@sh@pi@memoir stock\endcsname{pgfpageorigin}
(不要忘记这需要在\makeatletter
/\makeatother
对内。)