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?

2 Answers 2

4

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}
2
  • Would it be possible to obtain the same result, but keeping the original (local) bounding box? The idea would be to add nodes around, without changing the bounding box. So far, every attempt to place a node outside the bounding box failed (nothing is drawn), whether overlay, use as bounding box, etc.
    – Bibi
    Feb 21, 2022 at 9:24
  • @Bibi do not ask new questions in a comment. That only pings one person and so is a request for personal support. Ask a proper new question. Feb 21, 2022 at 9:45
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .