0

Im having trouble displaying an image. It tends to float where ever it wants in the doc. The code I used it displayed here

\begin{figure}[h!]
\begin{center}
  \includegraphics[width=8cm]{Hyperfine_splitting.png}
\end{center}
\caption{\label{fig1} Hyperfine splitting of hydrogen states. The first three states equivalent to $F=1$ and the single state corresponding to $F=0$}
\end{figure}
David Carlisle
  • 757,742
  • 1
    Please provide a specific example of the "tends to float where ever it wants" case. How far away does the figure environment float? Incidentally, how tall is the entire figure? Incidentally, if you want a simple way of economizing on vertical space, replace \begin{center} with \centering and delete \end{center}. – Mico Feb 08 '22 at 06:48
  • @Mico the image tends to float to the last section in the document. Also im not really sure what you mean by how tall is the figure? – Ritu Kelkar Feb 08 '22 at 07:08
  • @Ritu Kelkar The primary problem ist that you question as it is currently written is unsolveable. The code you provided is perfectly fine once a proper \documentclass{} is added and {Hyperfine_splitting.png} is exchanged with {example-image-a} since nobody has you image. Also without knowing your packages laoded (or documentclass) it is a big guessing game. Read the link I provided earlier. It basically handles your problem. – Roland Feb 08 '22 at 08:15
  • the only reason to use \begin{figure} is to allow it to move, but using [h] makes it moving to the end of the document quite likely as it removes the possibilities t b p so does not allow the float at the top of a page, the bottom of a page or on a page of just floats, which does not give many places it is allowed. latex will warn about this and change it to ht to give itself a chance but preventing p floats is still very restrictive and force larger images to the end of the document – David Carlisle Feb 08 '22 at 08:44
  • use \centering not \begin{center} and use [htbp] not [!h] – David Carlisle Feb 08 '22 at 08:45
  • if [h!] float is because cannot be fitted in the actual page, and the alternative to fix only here ([H] of float package) is much worse: jump anyway to the next page but now leaving a huge bottom space on the previous page. Bad solution: use [H] and bear with the ragged bottoms. Good solutions: move the float or resize the image so it can be fitted without floating, or better allow floating (see above comment) and use \ref and \pageref, that exist just to locate something that is "lost" in another page. – Fran Feb 08 '22 at 08:47

0 Answers0