使用由以下定义的锚点tikzpagenodes
在 a 内部minipage
会产生意外结果;对于标准 TikZ 定义的锚点系列,情况并非如此current page
,如下例所示。
标签cyan
对应于正确定位的标准 TikZ 锚点(“cp”代表“当前页面”);橙色标签对应于tikzpagenodes
正确定位的锚点(“ta”代表“文本区域”);红色标签对应tikzpagenodes
于不是正确定位,因为锚点是从 a 中调用的minipage
(“ta”代表“文本区域”)。showframe
包装用于直观地指导页面布局;minipage
还用于参考
\documentclass{article}
\usepackage[a6paper]{geometry}
\usepackage{tikzpagenodes}
\usepackage{showframe}
\begin{document}
\centering
\begin{tikzpicture}[remember picture,overlay]
\foreach \Anchor in {north,west,south,east}
{
\node[font=\color{orange}] at (current page text area.\Anchor) {ta.\Anchor};
\node[font=\Huge\color{orange}] at (current page text area.\Anchor) {X};
}
\end{tikzpicture}%
\frame{\begin{minipage}[c][4cm][c]{.5\textwidth}
\begin{tikzpicture}[remember picture,overlay]
\foreach \Anchor in {north,west,south,east}
{
\node[font=\color{cyan}] at (current page.\Anchor) {cp.\Anchor};
\node[font=\Huge\color{cyan}] at (current page.\Anchor) {X};
\node[font=\color{red}] at (current page text area.\Anchor) {ta.area.\Anchor};
\node[font=\Huge\color{red}] at (current page text area.\Anchor) {X};
}
\end{tikzpicture}%
\end{minipage}}
\end{document}
在内部使用时,如何tikzpagenodes
恢复定义的正确锚点minipage
。
答案1
您可以使用fit
库来定义全局“好的” current page text area
:
\tikz[remember picture,overlay]
\node[fit=(current page text area),line width=0,inner sep=0,name=good current page text area]{};
例子:
\documentclass{article}
\usepackage[a6paper]{geometry}
\usepackage{tikzpagenodes}
\usetikzlibrary{fit}
\usepackage{showframe}
\begin{document}
\centering
\tikz[remember picture,overlay]
\node[fit=(current page text area),line width=0,inner sep=0,name=good current page text area]{};
\begin{tikzpicture}[remember picture,overlay]
\foreach \Anchor in {north,west,south,east}
{
\node[font=\color{orange}] at (current page text area.\Anchor) {ta.\Anchor};
\node[font=\Huge\color{orange}] at (current page text area.\Anchor) {X};
}
\end{tikzpicture}%
\frame{\begin{minipage}[c][4cm][c]{.5\textwidth}
\begin{tikzpicture}[remember picture,overlay]
\foreach \Anchor in {north,west,south,east}
{
\node[font=\color{cyan}] at (current page.\Anchor) {cp.\Anchor};
\node[font=\Huge\color{cyan}] at (current page.\Anchor) {X};
%\node[font=\color{red}] at (current page text area.\Anchor) {ta.area.\Anchor};
%\node[font=\Huge\color{red}] at (current page text area.\Anchor) {X};
\node[font=\color{blue}] at (good current page text area.\Anchor) {ta.area.\Anchor};
\node[font=\Huge\color{blue}] at (good current page text area.\Anchor) {X};
}
\end{tikzpicture}%
\end{minipage}}
\end{document}