# position node relative to current bounding box

With

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}

\draw (2,2) circle (3cm);

\node at (current bounding box.north)[anchor=north]{north};
\node at (current bounding box.north west)[anchor=north west]{north west};
\node at (current bounding box.north east)[anchor=north east]{north east};

\end{tikzpicture}
\end{document}


one can position a node relative to the bounding box of the picture, using a set of given positions (north, north west, etc.).

I would like to position the text more freely within the current bounding box, e.g., at position (0.45, 0.7), where (0, 0) is the lower left and (1, 1) the top right corner of the current bounding box.

How to achieve this?

• \path (current bouding box.south west) -- (current bounding box.north east) node[pos=0.7] {xxx}; – Ignasi Oct 25 '15 at 19:22

You can calculate the coordinate using the calc library. Note that if you place nodes near the edge that sticks outside, the current bounding box node will change. If you don't want the bounding box to be changed you can add a \useboundingbox as in the below example.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand\relcoord[2]{({$(current bounding box.south west)!#1!(current bounding box.south east)$} |- {$(current bounding box.south west)!#2!(current bounding box.north west)$})}
\begin{document}
\begin{tikzpicture}

\node at (current bounding box.north)[anchor=north]{north};
\node at (current bounding box.north west)[anchor=north west]{north west};
\node at (current bounding box.north east)[anchor=north east]{north east};

\useasboundingbox \relcoord{0}{0} rectangle \relcoord{1}{1};

\draw [use as bounding box,help lines,step=0.5cm] \relcoord{0}{0} grid \relcoord{1}{1};


• I see slight inaccuracies with \foreach \x in {0,...,9} { \node at \relcoord{0.\x}{0.7}[anchor=center] {x}; } \node at \relcoord{1.0}{0.7}[anchor=center] {x}; \foreach \x in {0,...,9} { \node at \relcoord{0.7}{0.\x}[anchor=center] {x}; } \node at \relcoord{0.7}{1.0}[anchor=center] {x}; , in particular for \x=0. Also, the two loops don't intersect exactly. – Nico Schlömer Oct 25 '15 at 20:46
• @NicoSchlömer When you place nodes that has content outside the bounding box the current bounding box will change. In my example, if you add use as bounding box as an option to the \draw that makes the grid, and add the loops after it, it looks better. – Torbjørn T. Oct 25 '15 at 20:51