22

I'm having a problem with an image and some text. I have this code:

Some text...\\

\begin{figure}[ht]
\centering
\includegraphics[scale=0.75]{picture.jpg}
\caption{The caption}   
\label{fig:picture}
\end{figure}

Some more text...

Basically, I want this:

Some text. (Above image in the code)
[end of page / new page]
image
Some more text. (Below the image in the code)
[start of new section]

But, what the above code gives me is this:

Some text. (Above image in the code)
Some more text. (Below the image in the code)
[end of page / new page]
image
[start of new section]

Latex insists on putting everything but a new section above the image even though its below the image in the code. Its probably because the image floats on top - but whats my alternative? There's not enough space on the first page to display the image there, to I cannot use [h] as the float-alignment.

I can "hack it", by creating an empty new section, like \section*{}, but this creates some white-space, which looks weird. Any suggestions?

madth3
  • 7,275
  • 12
  • 50
  • 74
Frederik Wordenskjold
  • 10,031
  • 6
  • 38
  • 57
  • Do you really need to do that? I mean, LaTeX is great in managing float and cross-references, being one of its main features to achieve a beautiful typesetting and a nice page layout... – Alessandro Cuttin May 13 '10 at 15:39
  • 1
    This is off topic. Should be trasferred to TEX Exchange ASAP – Trect Aug 12 '18 at 16:48

2 Answers2

42

If you really need to have the figure in that place, use the float package:

In the preamble:

\usepackage{float}

then, in the text:

Some text...

\begin{figure}[H]
  \centering
  \includegraphics[scale=0.75]{picture.jpg}
  \caption{The caption}   
  \label{fig:picture}
\end{figure}

Some more text...

Even though, is more preferable to let LaTeX place the floats.


Another way to do the same thing is by using the caption package.

In the preamble:

\usepackage{caption}

then, in the text:

Some text...

\begin{center}
  \includegraphics[scale=0.75]{picture.jpg}
  \captionof{figure}[LOF entry]{The caption}   
  \label{fig:picture}
\end{center}

Some more text...
Alessandro Cuttin
  • 3,822
  • 1
  • 30
  • 36
  • Thanks, it works! How do I let latex place the floats? If I dont add the [ht] or whatever float I want, it just places the image at the end of my document. Am I placing the image in a weird place? Where would you place it? – Frederik Wordenskjold May 13 '10 at 15:40
  • use preferably two placing options: [tb] for small figures, that stay well with the text on a single page; otherwise, for large figures, use [p]. More control on floats placement can be achieved with the package placeins – Alessandro Cuttin May 13 '10 at 15:49
  • Cool, I didnt know about those. [tb] seems to place the image exactly where it logically should be placed, so that seems to be exactly what I wanted. – Frederik Wordenskjold May 13 '10 at 16:01
-1

Use captionof instead of caption: \usepackage{caption}

Some text...

\begin{center}
  \includegraphics[width=0.6\textwidth]{picture.jpg}
  \captionof{figure}{Caption contents}  
  \label{fig:picture}
\end{center}

Some more text...
X.Z
  • 1
  • 1