Text placed under figure instead of above

I have a figure that contains two subfigures side by side:

Foobar

\begin{figure*}[h!]
\centering
\begin{subfigure}[t]{0.5\textwidth}
\centering
\includegraphics[height=5.0in]{ressourcen/market_category}
\caption{Market category cocktails}
\end{subfigure}%
~
\begin{subfigure}[t]{0.5\textwidth}
\centering
\includegraphics[height=5.0in]{ressourcen/market_category_2}
\end{subfigure}
\caption{Market dashboard}
\end{figure*}


However the text foobar is placed under the figure instead of above it. I want to control the placement with h! but it has no effect. Any ideas how to have the text above the figure?

• That depends on the context. LaTeX tries to place floats in the best possible way according to its criteria. – Bernard Jun 22 '17 at 16:16
• B.t.w. are you in two-column mode? – Bernard Jun 22 '17 at 16:42
• @Bernard nope, not two-column mode – Lost in OWL Jun 22 '17 at 18:46
• IIRC, [h!] is actually translated as [htp], which is far more reasonable but the opposite of what you would expect. – John Kormylo Jun 22 '17 at 18:56
• As a last resort, you can use the [H] float placement from the float package, but it may result in unwanted blank areas in your document. Another solution would be the \insertBoxC plain TeX macro (load the package with \input{insbox}). – Bernard Jun 22 '17 at 19:07

\documentclass[10pt,a4paper]{article}
\usepackage{subcaption}
\usepackage{float}
\usepackage{graphicx}

\begin{document}

Text before.

\begin{figure}[H]
\centering
\begin{subfigure}[t]{0.5\textwidth}
\centering
\includegraphics[height=2.0in]{example-image}
\caption{Market category cocktails}
\end{subfigure}%
~
\begin{subfigure}[t]{0.5\textwidth}
\centering
\includegraphics[height=2.0in]{example-image}
\end{subfigure}
\caption{Market dashboard}
\end{figure}

Text after.

\end{document}


• Unfortunately this code doesn't work with 'figure*'... And I think @zab had a reason to use it – koleygr Jun 22 '17 at 20:18
• Maybe. He doesn't say something about it. Otherwise the answer may help others with a similar problem. – Dr. Manuel Kuehner Jun 22 '17 at 20:21
• Yes... of course... And it is more used method...(I thought I used 'float' package too but I did not) I just said what I said because it is not a duplicate... – koleygr Jun 22 '17 at 20:23
• Ok :). Going to bed now. – Dr. Manuel Kuehner Jun 22 '17 at 21:16
• @Dr.ManuelKuehner actually there is no special reason I use figure*, I removed the * and and now it's working – Lost in OWL Jun 23 '17 at 6:14

Try with [ht!] parameter.

(Also you may want to use 'keepaspectratio' in 'includegraphics' because you may loose the format of the figure if not)

\documentclass[10pt,a4paper]{article}
\usepackage{subcaption}
\usepackage{graphicx}

\begin{document}

Foobar

\begin{figure*}[ht!]
\centering
\begin{subfigure}[t]{0.5\textwidth}
\centering
\includegraphics[height=2.0in]{Sc1.png}
\caption{Market category cocktails}
\end{subfigure}%
~
\begin{subfigure}[t]{0.5\textwidth}
\centering
\includegraphics[height=2.0in]{Sc2.png}
\end{subfigure}
\caption{Market dashboard}
\end{figure*}
%\ref{test}

\end{document}


This is my code and this is the result:

• Thank you @Steven B. Segletes... I didn't know that we write packages and parameters in quotes – koleygr Jun 22 '17 at 18:27
• It is a matter of taste perhaps, but the rule of thumb I use is that if it is text that would be typed directly in a tex document, I use backquote delimiters to set it as code. – Steven B. Segletes Jun 22 '17 at 18:43
• Thank you, however ht! makes no difference, the problem remains – Lost in OWL Jun 22 '17 at 18:46
• @zab, probably something else is wrong with your packages or your macros in the documentclass or somewhere... take a look to my MWE... it works for me – koleygr Jun 22 '17 at 18:55
• @koleygr: I love your cocktails :o) – Bernard Jun 22 '17 at 18:57