I am new to Latex and currently I am "probing" Latex for issues that I want an solution to before actually using Latex for work. My current problem is placement of wrapped figures. Wrapfigure{} seems completely unreliable to me.
I have created a compileable code to illustrate the problem. I have included all the used packages even though most are not relevant to this problem.
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lipsum}
\usepackage{titlesec}
\usepackage[table,xcdraw]{xcolor}
\usepackage{graphicx}
\usepackage{multirow}
\usepackage{booktabs}
\usepackage[nottoc,numbib]{tocbibind}
\usepackage{verbatim}
\usepackage{float}
\usepackage{caption}
\usepackage{wrapfig}
\begin{document}
\section{Example}
\lipsum[1-2]
\lipsum[1-1]
\begin{wrapfigure}{R}{70mm}
\centering
\includegraphics[width=60mm]{./MeltingEnergyNH2}
\caption{Melting Energy}
\label{figur:NH2}
\end{wrapfigure}
\textbf{\lipsum[120]}
\subsection{WrapFigur Test}
\lipsum[1-4]
\end{document}
Since the page has so much text the wrapped picture is pushed into the bottom margin. If I change the [r] to [R] and thus make the wrapped figure a float the figure disappears completely(it is not at the end of the document) and severely messes up the formatting of rest of the document as it is seen on picture 2(every page is like this one or worse)
This problem seems to appear when too much text is in front of the wrapped figure. Using \newpage
or similar can remove the problem, but this does not seem like a flexible solution. Is there a reliable solution to this problem?
Pictures(too large for the post) of the problem in the document:
Document with "[r]" Picture1
Document with "[R]" Picture2
Best Answer
In general with floats, the best approach for me is do not care of where is finally placed the image until the final version, but take care that it is always referenced when is really relevant (i.e,
see fig. \ref{keylabel}
) as sometimes simply the image cannot be placed just here.In the final draft, then move floats some paragraphs above/below solve most problems, and as last resource one can fix the float options, but being as permissive as possible, especially when you have a lot of floats. As more restrictive you are with floats, more problems you will find later.
Said that, for this edge case (the figure must be in a paragraph that have a page break, with no enough space in the first page) this is a dirty hack for the very final version only: split the paragraph in two parts just where the page break should be, taking care of hiding that to the reader (fill the last line of the first part and avoid indentation of the first line of the second part). Then take care that the wrap figure take enough vertical space, so that the second part of the paragraph do not take a extravagant shape (the
[14]
option, although in this MWE work equally without that).