8

I have multiple figures placed in my document (all of which are using [htbp], [ht] etc. and are placed correctly). The last figure receives a separate page (which is alright) but it's centered on this page, which looks weird as the figure is quite small.

Is there any way to get this figure on top of this page? As written above, its a separate page and the last one in this chapter.

I can't really provide a minimal example (since I guess that the position depends on my previous figures), but here's the code I use for the figure (I've tried [ht], [ht!], [htbp] etc but none of them work - I've also deleted the .aux files before compiling):

\begin{figure}[t!]
\centering
\begin{tabularx}{\columnwidth}{cc}
\subfloat[Results 1]
{ \centering    \includegraphics[width=0.47\textwidth,height=0.47\textheight,keepaspectratio]{images/plot1}
}
&
\subfloat[Results 2]
{ \centering    \includegraphics[width=0.47\textwidth,height=0.47\textheight,keepaspectratio]{images/plot2}
}
\end{tabularx}
\caption{Blabla}
\end{figure}

Thanks in advance!

yo'
  • 51,322
  • Hi and welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. It is the default and in general correct behaviour that floats on pages with no text are vertically centered. Why would you want it another way? – yo' May 26 '14 at 10:33
  • It looks a bit weird because the image is quite small. Of course, another option would be to make it bigger (it's a plot), but I'm just wondering if there's a way to place it on top. – user52450 May 26 '14 at 10:47
  • The usage of ! as a specifier to the figure environment is discouraged for years now ;-) –  May 26 '14 at 10:51
  • Why are you using [!t] in the first place? How about [!ht] instead if there is room for it here. – daleif May 26 '14 at 11:02
  • You could drop the figure environment and use \captionof{figure}{Blabla} instead. Then the graphicx is at the place where you want to have it, if there is enough place left on the page, otherwise on the next page. –  May 26 '14 at 11:04
  • I've tried [!ht] too (same results) :/ – user52450 May 26 '14 at 20:07

3 Answers3

11

As tohecz pointed out, this is the general and correct behavior. But you can change this by using

\makeatletter
\setlength{\@fptop}{0pt}
\makeatother

as found here, following the answer to a similar question.

David Carlisle
  • 757,742
Markus
  • 450
  • Setting lengths globally is not always a good idea ;-) –  May 26 '14 at 11:00
  • 1
    If you deviate from the default, at least do it consistently ;-) @ChristianHupfer – Markus May 26 '14 at 11:32
  • @ChristianHupfer I agree with Markus on this. The solution is IMHO the proper way to do it, if you want it in the first place. Upvoted. – yo' May 26 '14 at 11:57
  • Thanks a lot! It might sound weird but I like the idea of the centering, it's just the very last page of the paper and looks extremely weird (since a small image is in the middle). – user52450 May 26 '14 at 20:14
4

Just place a large enough \vspace after the caption to push it to the top. Specifying the \vspace too large is OK. Here, I place a figure on a [p] page to guarantee the "bad" behavior, but add a 128inch \vspace after the caption, exaggerated to make the point that the actual length is immaterial, if it is large enough to do the trick.

\documentclass{article}
\usepackage[demo]{graphicx}
\begin{document}
\begin{figure}[p]
\centering
\includegraphics[width=0.47\textwidth,height=0.47\textheight]{file}
\caption{Blabla}
\vspace{128in}
\end{figure}
\end{document}

enter image description here

To avoid the "warning" that comes from a too-large float (if that bothers you), one could add negative \vspace prior to the figure contents, as in

\documentclass{article}
\usepackage[demo]{graphicx}
\begin{document}
\begin{figure}[p]
\vspace{-128in}
\centering
\includegraphics[width=0.47\textwidth,height=0.47\textheight]{file}
\caption{Blabla}
\end{figure}
\end{document}
  • 1
    That's a nasty thing to do that generates a Float to large! warning. – yo' May 26 '14 at 11:56
  • 2
    @tohecz How does the children's rhyme go?... Sticks and stones can break my bones, but warnings can never hurt me. – Steven B. Segletes May 26 '14 at 11:58
  • 1
    @tohecz Please see my follow up – Steven B. Segletes May 26 '14 at 12:01
  • Warning should make you warned. Warning appearing for things that are correct should be avoided. I always come through the log to check for presence of warning. And these "ok" ones then only confuse me. – yo' May 26 '14 at 12:08
  • @tohecz I didn't mean to diminish the import of your statement. You admittedly make a good point, which spurred me to revise my answer. – Steven B. Segletes May 26 '14 at 12:10
  • The problem with this solution is that you have to specificly mark one float as "the last one", i.e. if you want to insert one after that, you have to change it again. Besides, there might be 2 (small) floats being placed on the page and the author wants them both to be aligned top in this case (I assume). – Markus May 26 '14 at 14:30
  • @Markus If I understood the OP's question correctly, this was an issue specifically with "the last figure". Thus, I don't see a problem. More specifically, the technique shows how to overcome an issue for floats that insist (based on document structure) on being on a page by themselves. – Steven B. Segletes May 26 '14 at 15:51
  • @StevenB.Segletes: Absolutely, your version works and is thus an answer to this particular question. I just wanted to point out a "disadvantage". Maybe "problem" is too strong here. Change "problem" to "disadvantage" to minimize intended criticism. – Markus May 26 '14 at 16:19
  • That did the job! However, the negative vspace failed (already a negative -1in placed it back on the previous page). Thanks! – user52450 May 26 '14 at 20:27
  • @user52450 I hadn't thought of that. You could issue a \clearpage before the last figure to remedy the prior page thing, if the negative \vspace were preferred. – Steven B. Segletes May 26 '14 at 20:32
0

If you already tried \begin{figure}[!htb] ... \end{figure} and it still does not work, probably, your figures/tables have then floated on ahead to appear after the next \section heading. So, try clearing the page before the figure. This will lead to \clearpage before the figure: \clearpage \begin{figure}[!htb] ... \end{figure}. This worked for me without changing any default behavior of LaTeX.