TransWikia.com

Force placement of figure with subfigures and using a newer package

TeX - LaTeX Asked by Jason Spears on February 14, 2021

Could you tell me how can I force a figure with subfigures such as this

     centering
     begin{subfigure}[b]{0.45textwidth}
         centering
         includegraphics[width=textwidth]{figures/Test 1.png}
         caption{Some caption}
         label{fig:Test 1}
     end{subfigure}
     hfill
     begin{subfigure}[b]{0.45textwidth}
         centering
         includegraphics[width=textwidth]{figures/Test 2.png}
         caption{Some caption}
         label{fig:Test 2}
     end{subfigure}
     caption{Some caption}
        label{fig:Some label}
end{figure}

to appear in the page where I want it to, and then have some text after it.

I have tried the obvious [h] option, but that produced errors. I’m using the Harvard thesis template with Overleaf.

I end up with a page made of a figure with two subfigures plus another such figure, and I would like to have at one figure with some figures, then some text, and the next page again a figure with subfigures and some text.

How much does text/paragraph size affect this?

Maybe I fill have to use something like newpage before a paragraph or figure to have placements I would like?

How could I also rewrite this code and use a newer package, since I’ve just found out that subfigure is deprecated?

Thank you so much!

One Answer

Try this code first.

documentclass[a4paper]{article}

usepackage{graphicx}
usepackage{kantlipsum} %% added for dummy text
usepackage{caption}
usepackage{subcaption}

begin{document}    

kant[1]
See also figures ref{fig:Test 1} and ref{fig:Test 2}.

kant[2]

begin{figure}[ht]
    centering
    begin{subfigure}[b]{0.45textwidth}
        centering
        includegraphics[width=textwidth]{example-image-A}
        caption{Some caption}
        label{fig:Test 1}
    end{subfigure}
    hfill
    begin{subfigure}[b]{0.45textwidth}
        centering
        includegraphics[width=textwidth]{example-image-B}
        caption{Some caption}
        label{fig:Test 2}
    end{subfigure}
    caption{Some caption}
    label{fig:Some label}
end{figure}

kant[5]    

end{document}

output

Answered by Simon Dispa on February 14, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP