# How to move tikzpicture with named nodes?

I am trying to position an image with rounded corners to a specific position on screen. However, according to the following post, yshift and xshift do not affect nodes that are named and I am still a bit confused on how to use the ++ and if this is the best approach.

Take my current situation:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage[a4paper,top=3cm, bottom=3cm, left=2cm, right=2cm]{geometry}

\begin{document}

\begin{tikzpicture}
\begin{scope}
\clip [rounded corners=0.7cm] (0,0) rectangle coordinate (centerpoint) (4,4.0cm);
\node [inner sep=0pt] at (centerpoint) {\includegraphics[width=4.0cm]{dogesmall.jpg}};

\draw[line width=0.08cm,rounded corners=0.7cm] (0,0) rectangle (4,4.0cm);
\end{scope}
\end{tikzpicture}

\end{document}


(Where "dogesmall.jpg" is my current image)

This produces a result that places the image in the upper left hand corner, as defined by the margins. However, I would like to tweak the position of the tikzpicture without changing the margins like so:

I tried following this post by using the following:

\newcommand\setcoordinates{
\coordinate (centerpoint) at (4,4.0cm);
}


And then referencing this coordinate by \coordinate (centerpoint) and then applying a shift transformation, but that does not work either. Any thoughts?

Welcome to TeX.SE! Are you looking for overlay, which allows you to position stuff at absolute coordinates?

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikzpagenodes}
\usepackage[a4paper,top=3cm, bottom=3cm, left=2cm, right=2cm]{geometry}

\begin{document}

\begin{tikzpicture}[overlay,remember picture]
\begin{scope}
\clip [rounded corners=0.7cm] (current page text area.north west) coordinate (centerpoint)  rectangle ++(4,-4);
\node [inner sep=0pt,anchor=north west] at (centerpoint)
{\includegraphics[width=4.0cm,height=4cm]{example-image-duck}};
\end{scope}
\draw[line width=0.08cm,rounded corners=0.7cm] (centerpoint)  rectangle ++(4,-4);
\end{tikzpicture}

\end{document}


If you want to place the image at the upper left corner of the page (rather than the upper left corner of the of the text area), replace (current page text area.north west) by (current page.north west).

ADDENDUM: This is a version that shifts the picture relative to the current position in the text, which is set using \tikzmark that comes with the tikzmark library.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikzpagenodes}
\usetikzlibrary{tikzmark}
\usepackage[a4paper,top=3cm, bottom=3cm, left=2cm, right=2cm]{geometry}

\begin{document}
\tikzmark{x}
\begin{tikzpicture}[overlay,remember picture]
\begin{scope}
\clip [rounded corners=0.7cm] ([xshift=-1cm,yshift=2cm]pic cs:x) coordinate (centerpoint)  rectangle ++(4,-4);
\node [inner sep=0pt,anchor=north west] at (centerpoint)
{\includegraphics[width=4.0cm,height=4cm]{example-image-duck}};
\end{scope}
\draw[line width=0.08cm,rounded corners=0.7cm] (centerpoint)  rectangle ++(4,-4);
\end{tikzpicture}
\end{document}

• This produces the following error: Package pgf Error: No shape named current page text area is known. In addition, is the only way to tweak the position (i.e. not just using an anchor) to change the ++(4,-4)? – Danny Dan Oct 6 '18 at 20:10
• Using Northwest is called an anchor. It anchors the picture in the northwest corner. I was seeking to move the picture just slightly up and to the left, not necessarily to the exact corner. A shift would be perfect, but I am not allowed to do such an action. Does that make sense? – Danny Dan Oct 6 '18 at 20:27
• I can compile with no errors with (current page.north west), but having (current page text area.north west) produces the error. And I am using the latex compile on www.overleaf.com. Lastly, can you give an example with tikzmark? – Danny Dan Oct 6 '18 at 20:34