2

I have two plots with tikzpicture above each other. (they have quite difficult text files as source, so I can not show them here).

The plots have the same width, the problem is that the legend is different in size --> One plot is more to the left than the other)

What Can I do, to align them vertically?

Thank You very much !!

Kate
  • 173
  • How about a MWE? – subham soni Jul 12 '14 at 09:09
  • That is too complicated - sorry. – Kate Jul 12 '14 at 09:16
  • I basically need an alignment to the left side. =( – Kate Jul 12 '14 at 09:22
  • @Kate you could still make a MWE, the original tikz isn't relevant presumably you could just draw a square to illustrate your problem. It isn't clear how you are adding legends or aligning your plots. All latex boxes align to the left by default unless you do something special like \centering so without more detail it's hard to say anything about your question. – David Carlisle Jul 12 '14 at 09:31

1 Answers1

5

The following suggestions only work if you center both pictures.

You can use the option trim axis left (or maybe trim axis right) for both tikzpictures:

\begin{tikzpicture}[trim axis left]

enter image description here

Code:

\documentclass{scrartcl} 
\usepackage{pgfplots}
\pgfplotsset{width=8cm,height=6cm}

\begin{document}
\begin{center}
  \begin{tikzpicture}[trim axis left]
    \begin{axis}[no marks]
      \addplot {x};
    \end{axis}
  \end{tikzpicture}
  \captionof{figure}{Fugue 1}
  \vspace{2\baselineskip}
  \begin{tikzpicture}[trim axis left]
    \begin{axis}[ylabel = {$y(x)$},no marks]
      \addplot {2*x};
    \end{axis}
  \end{tikzpicture}
  \captionof{figure}{Figure 2}
\end{center}
\end{document}

Another possibility is the use of \pgfresetboundingbox and afterwards \useasboundingbox

\documentclass{scrartcl} 
\usepackage{pgfplots}
\pgfplotsset{width=8cm,height=6cm}

\newcommand\myBoundingBox{
  \pgfresetboundingbox
  \path(current axis.below south west)rectangle (current axis.above north east);
}

\begin{document}
\begin{center}
  \begin{tikzpicture}
    \begin{axis}[no marks]
      \addplot {x};
    \end{axis}
    \myBoundingBox
  \end{tikzpicture}
  \captionof{figure}{Fugue 1}
  \vspace{2\baselineskip}
  \begin{tikzpicture}
    \begin{axis}[ylabel = {$y(x)$},no marks]
      \addplot {2*x};
    \end{axis}
    \myBoundingBox
  \end{tikzpicture}
  \captionof{figure}{Figure 2}
\end{center}
\end{document}

Or you can use the environment pgfinterruptboundingbox for the axis and afterwards \useasboundingbox

...
\begin{pgfinterruptboundingbox}
  \begin{axis}[...
    ...
  \end{axis}
\end{pgfinterruptboundingbox}
\useasboundingbox(current axis.below south west)rectangle (current axis.above north east);
...
esdd
  • 85,675