I am trying to align 4 graphs in a paper. Previous searching led my to the master/slave trick (see code below). Compiling the code as it is gives the desired result, but if I comment the "\hspace{-.35cm}" where I put a "% HERE !!!!!" comment, then the graphs are no more aligned. I obtained the .35cm by trial and error, but I would like a clean solution. Is there any way to do so?
\documentclass[12pt]{article}
\usepackage[margin=1in, a4paper, pdftex]{geometry}
\usepackage{pgfplots}
\tikzset{
master/.style={
execute at end picture={
\coordinate (lower right) at (current bounding box.south east);
\coordinate (upper left) at (current bounding box.north west);
}
},
slave/.style={
execute at end picture={
\pgfresetboundingbox
\path (upper left) rectangle (lower right);
}
}
}
\begin{document}
\begin{figure}%Fig1
\begin{center}
FIGURE
\begin{tikzpicture}[master]
\begin{axis}[
width=2.1in, height=2in,
ymin=122, ymax=150, ylabel={y label 1},
name=plot1,
title={First title}
]
\addplot [color=blue, mark size=3.5pt, only marks, mark=square*, mark options={solid,draw=blue}]
table[row sep=crcr]{
0.25 127.29\\
0.5 145.68\\
};
\end{axis}
\begin{axis}[
width=2.1in, height=2in,
xmin=0, xmax=0.5,
ymin=166, ymax=190, ylabel={y label 2},
at=(plot1.right of south east),
anchor=left of south west,
title={Second title},
]
\addplot [color=blue, solid, dashed, ultra thick]
table[row sep=crcr]{
0.02 170\\
0.5 180\\
};
\end{axis}
\end{tikzpicture}%
\title{\textit{Graph B}}
\begin{tikzpicture}[slave]
\begin{axis}[
width=2.1in, height=2in,
xmin=60, xmax=200, xlabel={x label},
ymin=-0.08, ymax=0.04, name=plot1,
ylabel={y label 3},
title={3rd title },
title style={yshift=1ex}
]
\addplot [
color=blue, solid, ultra thick, forget plot, smooth]
table[row sep=crcr]{
60 -1e-5\\
200 1e-4\\
};
\end{axis}
\hspace{-.35cm} % HERE !!!!!
\begin{axis}[
width=2.1in, height=2in,
xmin=60, xmax=200, xlabel={x label},
ylabel={y label 4},
at=(plot1.right of south east),
anchor=left of south west,
title={4th title}
]
\addplot [color=blue, solid, ultra thick, forget plot, smooth]
table[row sep=crcr]{
60 -2.5e-5\\
200 0.0001\\
};
\end{axis}
\end{tikzpicture}
\end{center}
\end{figure}%Fig1
\end{document}