12 Comments

  1. Anja

    Thank you, this is indeed very useful!

    I only have one question:

    What should I adjust if I have 3×2 subfigures?

    I followed your suggestion with adding an empty line after the third subfigure but I end up with 2 colums and 4 lines instead of 3 colums and 2 lines.

    • tom

      Hi Anja,

      Thanks for your question. The code below produces three columns. The trick is to split the line width into three equal parts instead of assigning a fixed width.

      Best, Tom

      \documentclass[varwidth, border=10pt]{standalone}
      \usepackage{subcaption}
      \usepackage[labelformat=parens,labelsep=quad,skip=3pt]{caption}
      \usepackage{graphicx}
      
      \begin{document}
      \begin{figure}
        \begin{subfigure}[b]{0.3\linewidth}
          \centering\rule{1cm}{1cm}
          \caption{Caption text 1}
        \end{subfigure}\hfill
        \begin{subfigure}[b]{0.3\linewidth}
          \centering\rule{1cm}{1cm}
          \caption{Caption text 2}
        \end{subfigure}\hfill
        \begin{subfigure}[b]{0.3\linewidth}
          \centering\rule{1cm}{1cm}
          \caption{Caption text 3}
        \end{subfigure}
        
          \begin{subfigure}[b]{0.3\linewidth}
            \centering\rule{1cm}{1cm}
          \caption{Caption text 4}
        \end{subfigure}\hfill
         \begin{subfigure}[b]{0.3\linewidth}
          \centering\rule{1cm}{1cm}
          \caption{Caption text 5}
        \end{subfigure}\hfill
        \begin{subfigure}[b]{0.3\linewidth}
          \centering\rule{1cm}{1cm}
          \caption{Caption text 6}
        \end{subfigure}
      \end{figure}
      \end{document}
    • Hi Frank,

      Thanks for your feedback. The code above works for me. The error you see typically arises if you place a floating environment (e.g. figure, table) within a non floating environment (e.g. minipage). If that doesn’t help, please provide a minimal working example for me to reproduce the error.

      Best, Tom

  2. Hoan

    Hi, thanks a lot.
    I did as your instruction and it worked. But when I tried to label each sub figure and referenced it did not work (I want it appears 1a 1b 1c…). Do you have any suggestions?

    • Hi Hoan,

      Thanks for your feedback. You are right, the labels are missing in the example above. Please take a look at the examples on my figures code snippet page. There, the labels are set correctly and it shows how to reference the figures. Use either \ref or \subref depending on if you want to get the full label or only the sub-label.

      HTH, Tom

  3. Fossil Plants

    THANKS!!!! This saved me a bunch of time! I ended up using the pdfcrop technique, as it is much simpler to pull out a page with a figure and crop it, then to make the new fig in latex.

Leave a Reply to HoanCancel reply