# How to draw on a tikz picture without shifting it

I'm trying to draw on a tikz image. When I add arrows the pictures shifts to the right out of the frame. I'm a newby in latex as you can see. I couldn't find a proper solution or couldn't adapt the ones I found to my needs. Any ideas on this?

Here's my code:

\documentclass{article}

\usepackage{graphicx}
\usepackage{rotating}
\usepackage{subfigure}
\usepackage{tikz}
\usepackage{tikz-imagelabels}
\usepackage{caption}
\usetikzlibrary{arrows,snakes,backgrounds}

\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}\node[anchor=south west,inner sep=0] (image) at (0,0){\includegraphics[width=18cm]{filename}};
\begin{scope}[x={(image.south east)},y={(image.north west)}]

\draw[help lines,xstep=.1,ystep=.1] (0,0) grid (1,1);
\foreach \x in {0,1,...,9} { \node [anchor=north] at (\x/10,0) {0.\x}; }
\foreach \y in {0,1,...,9} { \node [anchor=east] at (0,\y/10) {0.\y}; }

%
\draw [thick, ->] (-0.05, 0.57) -- (0.07, 0.57);
\filldraw [thick] (-0.18, 0.57)  node[anchor=west] {Kühlkanäle};

%
\draw [thick, ->] (-0.05, 0.8) -- (0.2, 0.63);
\filldraw [thick] (-0.25, 0.8)  node[anchor=west] {Stirnseitiger Reibring};

%
\draw [thick, ->] (-0.05, 0.4) -- (0.2, 0.4);
\filldraw [thick] (-0.25, 0.8)  node[anchor=west] {Stirnseitiger Reibring};

\end{scope}
\end{tikzpicture}
\end{figure}

\end{document}


• See also pgfinterruptboundingbox (environment, page 1080) and \pgfresetboundingbox (page 1105). – John Kormylo Jan 20 at 22:10

The tikzpicture shifts because tikz computes the bounding box from all coordinates mentioned in the picture. This includes the labels that protrude from the image.

Include the line

\useasboundingbox (image.south east) rectangle (image.north west);


after defining the node image. This tells tikz to use this rectangle as bounding box instead of computing the box itself.

• thank you, exactly what I was looking for! – ChrisW Jan 20 at 18:55

18cm is a bit large for the image. But beside this: you can use a scope with overlay:

\documentclass{article}

\usepackage{graphicx}
\usepackage{rotating}
\usepackage{subfigure}
\usepackage{tikz}
\usepackage{tikz-imagelabels}
\usepackage{caption}
\usetikzlibrary{arrows,snakes,backgrounds}

\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}\node[anchor=south west,inner sep=0] (image) at (0,0){\includegraphics[width=18cm]{example-image}};
\begin{scope}[x={(image.south east)},y={(image.north west)}]

\draw[help lines,xstep=.1,ystep=.1] (0,0) grid (1,1);
\foreach \x in {0,1,...,9} { \node [anchor=north] at (\x/10,0) {0.\x}; }
\foreach \y in {0,1,...,9} { \node [anchor=east] at (0,\y/10) {0.\y}; }

\begin{scope}[overlay] %<----
\draw [thick, ->] (-0.05, 0.57) -- (0.07, 0.57);
\filldraw [thick] (-0.18, 0.57)  node[anchor=west] {Kühlkanäle};

%
\draw [thick, ->] (-0.05, 0.8) -- (0.2, 0.63);
\filldraw [thick] (-0.25, 0.8)  node[anchor=west] {Stirnseitiger Reibring};

%
\draw [thick, ->] (-0.05, 0.4) -- (0.2, 0.4);
\filldraw [thick] (-0.25, 0.8)  node[anchor=west] {Stirnseitiger Reibring};
\end{scope} %<--------
\end{scope}
\end{tikzpicture}
\end{figure}

\end{document}