3

I'm trying to use the subfigure environment to generate side-by-side images with captions, however because the images are different heights the captions come out at different heights. Also, they come out with absolutely no space between them, which in my view makes them unreadable. Is there a straightforward way to fix this?

Two really ugly captions

The code I'm using to generate these subfigures/captions is

\documentclass[a4paper,12pt,oneside]{report}
\usepackage[inline]{asymptote}
\usepackage{caption}
\usepackage{subcaption}

\makeatletter
\g@addto@macro\@floatboxreset\centering
\makeatother

\begin{document}
\begin{figure}[h!tb]
    \begin{subfigure}{.5\textwidth}
    \raggedright
    \begin{asy}
        picture pic; 
        path p1 = (-1, 0)--(-1, 1)--(-0.5, 1.5)--(0, 2)--(.5, .7)--(0, .7)--(.5, .5)--(.5, 0)--(-1, 0);
        draw(pic, p1); 
        draw(pic, (-1, 0)--(-1, 2)--(0.5, 2)--(0.5, 0)--(-1, 0), red+dashed);


          path p2 = shift(1, -0.5)*((-1, 0.5)--(-0.5, 1)--(0.5, 1)--(1, 0.5)--(1, -0.5)--(0.5, -1)--(-0.5, -1)--(-1, -0.5)--(-1, 0.5));
          draw(pic, p2); 
          draw(pic, shift(1, -0.5)*((-1, -1)--(-1, 1)--(1, 1)--(1, -1)--(-1, -1)), purple+dashed);

          add(scale(50)*pic);
      \end{asy}
      \caption{Two polygons that intersect, along with intersecting bounding
      rectangles}
  \end{subfigure}%
  \begin{subfigure}{.5\textwidth}
      \raggedleft
      \begin{asy}
          picture pic; 
          path p1 = (-1, 0)--(-1, 1)--(-0.5, 1.5)--(0, 2)--(.5, .7)--(0, .7)--(.5, .5)--(.5, 0)--(-1, 0);
          draw(pic, shift(1)*p1);
          draw(pic, shift(1)*((-1, 0)--(-1, 2)--(0.5, 2)--(0.5, 0)--(-1, 0)), blue+dashed);

          path p2 = shift(-0.8, 1.8)*((-1, 0.5)--(-0.5, 1)--(0.5, 1)--(1, 0.5)--(1, -0.5)--(0.5, -1)--(-0.5, -1)--(-1, -0.5)--(-1, 0.5));
          draw(pic, p2);
          draw(pic, shift(-0.8, 1.8)*((-1, -1)--(-1, 1)--(1, 1)--(1, -1)--(-1, -1)), green+dashed);

          add(scale(50)*pic);
      \end{asy}
      \caption{Two polygons that do not intersect but with intersecting
      bounding rectangles}
  \end{subfigure}
  \caption{The representation of some polygons and their minimum bounding
  rectangles.}
\end{figure}
\end{document}
3

Changing the lines

\begin{subfigure}{.5\textwidth}

to

\begin{subfigure}[b]{.5\textwidth}

and adding

\usepackage[margin=1cm]{subcaption}

to the start of the file should fix both issues.

2
  • 2
    Note that selecting the option margin=<width> will insert <width> to the left of the left-hand subfigure, <width> to the right of the right-hand subfigure, and 2<width> between the subfigures. If you'd rather have only separation between the subfigures and none at the margins, set the subfigure widths to something like 0.48\textwidth and insert the instruction \hspace*{\fill} between the two subfigure environments.
    – Mico
    Oct 26 '13 at 8:17
  • Welcome to TeX.SX. A tip: If you indent lines by 4 spaces, then they're marked as a code sample. You can also highlight the code and click the "code" button ({}) or hit Ctrl+K. Oct 26 '13 at 8:23

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.