5

I'm wanting to populate the cover page of my package with a border of examples of my package command's outputs, which are drawn in TikZ. To this end I'm using a tikzpicture environment with the overlay option. However, part of my command's syntax involves defining a local bounding box and using its anchors to draw other parts of the symbol, similar to the MWE below:

\documentclass[a4paper]{article}
\usepackage{tikz}
\begin{document}    

\begin{tikzpicture}[overlay]

\begin{scope} [local bounding box=M]
\draw (0, 0) rectangle (1, 1);
\end{scope}
\node [anchor=east] at (M.north west) {A};
\end{tikzpicture}

\end{document}

However, when I compile only the rectangle renders, the 'A' node does not:

Example 1

When I compile with the overlay option removed, the node renders:

Example 2

Is it possible to get the node to render even when the overlay option is set?

3

overlay stops the bounding box calculations (use as bounding box would do it too).

Instead of overlay you could reset the bounding box at the end:

\documentclass[a4paper]{article}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}    
\begin{scope} [local bounding box=M]
\draw (0, 0) rectangle (1, 1);
\end{scope}
\node [anchor=east] at (M.north west) {A};
\pgfresetboundingbox
\path[use as bounding box] (0,0);
\end{tikzpicture}

\end{document}
1

I know that we have to avoid nested tikzpictures, but this is the only way I found:

\documentclass[a4paper]{article}
\usepackage{tikz}
\begin{document}    

\begin{tikzpicture}[overlay]
\begin{tikzpicture}
  \begin{scope}[local bounding box=m]
  \draw(0, 0) rectangle (1, 1) coordinate (M);
  \end{scope}
  \begin{scope}[overlay]
  \node [anchor=east] at (m.north west) {A};
  \end{scope}
\end{tikzpicture}
\end{tikzpicture}

I tested it and works... But may be is not the suggested way.

PS: You can imagine the way I thought to trick the environment :P

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.