tikzpagenodes 和 minipage 的问题

tikzpagenodes 和 minipage 的问题

使用由以下定义的锚点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}

相关内容