1

I have two complex TikZ drawings that need to overlap (appear on the same page). I can't put them into one tikzpicture, because different scale parameters need to be applied to them. Minimal example:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,fit}
\begin{document}
\begin{tikzpicture}[inner sep=0pt, outer sep=0pt, scale=2]
  \node (image) {\includegraphics{example-image}};
  \fill [white]
    (0,1) circle [radius=1];
\end{tikzpicture}
\begin{tikzpicture}[overlay, remember picture, scale=1]
  \fill [red]
    (0,0) circle [radius=1];
\end{tikzpicture}
\end{document}

This is what I get:

enter image description here

This is what I actually need:

enter image description here

The overlay option doesn't seem to work as expected. Using (current page.center) in the second tikzpicture doesn't work either. What am I doing wrong?

4
  • Do you really need to use a second tikzpicture?
    – Sigur
    Oct 9 '18 at 16:07
  • Yes. :( As I explained, I need to use a different scale for each figure.
    – kontextify
    Oct 9 '18 at 16:08
  • 2
    You can use a single one and use \begin{scope}[scale=2] \end{scope} instead of duplicate the scale in the whole figure.
    – Sigur
    Oct 9 '18 at 16:10
  • Sounds good! Care to make that an answer?
    – kontextify
    Oct 9 '18 at 16:11
1

You can superpose two different tikzpicures if you have some reference from the first one. In this case, as you already have a image node in your first picture, just adding remember picture option to it, this image node will be available outside of it. Therefore, you can use it as reference inside the second tikzpicture.

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,fit}
\begin{document}
\begin{tikzpicture}[inner sep=0pt, outer sep=0pt, scale=2, remember picture]
  \node (image) {\includegraphics{example-image}};
  \fill [white]
    (0,1) circle [radius=1];
\end{tikzpicture}
\begin{tikzpicture}[overlay, remember picture, scale=1]
  \fill [red]
    (image) circle [radius=1];
\end{tikzpicture}
\end{document}

enter image description here

1
  • This answers the exact question in the title, although @Sigur has the better approach to my specific problem.
    – kontextify
    Oct 9 '18 at 18:44
4

You can use a single tikzpicture and put everything you want to scale inside a scope environment.

enter image description here

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,fit}
\begin{document}
\begin{tikzpicture}[inner sep=0pt, outer sep=0pt]
 \begin{scope}[scale=2]
  \node (image) {\includegraphics{example-image}};
  \fill [white] (0,1) circle [radius=1];
 \end{scope}
\fill [red] (0,0) circle [radius=1];
\end{tikzpicture}
\end{document}
3
  • Perfect. 1 hour reading docs > 1 hour fruitless trial and error > 5 minutes on SE > "OMG there are "scopes"?!
    – kontextify
    Oct 9 '18 at 18:42
  • This is the smarter way to do this, but @Ignasi has the answer to the actual question in the title. Wish I could accept both answers. :(
    – kontextify
    Oct 9 '18 at 18:43
  • @kontextify, don't worry. Feel free to choose one.
    – Sigur
    Oct 9 '18 at 19:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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