Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I tried to put two figures in one row and I found that subfigure package could help me. But code:

\documentclass[11pt, a4paper, draft]{article}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}

\begin{document}
\section{Example }
Lorem ipsum

\begin{figure}
        \centering
        \begin{subfigure}[b]{0.3\textwidth}
                \centering
                \includegraphics[width=\textwidth]{./2pol-hist}
                \caption{A gull}
        \end{subfigure}

        \begin{subfigure}[b]{0.3\textwidth}
                \centering
                \includegraphics[width=\textwidth]{./2pol-hist}
                \caption{A tiger}
        \end{subfigure}
        \caption{Pictures}
\end{figure}

\end{document}

reorganize my document, placing figures on the top of page. Why figures aren't below the section, as I specified in latex code?

share|improve this question
2  
figures are floating environments, so going to the top of the page is normal behaviour. If you never want a figure to float before its reference, add \usepackage{flafter} If you never want a figure to float out of its section add \usepackage[section]{placeins} –  David Carlisle Dec 16 '12 at 21:25
1  
Hi Marcin Welcome to TeX.SE! Have a look at How to influence the position of float environments like figure and table in LaTeX?/ and let us know if your question is a duplicate :) –  cmhughes Dec 16 '12 at 21:45
    
Thanks for response. It doesn't work in way I want. I want to have: some text figures1 | figures2 more text Like in: ` \begin{document} \section{Ex} Lorem \begin{figure}[htb] \centerline{\includegraphics[width=0.5\linewidth]{img}} \caption{caption} \end{figure} Lorem \end{document}` With one figure it works. In my case, I want two figures in one row. Two figures in row, all placed in order I specified in code. Maybe subfigure in this case is not good solution? I'm quite new in LaTeX and I found that subfigures are recommended way, and another are deprecated. –  Marcin Dec 16 '12 at 21:52
add comment

1 Answer

up vote 3 down vote accepted

Try this:

\documentclass[11pt, a4paper]{article}
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{subcaption}

\begin{document}
\section{Example}
Lorem ipsum

\begin{figure}[hbp]
        \centering
        \begin{subfigure}[b]{0.3\textwidth}
                \centering
                \includegraphics[width=\textwidth]{./2pol-hist}
                \caption{A gull}
        \end{subfigure}\hfill%
        \begin{subfigure}[b]{0.3\textwidth}
                \centering
                \includegraphics[width=\textwidth]{./2pol-hist}
                \caption{A tiger}
        \end{subfigure}
        \caption{Pictures}
\end{figure}

\end{document}

enter image description here

You had a blank line between the subfigure environment so the second environment was starting a new paragraph; I removed the spurious blank line and replaced it with an \hfill to get some spacing between the subfigures (not in this particular case, but you also need to be careful with possible spurious blank spaces). I also used [hbp] as placement specifier for the figure environment; this (in this case) prevents the floating object to appear before the section title and tries to place it where it was declared in the code or in the bottom of the page or in a float page (a dedicated page containing only floats).

The demo option for graphicx simply replaces actual figures with black rectangles; do not use that option in your actual document.

Using the draft class option your actual figures won't be included (you'll only see a rectangle and the name of the files); I suppressed that option from my example.

share|improve this answer
    
Possibly better [hbp]? –  egreg Dec 16 '12 at 22:21
    
@egreg yes, maybe it's better. I've edited my answer. –  Gonzalo Medina Dec 16 '12 at 22:23
    
Thanks, it works perfect. You read my mind, I almost asked, why figures are not included. I'm going to read article mentioned by cmhughes. This floating and positiong things for newbie are weird, I hope they will be clear. –  Marcin Dec 16 '12 at 22:33
    
@Marcin yes, that answer by Frank will clarify things. If you consider my answer solved your question, don't forget to mark it as accepted (in case of doubt, please see How do you accept an answer?); also, it you consider (after reading Frank's answer) that your question is a duplicate, please let us know so we can close it. –  Gonzalo Medina Dec 16 '12 at 22:40
    
@GonzaloMedina: now it's clear, things are getting obvious, you can close my question. I'm beginner in LaTeX (2 days user) and yesterday I had no idea where I can find solution and I were wasting time for looking for examples of side by side figures (there are such examples, but they focus directly on side by side, no floating, no positioning). I didn't see connection between floating and moving my figures on the top of page. –  Marcin Dec 17 '12 at 12:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.