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

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
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