Placement of images in row using subfigure
Since all four subfigure
s must appear on one row, the total width for the subfigure
s must not exceed \textwidth
; you could use .25\textwidth
(at most, if they all have to have the same width) for each subfigure
and make sure there's no spurious blank spaces between them (notice the %
characters after the three first \end{subfigure}
lines).
Below you find two possibilities using the maximum width for each subfigure
; in the first case, the width of the image equals the width of its container (and the images will appear without space in between); in the second case, the width of each image is a little smaller than the width of the container, so there's some air between the images.
Notice that in the first case, the subfigure
s are taken all the available width and each image takes all the available width inside its container too, so there's no need to use \centering
there.
\documentclass[12pt,twoside]{report}% Use this line for the print version of the thesis
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\begin{document}
\begin{figure}
\begin{subfigure}[b]{0.25\textwidth}
\includegraphics[width=\linewidth]{example-image-a}
\caption{A gull}
\label{fig:gull}
\end{subfigure}%
\begin{subfigure}[b]{0.25\textwidth}
\includegraphics[width=\linewidth]{example-image-a}
\caption{A gull2}
\label{fig:gull2}
\end{subfigure}%
\begin{subfigure}[b]{0.25\textwidth}
\includegraphics[width=\linewidth]{example-image-a}
\caption{A tiger}
\label{fig:tiger}
\end{subfigure}%
\begin{subfigure}[b]{0.25\textwidth}
\includegraphics[width=\linewidth]{example-image-a}
\caption{A mouse}
\label{fig:mouse}
\end{subfigure}
\caption{Pictures of animals}\label{fig:animals}
\end{figure}
\begin{figure}
\begin{subfigure}[b]{0.25\textwidth}
\centering
\includegraphics[width=.85\linewidth]{example-image-a}
\caption{A gull}
\label{fig:gull}
\end{subfigure}%
\begin{subfigure}[b]{0.25\textwidth}
\centering
\includegraphics[width=.85\linewidth]{example-image-a}
\caption{A gull2}
\label{fig:gull2}
\end{subfigure}%
\begin{subfigure}[b]{0.25\textwidth}
\centering
\includegraphics[width=.85\linewidth]{example-image-a}
\caption{A tiger}
\label{fig:tiger}
\end{subfigure}%
\begin{subfigure}[b]{0.25\textwidth}
\centering
\includegraphics[width=.85\linewidth]{example-image-a}
\caption{A mouse}
\label{fig:mouse}
\end{subfigure}
\caption{Pictures of animals}\label{fig:animals}
\end{figure}
\end{document}
Of course, you don't have to give each subfigure
a width of .25\textwidth
; you can use a smaller value (in this case, \centering will be needed) and you can use some space, (an explicit space, or \quad
, or, even better, \hfill
) to separate your figures:
\documentclass[12pt,twoside]{report}% Use this line for the print version of the thesis
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\begin{document}
\begin{figure}
\centering
\begin{subfigure}[b]{0.22\textwidth}
\centering
\includegraphics[width=\linewidth]{example-image-a}
\caption{A gull}
\label{fig:gull}
\end{subfigure}\hfill
\begin{subfigure}[b]{0.22\textwidth}
\centering
\includegraphics[width=\linewidth]{example-image-a}
\caption{A gull2}
\label{fig:gull2}
\end{subfigure}\hfill
\begin{subfigure}[b]{0.22\textwidth}
\centering
\includegraphics[width=\linewidth]{example-image-a}
\caption{A tiger}
\label{fig:tiger}
\end{subfigure}\hfill
\begin{subfigure}[b]{0.22\textwidth}
\centering
\includegraphics[width=\linewidth]{example-image-a}
\caption{A mouse}
\label{fig:mouse}
\end{subfigure}
\caption{Pictures of animals}\label{fig:animals}
\end{figure}
\end{document}
The first thing you should note that your total width, 0.3\textwidth
X 4 1.2\textwidth
is more than \textwidth
. So, it would be physically impossible to accommodate the images in one row.
Moreover, even if you reduce the widths to some value like 0.2\textwidth
, still they fail to appear in a row. This is due the carriage returns you have inserted between images.
So, taking in to account all the above issues, your code becomes,
\begin{figure}
\centering
\begin{subfigure}[b]{0.20\textwidth}
\centering
\includegraphics[width=\textwidth]{gull}
\caption{A gull}
\label{fig:gull}
\end{subfigure}
\begin{subfigure}[b]{0.20\textwidth}
\centering
\includegraphics[width=\textwidth]{gull}
\caption{A gull2}
\label{fig:gull2}
\end{subfigure}
\begin{subfigure}[b]{0.20\textwidth}
\centering
\includegraphics[width=\textwidth]{tiger}
\caption{A tiger}
\label{fig:tiger}
\end{subfigure}
\begin{subfigure}[b]{0.20\textwidth}
\centering
\includegraphics[width=\textwidth]{mouse}
\caption{A mouse}
\label{fig:mouse}
\end{subfigure}
\caption{Pictures of animals}\label{fig:animals}
\end{figure}
And the images are nicely displayed in one row.
For my case, I sometimes put the images for a row in one tabular row. This is just to have more control in the placements. But whether you decide to go for this depends on your personal choice. Should you decide to use this, the code is,
\begin{figure}
\centering
\begin{tabular}[c]{cccc}
\begin{subfigure}[b]{0.20\textwidth}
\includegraphics[width=\textwidth]{gull}
\caption{A gull}
\label{fig:gull}
\end{subfigure}&
\begin{subfigure}[b]{0.20\textwidth}
\includegraphics[width=\textwidth]{gull}
\caption{A gull2}
\label{fig:gull2}
\end{subfigure}&
\begin{subfigure}[b]{0.20\textwidth}
\includegraphics[width=\textwidth]{tiger}
\caption{A tiger}
\label{fig:tiger}
\end{subfigure}&
\begin{subfigure}[b]{0.20\textwidth}
\includegraphics[width=\textwidth]{mouse}
\caption{A mouse}
\label{fig:mouse}
\end{subfigure}
\end{tabular}
\caption{Pictures of animals}\label{fig:animals}
\end{figure}
And the images placements will be somewhat better. This is will allow more control which you may want to have as time passes.
To place all four subfigure environments in one row (and each occupy the same width), you must set their widths to something less than 0.25\textwidth
. In the example below, I use 0.24\textwidth
, and I set the spacing between the subfigures to \hspace{\fill}
, i.e., the maximum available amount. If you need more space between the individual subfigures, you should reduce their overall width (say, to 0.21\textwidth
).
By the way, there's no need for any \centering
instructions inside the individual subfigure
environments, as the graphs occupy the maximum available space. Likewise, there's no need for a \centering
instruction after \begin{figure}
if the full width of the textblock is to be used.
\documentclass[12pt,twoside]{report}
\usepackage[demo]{graphicx} % remove demo option for your production document
\usepackage{subcaption} % subcaption automaticallz loads caption package
\begin{document}
\begin{figure}
\begin{subfigure}[b]{0.24\textwidth}
\includegraphics[width=\linewidth]{gull}
\caption{A gull}
\label{fig:gull}
\end{subfigure}%
\hspace{\fill}
\begin{subfigure}[b]{0.24\textwidth}
\includegraphics[width=\linewidth]{gull}
\caption{A gull2}
\label{fig:gull2}
\end{subfigure}%
\hspace{\fill}
\begin{subfigure}[b]{0.24\textwidth}
\includegraphics[width=\linewidth]{tiger}
\caption{A tiger}
\label{fig:tiger}
\end{subfigure}%
\hspace{\fill}
\begin{subfigure}[b]{0.24\textwidth}
\includegraphics[width=\linewidth]{mouse}
\caption{A mouse}
\label{fig:mouse}
\end{subfigure}
\caption{Pictures of animals}\label{fig:animals}
\end{figure}
\end{document}