2

When I scale my \includestandalone[width=...], my remembered coordinate (A) is not at the right position anymore. How can I fix that?

A.tex: a standalone tikz that defines the coordinate (A) at the center

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[remember picture]
      \node at (0,0) {\includegraphics{example-image-a}};
      \node (A) at (0,0) {A};
    \end{tikzpicture}
\end{document}

Main.tex: include the standalone and draw a circle at (A)

\documentclass{book}
\usepackage{standalone}
\usepackage{tikz}
\begin{document}
  \includestandalone[width=5cm]{A}
  \begin{tikzpicture}[remember picture,overlay]
      \draw[red] (A) circle(1);
  \end{tikzpicture}
\end{document}

The circle is not centered on (A)! enter image description here

How to keep the circle centred on (A), even if the standalone is scaled?

1 Answer 1

1

The example works if the option [width=5cm] is given to \includegraphics in the file A.tex instead of \includestandalone in the file Main.tex.

According to the pgfmanual, the syntax \draw[red] (A) circle(1); is old. The newer syntax is \draw[red] (A) circle [radius=1];.

enter image description here

File A.tex

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[remember picture]
      \node at (0,0) {\includegraphics[width=5cm]{example-image-a}};
      \node (A) at (0,0) {A};
    \end{tikzpicture}
\end{document}

File Main.tex

\documentclass{book}
\usepackage{standalone}
\usepackage{tikz}
\begin{document}
  \includestandalone{A}
  \begin{tikzpicture}[remember picture,overlay]
      \draw[red] (A) circle [radius=1];
  \end{tikzpicture}
\end{document}
4
  • Ok. Thanks for the answer (and the syntax advise :-). This already an excellent solution, but ... the idea is to externalise the tikz to re-use it in a beamer doc. I am not sure that setting the dimension in the standalone will suit all my use cases. Jan 16 at 12:30
  • I would love to get @MartinScharrer's reaction on this ... Jan 16 at 20:47
  • @JosephMarie The width can be defined depending on whether externalization is used. For example width=\mywidth where \mywidth can be defined in the preamble. Jan 18 at 18:06
  • Of course, this is a way. But to be honest, I won't push this style of making my standalone code dependant of a 'global' variable. Jan 28 at 10:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .