0

In a figure environment, I can use \centering to achieve this effect:

\begin{figure}
\centering
\begin{subfigure}{0.3\textwidth} A \end{subfigure}
\begin{subfigure}{0.3\textwidth} B \end{subfigure}
\begin{subfigure}{0.3\textwidth} C \end{subfigure}
\end{figure}

And they would be stacked together like this in the output

-ABC-

Where - denotes space.

Instead of centering, could we \justify?, i.e.

A-B-C

Of course I can manually do it by inserting \hspace{0.5\textwidth} between A-B and B-C, but is there something more automatic available?

I tried \justify from ragged2e which didn't work, and neither did \begin{justify}. I assume these are for text and that's why they didn't work.

  • as always justification is the default so you almost never need \justify, but the last line of a paragraph (even with \justify) is allowed to be short, you could use \end{subfigure}\hfill \begin{subfigure} between the figures – David Carlisle Apr 9 '19 at 7:21
  • The subfigures are acually left-justified by default (if you omit \centering) so that leaves space at the right. You're right about \hfill though, that did the trick. I didn't know I could use it multiple times on the same line. You could post it as an answer. – Peeyush Kushwaha Apr 9 '19 at 7:45
  • No. As I say they are subject to the standard paragraph justification but you have a one line paragraph, it is exactly the same as if you have a \parbox{\textwidth}{a b c} the paragagrah a b c is justified but as teh last line has \parfillski added and ther is only one line, it looks the same as left justified unless you set \parfillskip to 0pt or add \hfill between the letters. there is no difference between positioning subfigures and positioning letters, it is exactly the same code. – David Carlisle Apr 9 '19 at 8:44
  • Oh wow. Yes, setting \setlength\parfillskip{0pt} works. What's the best place to put it? I've put it right after begin{figure}. I think it's a neater way and you should include it in your answer to make it more complete. – Peeyush Kushwaha Apr 9 '19 at 10:02
  • That only works if the subfigures are big enough that one word space between each figure is enough stretch to make them full width. adding \hfill is far more general as that is infinite stretch. – David Carlisle Apr 9 '19 at 10:32
2

As always, justification is the default so you almost never need \justify, but the last line of a paragraph (even with \justify) is allowed to be short, you could use

\end{subfigure}\hfill \begin{subfigure}

between the figures

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.