1

I like to use tikz nodes to position plots next to each other. However in the following MWE the axis seem to be shifted to the left.

\documentclass{book}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
    \node[text width=.4\linewidth] (A) {%
            \begin{tikzpicture}
            \begin{axis}
            \addplot {x^2 - x +4};                  
            \end{axis}
            \end{tikzpicture}
    };

    \node[text width=.4\linewidth,anchor = north] (B) at (A.south) {%   
            \begin{tikzpicture}
            \begin{axis}
            \addplot {x^2 - x +4};                  
            \end{axis}
            \end{tikzpicture}
    };  
\end{tikzpicture}
\end{document}

enter image description here

How can I fix this?

  • Is there any reason why you need text width=.4\linewidth ? Because if I remove it, the plots look fine. – Benjamin Feb 17 '16 at 11:38
  • I scaled the plots this way, but at the moment I cannot think about a reason why I should not do this directly at the axis. If you provide an answer, I can mark it as correct. – Manuel Schmidt Feb 17 '16 at 11:41
1

The key text width=.4\linewidth is inherited by yticklabel style and xticklabel style. That is why the tick labels appear shifted. Removing the unnecessary key from the nodes fixes this issue.

pgfplots

| improve this answer | |
1

Every tikzpicture is considered like a single char and you don't need to include them in external tikzpictures to place them, you could use simple tabluar or just an empty line like in following example.

If you need to fix plot dimensions, width and height axis' will also help you.

\documentclass{book}
\usepackage{pgfplots}

\begin{document}

\begin{center}
            \begin{tikzpicture}
            \begin{axis}[width=.4\linewidth]
            \addplot {x^2 - x +4};                  
            \end{axis}
            \end{tikzpicture}

            \begin{tikzpicture}
            \begin{axis}[width=.4\linewidth]
            \addplot {x^2 - x +4};                  
            \end{axis}
            \end{tikzpicture}
\end{center}
\end{document}

enter image description here

| improve this answer | |

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.