8

Using the anchors defined by tikzpagenodes inside a minipage produces unexpected results; this is not the case for the current page family of anchors defined by standard TikZ as the following example shows.

Labels in cyan correspond to the standard TikZ anchors which are correctly positioned ("cp" stands for "current page"); labels in orange correspond to tikzpagenodes anchors which are correctly positioned ("ta" stands for "text area"); labels in red correspond to tikzpagenodes anchors which are not correctly positioned since the anchors were called from withing a minipage ("ta" stands for "text area"). The showframe package was used to have a visual guide of the page layout; the minipage also was framed for reference

\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}

enter image description here

How can the correct anchors defined by tikzpagenodes be recovered when used inside a minipage.

7

You may use the fit library to define a global "good" 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]{};

Example:

\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}
  • It produces two misplaced blue X and no orange ? – Tarass Apr 26 '14 at 7:18
  • @Tarass This example requires two compilations. – Paul Gaborit Apr 26 '14 at 7:34
  • I didn't know. Works fine. Sorry. Should I delete the first comment ? – Tarass Apr 26 '14 at 7:45
  • @Tarass The first compilation warns: "LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right". Leave your first comment: it can serve other people. ;-) – Paul Gaborit Apr 26 '14 at 9:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.