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 am having difficulty with TikZ remembering node positions, or just reconciling things between different coordinate systems (such as nodes named within a given coordinate system and then refered from outside of the coordinate system), when scaling the tikzpicture.

Here's a simple standalone document that I want including in my document.

\documentclass[border=6pt]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{calc}

\pgfplotsset{every axis/.append style={
    font=\scriptsize,
    x=.75cm,
    y=.75cm,    
    axis x line=center,
    axis y line=center,
    x axis line style={<->},
    y axis line style={<->},
    xtick={-5,-4,...,5},
    ytick={-5,-4,...,5},
    xlabel={$x$},
    ylabel={$y$},
    xlabel style={below},
    ylabel style={left},
    xmin=-5.5, xmax=5.5,
    ymin=-5.5, ymax=5.5,
    }
}

\pgfmathdeclarefunction{myfncG}{1}{\pgfmathparse{ #1 + sqrt(#1^2+1)}}
\pgfmathdeclarefunction{fncLN}{1}{\pgfmathparse{ln(#1)}}

\begin{document}

\begin{tikzpicture}[>=latex]%,scale=0.75]
\begin{axis}
  \addplot[domain=-5.5:2.5, blue, samples=200,line cap=round,arrows=<->]  {myfncG(x)} node [pos=0.25,above] (g) {};
  \addplot[domain=0.025:5.5, blue, samples=200,line cap=round,arrows=<->] {fncLN(x)} node [pos=0.95,above] (ln) {};
\end{axis}
  \node at ($(g)+(0,2ex)$) {$y=x + \sqrt{x^{2}+1\,}$};
  \node[anchor=east] at ($(ln)+(0,0.5ex)$) {$y=\ln(x)$};
\end{tikzpicture}

\end{document}

which generates:

enter image description here

But in the master document, I want to rescale the image. Here's an example of how I could approach this in the master document:

\documentclass{article}
\usepackage{graphicx}

\begin{document}

This time I'm using \verb=\includegraphics=

\includegraphics[width=2in]{combined}

\end{document}

which produces:

enter image description here

But I'm not happy with the font size. So, I thought I could just rescale the standalone.
That requires just one change in the first MWE.

Change

\begin{tikzpicture}[>=latex]%,scale=0.75]

to

\begin{tikzpicture}[>=latex,scale=0.75]

Then things go all wonky on me:

enter image description here

And notice that it's not just that the nodes for my annotations that get placed improperly, but also the labels for the axes' names.

I do have a work around. I could use the following for my standalone document:

\documentclass[border=6pt]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{calc}

\pgfplotsset{every axis/.append style={
    font=\scriptsize,
    x=.75cm*0.75,%% <---- scaling HERE!
    y=.75cm*0.75,%% <---- scaling HERE!
    axis x line=center,
    axis y line=center,
    x axis line style={<->},
    y axis line style={<->},
    xtick={-5,-4,...,5},
    ytick={-5,-4,...,5},
    xlabel={$x$},
    ylabel={$y$},
    xlabel style={below},
    ylabel style={left},
    xmin=-5.5, xmax=5.5,
    ymin=-5.5, ymax=5.5,
    }
}

\pgfmathdeclarefunction{myfncG}{1}{\pgfmathparse{ #1 + sqrt(#1^2+1)}}
\pgfmathdeclarefunction{fncLN}{1}{\pgfmathparse{ln(#1)}}

\begin{document}

\begin{tikzpicture}[>=latex]%%,scale=0.75]
\begin{axis}
  \addplot[domain=-5.5:2.5, blue, samples=200,line cap=round,arrows=<->]  {myfncG(x)} node [pos=0.25,above] (g)  {};
  \addplot[domain=0.025:5.5, blue, samples=200,line cap=round,arrows=<->] {fncLN(x)}  node [pos=0.95,above] (ln) {};
\end{axis}
  \node at ($(g)+(0,2ex)$) {$y=x + \sqrt{x^{2}+1\,}$};
  \node[anchor=east] at ($(ln)+(0,0.5ex)$) {$y=\ln(x)$};
\end{tikzpicture}

\end{document}

Resulting in:

enter image description here

But it seems that this is more of a hack than a general principal I should follow. In fact, it can be a rather annoying work around when every time I want to generate coordinates and nodes with given coordinates, I've got to remember to include my scale factor:

\def\aesf{0.75}
\coordinate (A) at (3*\aesf,4*\aesf);

Additionally, I thought scale does not effect the font size. According to the TikZ manual, scale should be multiplying the coordinate by the named factor.

But in this final MWE by changing the scale, you get different scaled labels too! (I've chosen a ridiculously small scale to emphasize the effect.)

\documentclass[border=6pt]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{calc}

\pgfplotsset{every axis/.append style={
    font=\scriptsize,
    x=.75cm,
    y=.75cm,
    axis x line=center,
    axis y line=center,
    x axis line style={<->},
    y axis line style={<->},
    xtick={-5,-4,...,5},
    ytick={-5,-4,...,5},
    xlabel={$x$},
    ylabel={$y$},
    xlabel style={below},
    ylabel style={left},
    xmin=-5.5, xmax=5.5,
    ymin=-5.5, ymax=5.5,
    }
}

\pgfmathdeclarefunction{myfncG}{1}{\pgfmathparse{ #1 + sqrt(#1^2+1)}}
\pgfmathdeclarefunction{fncLN}{1}{\pgfmathparse{ln(#1)}}

\begin{document}

\begin{tikzpicture}[>=latex,scale=0.5]
\begin{axis}
  \addplot[domain=-5.5:2.5, blue, samples=200,line cap=round,arrows=<->]  {myfncG(x)} node [pos=0.25,above] (g) {\normalsize$y=x + \sqrt{x^{2}+1\,}$};
  \addplot[domain=0.025:5.5, blue, samples=200,line cap=round,arrows=<->] {fncLN(x)} node [pos=0.95,above left] (ln) {\normalsize$y=\ln(x)$};
\end{axis}
%  \node at ($(g)+(0,2ex)$) {$y=x + \sqrt{x^{2}+1\,}$};
%  \node[anchor=east] at ($(ln)+(0,0.5ex)$) {$y=\ln(x)$};
\end{tikzpicture}

\end{document}

enter image description here

Is there a better approach to this? What am I not understanding about how scale works?

share|improve this question

1 Answer 1

Scaling only the axis environment works for me:

\begin{axis}[scale=0.75]

enter image description here

If you also want to scale the distance of the label nodes with the functions you can scale the rest of the image inside a scope. May be this is not necessary because that distances depend on the fontsize.

\begin{scope}[scale=0.75]
  \node at ($(g)+(0,2ex)$) {$y=x + \sqrt{x^{2}+1\,}$};
  \node[anchor=east] at ($(ln)+(0,0.5ex)$) {$y=\ln(x)$};
\end{scope}

enter image description here

\documentclass[border=6pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{calc}

\pgfplotsset{every axis/.append style={
    font=\scriptsize,
    x=.75cm,
    y=.75cm,    
    axis x line=center,
    axis y line=center,
    x axis line style={<->},
    y axis line style={<->},
    xtick={-5,-4,...,5},
    ytick={-5,-4,...,5},
    xlabel={$x$},
    ylabel={$y$},
    xlabel style={below},
    ylabel style={left},
    xmin=-5.5, xmax=5.5,
    ymin=-5.5, ymax=5.5,
    }
}

\pgfmathdeclarefunction{myfncG}{1}{\pgfmathparse{ #1 + sqrt(#1^2+1)}}
\pgfmathdeclarefunction{fncLN}{1}{\pgfmathparse{ln(#1)}}

\begin{document}

\begin{tikzpicture}[>=latex]
\begin{axis}[scale=0.75]% scaling the axis environment
  \addplot[domain=-5.5:2.5, blue, samples=200,line cap=round,arrows=<->]  {myfncG(x)} node [pos=0.25,above] (g) {};
  \addplot[domain=0.025:5.5, blue, samples=200,line cap=round,arrows=<->] {fncLN(x)} node [pos=0.95,above] (ln) {};
\end{axis}
\begin{scope}[scale=0.75]
  \node at ($(g)+(0,2ex)$) {$y=x + \sqrt{x^{2}+1\,}$};
  \node[anchor=east] at ($(ln)+(0,0.5ex)$) {$y=\ln(x)$};
\end{scope}
\end{tikzpicture}

\end{document}

In fact you already scale the plot using x=0.75cm and y=0.75cm and it is of course possible to change this values to 0.5625cm.

The key /pgfplots/scale only rescales the unit vectors x and y after the axis scaling based on width (that is an another possibility of scaling), height, plot box Ratio, axis equal or explicit unit vectors with x, y was computed. But it does not change text labels. Note there is a difference between /pgfplots/scale and /tikz/scale.

For further details have a look at section 4.10 Scaling options in the pgfplots manual.

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.