Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to join a node inside a pgfplots axis to a node belonging to a different tikzpicture. I can do this with an overlay from inside the axis. However, if I scale the tikzpicture that encloses the axis, the overlay breaks.

For example, the following works fine:

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}[remember picture]
    \node (n1) {n1};
\end{tikzpicture}

\begin{tikzpicture}[remember picture] 
%\begin{tikzpicture}[remember picture, scale=0.85, transform shape]
    \node (n2) {n2};
    \draw[overlay, green] (n1) -- (n2);
    \begin{axis}[right of=n2, name=plot, clip=false]
    \addplot coordinates {(0,0) (2,3) (4,2)};
    \draw[overlay, red] (n1.east) -- (axis cs:2,3);
    \end{axis}
\end{tikzpicture}
\end{document}

When I add a scale parameter (e.g. scale=0.85 with transform shape) to the tikzpicture outside the axis (and run pdflatex twice), the red line no longer starts from the node (n1):

without scale with scale

Everything works fine if the scale is a parameter of the axis, but I would like to scale the whole tikzpicture. Is there a way to make this work correctly?

share|improve this question
    
When you supply the scale parameter to the axis, only the plot dimensions, but not the text labels will be scaled, and the number of tick labels may be different. The behaviour is basically as if you had supplied different values for width and height. Is that what you want, or do you actually want to scale the plot, text and all? –  Jake May 22 '12 at 11:45
    
@Jake Sorry for not being clear enough, I would like to scale the whole picture, including the text. I usually scale down my diagrams in beamer a bit and would like to use this to annotate them from the text in the enclosing frame. –  anton May 22 '12 at 14:45

1 Answer 1

As seen in the picture on the right, the vector magnitude is shrunk down by the scaling factor 0.85 compared to the original length. Hence we can deduce that the scaling is applied after the required calculations. It's not the best choice but one can supply the scaling to the required keys manually as follows

\documentclass{beamer}
\usepackage{tikz}
\usepackage{pgfplots}
\def\myscale{0.4}
\tikzset{myscalar/.style={
    node distance=\myscale cm and \myscale cm,
    every node/.style={scale=\myscale},
    every axis/.style={
        major tick length=0.15*\myscale cm,
        minor tick length=0.1*\myscale cm,
        mark options={scale=\myscale},
        scale=\myscale
        }
    }
}
\begin{document}
\begin{frame}{Title}
\begin{tikzpicture}[remember picture]
    \node (n1) {n1};
\end{tikzpicture}


\begin{tikzpicture}[remember picture,transform shape,myscalar]
    \node (n2) {n2};
    \draw[overlay, green] (n1) -- (n2);
    \begin{axis}[right of=n2, name=plot, clip=false]
    \addplot coordinates {(0,0) (2,3) (4,2)};
    \draw[overlay, red] (n1.east) -- (axis cs:2,3);
    \end{axis}
\end{tikzpicture}
\end{frame}
\end{document}

enter image description here

One can change \myscale by re\defining it after some point.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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