# Placing an image with caption at the bottom of the page in XeLaTeX?

I need to create a figure an place it at the bottom of the page (figure includes the image and some caption text). Is there a way to do it?

I tired using figure environment, but it sends my image all the way to the end of the document.

MWE:

\documentclass[a4paper, 12pt]{article}

\usepackage{xltxtra}
\setmainfont[Mapping=tex-text]{Times New Roman}
\usepackage[russian]{babel} % for russian hypenation

\begin{document}

\pagebreak
\section*{\centering Методика}

Some text.

\begin{figure}[b]
\centering
\includegraphics[width=\textwidth]{labyrinth.png}
\end{figure}

Some more text.

\pagebreak
\section*{\centering Результаты}

\end{document}


The figure ends up being stuffed on the very last page.

I'm using XeTeX 3.1415926-2.2-0.9995.2 (TeX Live 2009/Debian).

-
 @HarishKumar - then it gets printed on the next page, and eats all that page. I need it to be placed at the bottom of the page, so that the text is above the figure and continues on the next page. – Rogach Apr 23 '12 at 22:50 Can you post a MWE? – Harish Kumar Apr 23 '12 at 22:56 @HarishKumar - posted. – Rogach Apr 23 '12 at 23:04

You have missed adding graphicx. Also you better use fontenc for better results. Here is the working MWE: (I can't use russian, so I used english)

\documentclass[a4paper, 12pt]{article}
\usepackage[demo]{graphicx} %Remove demo in your file
\usepackage{xltxtra}
\usepackage{lipsum} % for dummy text
\usepackage[T1]{fontenc}
\setmainfont[Mapping=tex-text]{Times New Roman}
%\usepackage[russian]{babel} % for russian hypenation
%
\begin{document}
%
\pagebreak
\section*{A section} % Don't use \centering inside a section.
%
\lipsum[1]
%
\begin{figure}[b]
\centering
\includegraphics[width=\textwidth]{labyrinth.png}
\end{figure}

\lipsum[5-10]
%
\pagebreak
\section*{another section}
%
\end{document}


-
 This is really strange - that figure is quite big (half a page tall if set to \textwidth), so if I scale it down, it works as you have shown. But if it gets a bit bigger, latex throws it down. – Rogach Apr 24 '12 at 0:10 But if I add some text below the image (inside figure), and set the position as [b!], it suddenly starts to work. :) Thanks for your help! – Rogach Apr 24 '12 at 0:15 @Rogach: The code provided by @HarishKumar works, even though your figure's height exceeds 0.3\textheight, because the \pagebreak instructions (eventually) force LaTeX to "flush" accumulated floats. For a method that does not rely on forcing page breaks, I (shamelessly...) suggest you consult the answer I've provided. – Mico Apr 24 '12 at 19:50

If you try the following document

\documentclass[a4paper, 12pt]{article}

\usepackage{fontspec}
\setmainfont[Ligatures=TeX]{Times New Roman}
\usepackage{polyglossia}
\setmainlanguage{russian} % for russian hyphenation
\usepackage{kantlipsum}

\begin{document}

\section*{Методика}

Some text.

\begin{figure}[b]
\centering
\includegraphics[width=\textwidth]{labyrinth.png}
\end{figure}

Some more text.

\kant

\section*{Результаты}

\end{document}


you'll see that the figure is at the bottom. Setting figures where we want they to be requires a bit of white magic (shifting the code up one paragraph sometimes help). In your example the figure is actually at the bottom, but the \pagebreak command made the bottom to be just below the figure because the article class issues \raggedbottom.

Using Babel for Russian with XeLaTeX can't be recommended (try and write \tableofcontents to see why). The xltxtra package is by no means necessary and simply fontspec is usually better.

Note that kantlipsum and the demo option to graphicx are only for demonstration purposes.

-

You haven't told us how tall the figure is, but I have a hunch that its height is greater than 0.3\textheight. My hunch is based on your remarks that (i) LaTeX places the float in question at the very end of the document and (ii) you've specified the b (and only the b, right?) placement directive.

LaTeX has a parameter named \bottomfraction, which is set to 0.3\textheight initially; what this means is that LaTeX will only place a float in the b (bottom) position of a page if the float's height is no larger than, you guessed it, 0.3\textheight. If your figure's height is indeed greater than this default parameter value and if you've specified the b placement directive, LaTeX can't place the float on the page in question and, as a result, will keep deferring placement of the float until either the very end of the document is reached or until a \clearpage instruction is encountered (whichever comes first).

Assuming that the height of the figure is indeed greater than 30% of the height of the text block, you may want to add the following instruction to your document's preamble:

\renewcommand\bottomfraction{0.7} % same value as \topfraction...


and recompile your LaTeX file. Happy TeXing!

-
 funny thing is, I ran into the same problem when using Harish's approach on even bigger, and tried your suggestion - but this did not help, for some twisted reason. – Rogach Apr 24 '12 at 20:30 @Rogach -- would you mind being a bit more specific regarding the observation "this did not help, for some twisted reason". Did you get an error message? If so, what did it say? Does the float in question still end up at the very end of the document? How tall is the float (with the inluded pdf file set to \textwidth)? I'm really curious. – Mico Apr 24 '12 at 20:36 sorry, I was really in a hurry at that time and can't reproduce that behavior now :( But I do remember that there were no error messages, and the float ended on the next page (due to \pagebreak, probably). The height of it was a bit more that half page height. – Rogach Apr 24 '12 at 22:31 @Rogach - since you note that "the float ended on the next page", the easiest remedy is (in addition to issuing the command \renewcommand\bottomfraction{0.7} in the preamble) placing the code for the float, i.e., the \begin{figure}[b!] ... \end{figure} stuff, near the top of the page where you know it should be placed. That way, LaTeX will (almost certainly...) place it on the page where you want it to be without you having to resort to \pagebreak or \clearpage instructions. – Mico Apr 25 '12 at 0:01