# Multiple subfigures not appearing on the same line

Multiple figures under a single caption. I have tried a code to put two images in a together under a same caption. The subfigures do not appear on the same line.

The code is :

    \documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{subcaption}

\begin{document}
\blindtext \blindtext \blindtext
\begin{figure}
\centering
\begin{subfigure}[b]{0.5\textwidth}
\centering
\includegraphics[width=\textwidth]{C:/Thesis/Latex/thesis_1(1)/Figures/study.jpeg}
\rule{35em}{0.3pt}
\caption{the distribution of the nodes in the study site}
\label{fig:sensor3}
\hfill %% useful if width of each figure is less the .5\textwidth
\begin{subfigure}[b]{0.48\textwidth}
\centering
\includegraphics[width=\textwidth]{C:/Thesis/Latex/thesis_1(1)/Figures/coord.jpeg}
\rule{35em}{0.3pt}
\caption{the coordinates of nodes according to the Swiss coordinate system}
\label{fig:tiger}
\end{subfigure}
\caption{The Grand St. Bernard wireless sensor network deployment} \label{fig:Sensor}
\FloatBarrier
\end{figure}
\end{document}


Problem occurred with the code:

• What is the error you're receiving that makes it "not work properly?" – Werner Jan 3 '13 at 22:35
• Welcome to TeX.SE! When I put your code into a complete MWE it works fine for me... – cmhughes Jan 3 '13 at 22:36
• Not, error but plot doesn't appear in a same line. And figures are presented separately in different rows. – Topdombili Jan 3 '13 at 22:37
• Maybe \rule{\textwidth}{0.3pt}? – egreg Jan 4 '13 at 22:30
• Please, make the code into a complete compilable example. – egreg Jan 4 '13 at 22:40

You need to put a % after the first subfigure since the width of each subfigure is .5\textwidth. Also you may need a \hfill if the width is less than .5\textwidth.

\documentclass{article}

\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\begin{document}
\begin{figure}
\centering
\begin{subfigure}[b]{0.5\textwidth}
\centering
\includegraphics[width=\textwidth]{C:/Thesis/Latex/thesis_1(1)/Figures/study.jpeg}
\caption{the distribution of the nodes in the study site}
\label{fig:sensor3}
\hfill %% useful if width of each figure is less the .5\textwidth
\begin{subfigure}[b]{0.5\textwidth}
\centering
\caption{the coordinates of nodes according to the Swiss coordinate system}
\label{fig:tiger}
\end{subfigure}
\caption{The Grand St. Bernard wireless sensor network deployment} \label{fig:Sensor}
\end{figure}
\end{document}


But using a width of little less than .5\textwidth (say .49\textwidth) makes it look better IMO.

# Edit

Your problem (now) is the \rule{35em}{0.3pt} for which you have put a length of 35em. Actually subfigures are put in a minipage of of specified width. Hence this results in a badbox warning. Use \rule{\textwidth}{0.3pt} (or \linewidth) and badboxes run away.

Also, you are using \FloatBarrier inside the figure environment, which shouldn't be done. Move it outside as in my code.

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{subcaption,placeins,blindtext}

\begin{document}
\blindtext \blindtext \blindtext
\begin{figure}
\centering
\begin{subfigure}[b]{0.5\textwidth}
\centering
\includegraphics[width=\textwidth]{C:/Thesis/Latex/thesis_1(1)/Figures/study.jpeg}
\rule{\textwidth}{0.3pt}
\caption{the distribution of the nodes in the study site}
\label{fig:sensor3}
\hfill %% useful if width of each figure is less the .5\textwidth
\begin{subfigure}[b]{0.48\textwidth}
\centering
\includegraphics[width=\textwidth]{C:/Thesis/Latex/thesis_1(1)/Figures/coord.jpeg}
\rule{\textwidth}{0.3pt}
\caption{the coordinates of nodes according to the Swiss coordinate system}
\label{fig:tiger}
\end{subfigure}
\caption{The Grand St. Bernard wireless sensor network deployment} \label{fig:Sensor}
\end{figure}
\FloatBarrier %% put this here.
\end{document}


• The \centering commands inside the subfigure environments aren't needed because the graph objects take up the full widths of these environments. – Mico Jan 4 '13 at 0:40
• The code still doesn't work properly. I have edited the question and problem illustrated there. – Topdombili Jan 4 '13 at 8:12
• @Topdombili Which code? What are the details of doesn't work? Did you put the % as I told? – user11232 Jan 4 '13 at 13:45
• @HarishKumar, Yes, I have added % as you mentioned. The latest code is updated in question. – Topdombili Jan 4 '13 at 13:47
• @HarishKumar, I updated the question late. Sorry for that. I tries %. – Topdombili Jan 4 '13 at 13:51

One of the problems seems to be that you give your \rule commands a fixed width and therefore the subfigures are wider than the stated half \linewidth. I reset the rules to the length of \linewidth which is the width of your subfigures. Above that I put some % sign at the end of the first subfigure environment (Important: there must be no whitespace between the last character and the % sign) to eliminate the space between the two subfigures.

\documentclass{article}
\usepackage{subcaption}
\begin{document}
\begin{figure}
\centering
\begin{subfigure}[b]{0.5\textwidth}
\centering
\rule{\linewidth}{10em}
\rule{\linewidth}{0.3pt}
\caption{the distribution of the nodes in the study site}
\label{fig:sensor3}
\end{subfigure}%
\begin{subfigure}[b]{0.5\textwidth}
\centering
\rule{\linewidth}{6em}
\rule{\linewidth}{0.3pt}
\caption{the coordinates of nodes according to the Swiss coordinate system}
\label{fig:tiger}
\end{subfigure}
\caption{The Grand St. Bernard wireless sensor network deployment} \label{fig:Sensor}
\end{figure}
\end{document}


This gives the following output (I replaced the images by simple \rule commands:

For the subcaptions appearing in the List of Figures: this is a feature of the subcaptions package, not a bug. As far as I could see from the package documentation there is no simple option to turn this off.

I just removed \FloatBarrier and got:

which is what I think you wanted.

• There's still the problem of the too long rule, but \FloatBarrier definitely goes outside the figure environment. – egreg Jan 4 '13 at 23:03

I never used subcaption package, but it seems to me that subfigure package can be useful for you.

    \documentclass{article}
\usepackage{graphicx}

\usepackage{subfigure}

\begin{document}
\begin{figure}

\subfigure [the distribution of the nodes in the study site] {
\includegraphics[width=0.5\textwidth]{fig2.jpg}
%\caption{the distribution of the nodes in the study site}
\label{fig:sensor3}
}
\subfigure[The Grand St. Bernard wireless sensor network deployment]{
\includegraphics[width=0.5\textwidth]{fig1.jpg}
\label{fig:tiger}
}
\caption{The Grand St. Bernard wireless sensor network deployment}
\label{fig:Sensor}

\end{figure}
\end{document}


I hope this is useful.

• As far as I'm concerned the subfigure package hasn't seen any development for some time now and the subcaption package is the most actively developed package for this purpose. – Benedikt Bauer Jan 4 '13 at 23:56