I am new in latex writing. I am have problem with figures alignment. I am trying to put six figures on single page side by side. but the last figure is bit right shifted. I am no getting what could be the reason behind this. Please help me out to fix this problem. Thank you. Here is my code,
\begin{figure}[h]
\begin{subfigure}[h]{7cm}
\centering
\includegraphics[scale=0.38]{images/er1.pdf}
\caption{PE}
\label{snr_a}
\end{subfigure}
\begin{subfigure}[h]{7cm}
\centering
\includegraphics[scale=0.38]{images/sb.pdf}
\caption{Pn}
\label{snr_b}
\end{subfigure}
\begin{subfigure}[h]{7cm}
\centering
\includegraphics[scale=0.38]{images/s5.pdf}
\caption{Pl}
\label{snr_c}
\end{subfigure}
\begin{subfigure}[h]{7cm}
\centering
\includegraphics[scale=0.38]{images/s0.pdf}
\caption{Pc}
\label{snr_d}
\end{subfigure}
\begin{subfigure}[h]{7cm}
\centering
\includegraphics[scale=0.38]{images/s5.pdf}
\caption{Pd}
\label{snr_e}
\end{subfigure}
\begin{subfigure}[h]{7cm}
\centering
\includegraphics[scale=0.38]{images/s9.pdf}
\caption{Pb}
\label{snr_f}
\end{subfigure}
\caption{abcdef}
\label{os}
\end{figure}
Best Answer
Don't use the
[h]
option alone, use[htp]
. Second, the[h]
option doesn't make sense forsubfigure
(for which the same options as forminipage
apply, that is,[t]
or[b]
, where the absence is equivalent to[c]
).It's also better to specify the width of figures, rather than a scale factor. In order to be independent of the actual text width, use a multiple of
\textwidth
, which is reset in asubfigure
to the stated width.The
figure
environment has a global\centering
, which avoids the filling in the last line (it's the same as for normal paragraphs, otherwise, where the last line is filled). Two subfigures are placed side by side, with a width slightly less than half of the text width and\hfill
between them. A blank line separates the rows. Adjust to suit your tastes.I the example, for lack of your images, I also specify a height, but you shouldn't. Also the
demo
option is just for producing the example, don't use it yourself.