Graphics, Figures & TablesSubfigure and legend

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
elglanto
Posts: 6
Joined: Fri Oct 05, 2012 1:05 pm

Subfigure and legend

Post by elglanto »

Hello there,

In a document i'm writting, i need sometime to put several images in the same figure. For this, i use subfigure. Here is an exemple of what i wrote for two images:

Code: Select all

\begin{figure}[htbp]
        \begin{subfigure}[b]{0.5\textwidth}
                \centering
                \includegraphics[width=\textwidth]{image1.pdf}
                \caption{Legend1}
                \label{fig:image1}
        \end{subfigure}%
        ~
        \begin{subfigure}[b]{0.5\textwidth}
                \centering
                \includegraphics[width=\textwidth]{image2.pdf}
                \caption{Legend}
                \label{fig:image2}
        \end{subfigure}
        \caption{General legend}
        \label{fig:images}
\end{figure}
It usually works quite well but i'm having some trouble when the text of Legend1 or Legend2 use more lines than the other one. Then, the two subfigures are no more aligned. Is there a way to solve this problem?

Thanks for your help and please excuse my english, i'm not a native speaker.

My packages are the folowing:

Code: Select all

\usepackage[utf8]{inputenc}
\usepackage[english,francais]{babel}
\usepackage{xspace}
\usepackage{amsmath,amsthm}
\usepackage{amsfonts}
\usepackage{graphicx}% Include figure files
\usepackage{dcolumn}% Align table columns on decimal point
\usepackage{bm}% bold math
\usepackage{caption}
\usepackage{subcaption}
\usepackage[final]{pdfpages}
Last edited by cgnieder on Fri Oct 05, 2012 1:21 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

Subfigure and legend

Post by sommerfee »

elglanto wrote:It usually works quite well but i'm having some trouble when the text of Legend1 or Legend2 use more lines than the other one. Then, the two subfigures are no more aligned. Is there a way to solve this problem?
What alignment do you want to have? If you want to have an alignment to the top of the subfigures, don't use but [t] instead. If you want to have an alignment to the very first caption/legend line, don't use the subfigure environment at all but the \subcaptionbox command instead.
elglanto
Posts: 6
Joined: Fri Oct 05, 2012 1:05 pm

Subfigure and legend

Post by elglanto »

sommerfee wrote:What alignment do you want to have? If you want to have an alignment to the top of the subfigures, don't use but [t] instead. If you want to have an alignment to the very first caption/legend line, don't use the subfigure environment at all but the \subcaptionbox command instead.


Thanks, the work perfectly. But just for my knowledge, how should i use \subcaptionbox?
User avatar
sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

Subfigure and legend

Post by sommerfee »

elglanto wrote:But just for my knowledge, how should i use \subcaptionbox?
Just as stated in the subcaption package documentation, e.g.:

Code: Select all

\subcaptionbox{Legend1\label{fig:image1}}
  {\includegraphics[width=0.5\textwidth]{image1.pdf}}
Post Reply