4

I want three subfigures to be shown next to each other so that the subcaptions of all three subfigures are equally 'wide'. I'm experiencing 2 problems.

  1. Since my middle subfigure is a lot smaller, the subcaption of this figure is stretched out vertically. I want all the subcaptions, however, to have the same width.

  2. Since the sizes of the images differ, the images are displayed very strangely. I would like the two outer ones to start at the same height and the middle one to be centered (same distance above and under the image as well as at the sides, relative to the outer images).

I've already been playing with \hspace, \vspace, and \hfill, but this seems to have no effect. The output result I keep obtaining:

Output result of my three subfigures

My code

\documentclass[master=elt,masteroption=eg]{kulemt}
\usepackage{color}
\usepackage{amsmath,amsfonts,amssymb}
  \everymath{\displaystyle}
  \numberwithin{equation}{section}     
\usepackage{graphicx}
  \graphicspath{{./Images/}}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{natbib}
  \bibpunct{[}{]}{;}{a}{,}{,}

\begin{document}
\begin{figure}
  \centering
  \begin{subfigure}[b]{0.3\textwidth}
    \vspace{0.05\textheight}
    \includegraphics[width=\textwidth]{OriginalImage}
    \caption{An original set of pixels making up an object}
    \label{OriginalImage}
  \end{subfigure}%
    ~ %add desired spacing between images, e. g. ~, \quad, \qquad etc.
      %(or a blank line to force the subfigure onto a new line)
  \begin{subfigure}[b]{0.1\textwidth}
    \vspace{0.08\textheight}
    \hspace{0.2\textwidth}
    \includegraphics[width=\textwidth]{StructuringElement}
    \caption{The structuring element used for the closing}
    \label{StructuringElement}
    \hspace{0.2\textwidth}
  \end{subfigure}
    ~ %add desired spacing between images, e. g. ~, \quad, \qquad etc.
      %(or a blank line to force the subfigure onto a new line)
  \begin{subfigure}[b]{0.3\textwidth}
    \vspace{0.05\textheight}
    \includegraphics[width=\textwidth]{ClosedImage}
    \caption{The closed image}
    \label{ClosedImage}
  \end{subfigure}
  \caption{The closing of an object}\label{Closing}
\end{figure}
\end{document}
  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – karlkoeller Apr 10 '14 at 10:24
4

I changed to class article so that I could work with it. One of the primary things was to change the width of all three subfigures to be the same. Also, subfigures were invoked with top, not bottom, alignment. Once that was done, the middle figure's width/height, when expressed as a fraction of \textwidth, had to be changed (I also used \hfil and \hfill to center it). Finally, a \raisebox was needed to raise the middle figure.

\documentclass[master=elt,masteroption=eg]{article}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{color}
\everymath{\displaystyle}
\numberwithin{equation}{section}
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\graphicspath{{./Images/}}
\usepackage{natbib}
\bibpunct{[}{]}{;}{a}{,}{,}
\begin{document}
\begin{figure}
        \centering
        \begin{subfigure}[t]{0.3\textwidth}
                  \includegraphics[width=\textwidth,height=\textwidth]{OriginalImage}
                \caption{An original set of pixels making up an object}
                \label{OriginalImage}
        \end{subfigure}%
        ~ %add desired spacing between images, e. g. ~, \quad, \qquad etc.
          %(or a blank line to force the subfigure onto a new line)
        \begin{subfigure}[t]{0.3\textwidth}
                \hfil
                \raisebox{.3333\textwidth}{%
                  \includegraphics[width=.3333\textwidth,height=.3333\textwidth]{StructuringElement}%
                }
                \caption{The structuring element used for the closing}
                \label{StructuringElement}
                \hfill
        \end{subfigure}%
        ~ %add desired spacing between images, e. g. ~, \quad, \qquad etc.
          %(or a blank line to force the subfigure onto a new line)
        \begin{subfigure}[t]{0.3\textwidth}
                \includegraphics[width=\textwidth,height=\textwidth]{ClosedImage}
                \caption{The closed image}
                \label{ClosedImage}
        \end{subfigure}
        \caption{The closing of an object}\label{Closing}
\end{figure}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.