0

I would like to reduce the space between two figure that are side by side. I am using the following code but I don't know how to do that.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{caption}


\begin{document}



\begin{figure}
  \begin{subfigure}[tbp]{0.3\textwidth}
    \includegraphics[width=\textwidth]{img1}
    \caption{traditional.}
     \label{fig:atzeni_trad}
  \end{subfigure}
  %
  \begin{subfigure}[tbp]{0.4\textwidth}
    \includegraphics[width=\textwidth]{img2}
    \caption{SLS}
    \label{fig:atzeni_sls}
  \end{subfigure}
  \caption[.]{Fluoriscent lamp holder. Traditional on left-side, CAD redesigned centered, and SLS manufactured on right-side}
  \label{fig:lamp}
\end{figure}


\end{document}

Moreover, do you know how to have the caption of each of the figure at the same hight?

  • The optional argument to the subfigure environment can either t, c, or b, not a combination of them. There shouldn't be more than a normal interword space between them I believe, if you see more than that it is because there is whitespace in the images themselves, and cropping is in order. – Torbjørn T. Sep 29 '16 at 14:43
3

A negative \hskip in between reduces the space. Shifting from [tbp] to [b] aligns the subfigures entirely at their bottoms, including aligning the captions at the bottom. But this also aligns the images at their bottoms; I don't know if you mind this or not.

Here's the modified source; you can change -2ex to whatever distance you want.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{caption}

\begin{document}

\begin{figure}
  \begin{subfigure}[b]{0.3\textwidth}
    \includegraphics[width=\textwidth]{img1}
    \caption{traditional.}
    \label{fig:atzeni_trad}
  \end{subfigure}
  \hskip -2ex
  \begin{subfigure}[b]{0.4\textwidth}
    \includegraphics[width=\textwidth]{img2}
    \caption{SLS}
    \label{fig:atzeni_sls}
  \end{subfigure}
  \caption[.]{Fluoriscent lamp holder. Traditional on left-side, CAD redesigned centered, and SLS manufactured on right-side}
  \label{fig:lamp}
\end{figure}

\end{document}

If you want to align captions without aligning the pictures, I think you want \subcaptionbox. Here's an example:

\begin{figure}    
    \subcaptionbox{traditional.\label{fig:atzeni_trad}}[0.3\textwidth]{\includegraphics[width=0.3\textwidth]{img1}}
    \hskip -2ex
    \subcaptionbox{SLS\label{fig:atzeni_sls}}[0.4\textwidth]{\vspace*{3em}\includegraphics[width=0.4\textwidth]{img2}}
    \caption[.]{Fluoriscent lamp holder. Traditional on left-side, CAD redesigned centered, and SLS manufactured on right-side}
    \label{fig:lamp}
\end{figure}

In this case, I've moved the second image up with \vspace*{}, but of course you can move it however you prefer. Note as well that \textwidth is not redefined inside a subcaptionbox, so the width argument to \includegraphics has changed.

  • Yes fantastic! but what if I want to have the two figure in a precise location that is not the bottom? then how do I align the subcaption? – Alexis Charalambis Sep 29 '16 at 14:34
  • Then I think what you want is \subcaptionbox. I'll edit my answer to give an example. – Dave Ripley Sep 29 '16 at 14:46

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.