[Tex/LaTex] How to justify subfig subfloats

floatshorizontal alignmentsubfloats

I have three subfloats and I want them to be aligned over the full \textwidth, no matter what the sizes are (smaller than a third of the page of course).

I have the following setup:

\begin{figure} %
    \centering
    \subfloat[subcaption 1]{%
    \includegraphics[width=0.2\textwidth]{image1}} %
    %
    \subfloat[subcaption 2]{%
    \includegraphics[width=0.2\textwidth]{image2}} %
    %
    \subfloat[subcaption 3]{%
    \includegraphics[width=0.2\textwidth]{image3}} %

    \caption{%
    \label{fig:trans_actions} %
    Some caption text here. This is the full textwidth.}
\end{figure}

How do I get the images justified over the full width of the text?

Best Answer

Just add \hfill to spread out the figures, which adds a rubber length that is allowed to stretch and shrink horizontally as needed.

The [showframe] option for the geometry pacakge was used to show the placement of the figures and the margins.

enter image description here

\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage[demo]{graphicx}% Remove demo option in real document
\usepackage{caption}
\usepackage{subfig}

\begin{document}
\begin{figure}
    \centering
    \subfloat[subcaption 1]{\includegraphics[width=0.2\textwidth]{image1}}
    \hfill
    \subfloat[subcaption 2]{\includegraphics[width=0.2\textwidth]{image2}}
    \hfill
    \subfloat[subcaption 3]{\includegraphics[width=0.2\textwidth]{image3}}
    \caption{\label{fig:trans_actions}
    Some caption text here. This is the full textwidth.}
\end{figure}
\end{document} 

As Werner pointed out, the above solution aligns the edges of the figures with the margins. If you also want spacing between the figures and margins as well you add \null\hfill on the left, and \hfill\null on the right.

enter image description here

\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage[demo]{graphicx}% Remove demo option in real document
\usepackage{caption}
\usepackage{subfig}

\begin{document}
\begin{figure}
    \centering
    \null\hfill
    \subfloat[subcaption 1]{\includegraphics[width=0.2\textwidth]{image1}}
    \hfill
    \subfloat[subcaption 2]{\includegraphics[width=0.2\textwidth]{image2}}
    \hfill
    \subfloat[subcaption 3]{\includegraphics[width=0.2\textwidth]{image3}}
    \hfill\null
    \caption{\label{fig:trans_actions}
    Some caption text here. This is the full textwidth.}
\end{figure}
\end{document}