I have a figure which has three similar subfigures and one of a different size (showing the legend of the other three). I'm having problems making the size and placing in the document look good.
This is my current code:
\begin{figure}
\begin{subfigure}[b]{0.5\textwidth}
\centering
\includegraphics[width=\textwidth,trim=3mm 4mm 50mm 2mm, clip=true]{./Data_Figures/Coeff_evolution_LS_os.pdf}
\caption{}
\end{subfigure}%
\begin{subfigure}[b]{0.5\textwidth}
\centering
\includegraphics[width=\textwidth,trim=3mm 4mm 50mm 2mm, clip=true]{./Data_Figures/Coeff_evolution_IP_p.pdf}
\caption{}
\end{subfigure}%
\\
\begin{subfigure}[b]{0.5\textwidth}
\centering
\includegraphics[width=\textwidth,trim=3mm 4mm 50mm 2mm, clip=true]{./Data_Figures/Coeff_evolution_LS_p.pdf}
\caption{}
\end{subfigure}%
\begin{subfigure}[b]{0.5\textwidth}
\centering
\includegraphics[width=\textwidth,trim=5cm 1mm 5cm 5.2cm, clip=true]{./Data_Figures/Coeff_evo_legend.pdf}
\end{subfigure}%
\end{figure}
All the figures are cropped as much as I could. This gives the following result, where the legend is too big:
But then I try e.g. changing the last figure to
\includegraphics[width=0.5\textwidth...]{...}
the spacing is off:
Nothing else I tried worked either. Any ideas?
Best Answer
With use of
\sbox{...}
you can measures the size of left images and then accommodate your image with legend to its height:Which gives (with using
example-image
fromgraphicx
package):With your real images estimating from your picture in question, the width of picture with legend is narrowed than other picture, so consequently ti will not protrude outside of text width.
If the aspect ratio of image is not essential, you can limit its width to fraction of available width, for example:
In this case the picture becomes:
Note: for positioning of images in second row the placement parameter of
subfigure
is changed from[b]
to[t]
. This would be good to do also for sub figures in the first row of picture.Addendum: Another possibility to fit image with legend is to use the following code for the last sub image:
Considering this part of code and after appropriate trimming of your original images, special one with containing legend, my MWE gives:
Frames around images are added that trimming of images is better to observe. Of course, in real use these frames had to be omitted.
Let be noted, that measurement of image heght consider whole image height (with white space around it). Consider this height the legend image become to tall, so to it is need to add a white space below it which simulate text below graph (tick labels, axis label) on the left image. I estimate, that equivalent heght is
3ex
which I add to trim values.Complete code with frames around image is:
From code you can observe, that main your problem was bad trimming of image with legend (you left and top white space in it).