I want to place 3 pictures next to each other using subcaption. The two right pictures are external graphics files that I include using \includegraphics. The left one is supposed to be a pgfplots chart. Naturally, I want them and the captions to align vertically. To achieve set I use a common height for all three pictures which is defined in \figheight. As a dry run, everything seems to work with example-image-a, etc:
However, when I replace the left figure by a pgfplot and specify its exact height to the height of the external figures right next, the result is somehow curious:
Why is the height not exactly the value of \figheight? Is there a difference between the height of the axis environment and the height of the tikzpicture? From the manual:
If scale only axis=false (the default), pgfplots will try to produce the desired width including labels, titles and ticks.
I guess the same holds for the height?! How can I fix this for a proper alignment of the pictures as well as the subcaptions?
MWE
\documentclass{article}
\usepackage{graphicx}
\usepackage{pgfplots}
\usepackage{subcaption}
\pgfplotsset{compat=newest}
\newlength{\figheight}
\setlength{\figheight}{5cm}
\begin{document}
Works:
\begin{figure}[htbp]
\begin{subfigure}{0.65\linewidth}
\centering
\includegraphics[width=\linewidth,height=\figheight]{example-image-a}
\caption{Test1}
\end{subfigure}
\hfill
\begin{subfigure}{0.16\linewidth}
\centering
\includegraphics[angle=90,width=\linewidth,height=\figheight]{example-image-b}
\caption{Test2}
\end{subfigure}
\hfill
\begin{subfigure}{0.16\linewidth}
\centering
\includegraphics[angle=90,width=\linewidth,height=\figheight]{example-image-c}
\caption{Test3}
\end{subfigure}
\caption{Overall caption}
\end{figure}
Weird size and resulting caption position:
\begin{figure}[htbp]
\begin{subfigure}{0.65\linewidth}
\centering
\begin{tikzpicture}
\begin{axis}[
width=\linewidth,
height=\figheight,
]
\addplot+ {x};
\addlegendentry{$f(x)=x$}
\end{axis}
\end{tikzpicture}
\caption{Test1}
\end{subfigure}
\hfill
\begin{subfigure}{0.16\linewidth}
\centering
\includegraphics[angle=90,width=\linewidth,height=\figheight]{example-image-b}
\caption{Test2}
\end{subfigure}
\hfill
\begin{subfigure}{0.16\linewidth}
\centering
\includegraphics[angle=90,width=\linewidth,height=\figheight]{example-image-c}
\caption{Test3}
\end{subfigure}
\caption{Overall caption}
\end{figure}
\end{document}






