I would like to align two plots containing legends on their outside:
\documentclass[a4paper]{article}
\usepackage{tikz}
\usepackage{tikzscale}
\usepackage{subcaption}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\begin{document}
\begin{figure}
\begin{centering}
\begin{subfigure}[t]{0.4\textwidth}
\vskip 0pt
\includegraphics[width=\textwidth]{plot1.tikz}
\end{subfigure}
~
\begin{subfigure}[t]{0.4\textwidth}
\vskip 0pt
\includegraphics[width=\textwidth]{plot2.tikz}
\end{subfigure}
\end{centering}
\end{figure}
\end{document}
Specifically, the two plot files contain the following:
% plot1.tikz
\begin{tikzpicture}
\begin{axis}[
legend entries={Short caption},
legend style = {at = {(0.5, -0.3)}, anchor = north},
width=\textwidth,
height=\textwidth]
\addplot[color=red,mark=x] coordinates {
(2,-2.8559703)
(8,-7.9377747) };
\end{axis}
\end{tikzpicture}
% plot2.tikz
\begin{tikzpicture}
\begin{axis}[
legend entries={Long long long long long long caption},
legend style = {at = {(0.5, -0.3)}, anchor = north},
width=\textwidth,
height=\textwidth]
\addplot[color=red,mark=x] coordinates {
(2,-2.8559703)
(8,-7.9377747) };
\end{axis}
\end{tikzpicture}
Unfortunately, the width of the caption of the second plot dominates the width of the plot itself. Therefore, the plot is shrunk and the sizes don't match up anymore:
I would like the layout of the legend to break this long line and to maintain a fixed width. How can I achieve that effect?
Is there a way to do so?