draw on image not fit original one perfectly

OK, I just tried what I thought should work, and surprisingly it does. That is.

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[x=1pt,y=1pt,line width = 1pt]
    \node[anchor=south west,inner sep=0,outer sep=0] at (-\pgflinewidth/2,-\pgflinewidth/2) {\includegraphics{input.pdf}};
    \draw (0,0) rectangle (50,50);
    \draw (25,25) circle (25);
\end{tikzpicture}
\end{document}

produces

enter image description here

as expected. Why? You put the node with anchor south west, and, as pointed out
by David Purton, your image is wider (and taller) by the line width (since it is wider and taller by half the line width in each direction). And why is this? You draw a path through the specified coordinates, and the line width gets added to this. I know that the explanation is very clumsy, it would be much easier in marmot language, but I am not sure how to type this, so as a compromise I add a figure. ;-)

enter image description here


An alternative to @marmot's solution is to put the image at (25,25) to line up with your circle and anchor it at it's centre:

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[x=1pt,y=1pt,line width = 1pt]
    \node[inner sep=0,outer sep=0] at (25,25) {\includegraphics{input.pdf}};
    \draw (0,0) rectangle (50,50);
    \draw (25,25) circle (25);
\end{tikzpicture}
\end{document}

Tags:

Tikz Pgf