TransWikia.com

Captioning two minipages in custom float

TeX - LaTeX Asked on December 23, 2020

I am trying to put two listings side by side in a custom float using the float package using minipages. What I am trying to do works fine inside a figure (both captions appear) but inside my custom code environment only the second ("Listing 2") caption appears.

MWE

MWE:

documentclass{article}
usepackage{lipsum}
usepackage{caption}
usepackage{listings}

usepackage{float}
floatstyle{plaintop}
newfloat{code}{thp}{lop}
floatname{code}{Listing}

begin{document}

lipsum

begin{code}[t]
    begin{minipage}{0.45linewidth}
    captionof{lstlisting}{Disappears}
    Inside custom 1
    end{minipage}hfill%
    begin{minipage}{0.45linewidth}
    captionof{lstlisting}{Appears}
    Inside custom 2
    end{minipage}
end{code}

begin{figure}[t]
    begin{minipage}{0.45linewidth}
    caption{Appears}
    Inside figure 1
    end{minipage}hfill%
    begin{minipage}{0.45linewidth}
    caption{Appears}
    Inside figure 2
    end{minipage}
end{figure}

end{document}

How can I solve this?

One Answer

I found a solution using the newfloat environment:

usepackage{newfloat}
DeclareFloatingEnvironment[fileext=frm,placement={tph},name=Frame]{myfloat}

…

begin{myfloat}[t]
    centering
    begin{minipage}{0.45linewidth}
    captionof{lstlisting}{Appears}
    Inside custom 1
    end{minipage}hfill%
    begin{minipage}{0.45linewidth}
    captionof{lstlisting}{Appears}
    Inside custom 2
    end{minipage}
end{myfloat}

Correct answer by orestisf on December 23, 2020

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