3

In my example, I wish to draw grid lines on the second image but now it draws on first image also:

\documentclass{standalone}

\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{backgrounds}
\begin{document}
    \begin{tikzpicture}[background rectangle/.style={fill=yellow!20}, show background rectangle]
    \tikzset{box/.style={anchor=south west,inner sep=0}}
    \node[box] (N1) {\includegraphics[width=\textwidth]{example-image-a}};

    \node[box,right=0.5cm of N1] (N2) {\includegraphics[width=\textwidth]{example-image-b}};
    \begin{scope}[x={(N2.south east)},y={(N2.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}; }
    \end{scope}
    \foreach \i in {N2.south east,N2.north west} {
        \node[circle,fill=red,minimum size=20pt] at(\i) {};
    }

    \end{tikzpicture}
\end{document}

enter image description here

5

You must use shift={N2.south west} to change the origin in your scope:

\documentclass{standalone}

\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{backgrounds}
\begin{document}
    \begin{tikzpicture}[background rectangle/.style={fill=yellow!20}, show background rectangle]
    \tikzset{box/.style={anchor=south west,inner sep=0}}
    \node[box] (N1) {\includegraphics[width=\textwidth]{example-image-a}};

    \node[box,right=0.5cm of N1] (N2) {\includegraphics[width=\textwidth]{example-image-b}};
    \begin{scope}[shift={(N2.south west)},x={(N2.south east)},y={(N2.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}; }
    \end{scope}
    \foreach \i in {N2.south east,N2.north west} {
        \node[circle,fill=red,minimum size=20pt] at(\i) {};
    }

    \end{tikzpicture}
\end{document}

enter image description here

3

This is more like a work-around, place the second picture at the origin first, then place the first image relative to it.

\documentclass{standalone}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{backgrounds}
\begin{document}
    \begin{tikzpicture}[background rectangle/.style={fill=yellow!20}, show background rectangle]
    \tikzset{box/.style={anchor=south west,inner sep=0}}
    \node[box] (N2) {\includegraphics[width=\textwidth]{example-image-b}};
    \node[box,left=0.7cm of N2] (N1) {\includegraphics[width=\textwidth]{example-image-a}};

    \begin{scope}[x={(N2.south east)},y={(N2.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}; }
    \end{scope}
    \foreach \i in {N2.south east,N2.north west} {
        \node[circle,fill=red,minimum size=20pt] at(\i) {};
    }
    \end{tikzpicture}
\end{document}

enter image description here

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.