1

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.45\linewidth}
    \captionof{lstlisting}{Disappears}
    Inside custom 1
    \end{minipage}\hfill%
    \begin{minipage}{0.45\linewidth}
    \captionof{lstlisting}{Appears}
    Inside custom 2
    \end{minipage}
\end{code}

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

\end{document}

How can I solve this?

5
  • this was asked yesterday as well \floatstyle{plaintop} means you can only have one caption per float, placed on top. Commented Sep 28, 2020 at 23:23
  • tex.stackexchange.com/a/564413/1090 Commented Sep 28, 2020 at 23:24
  • Thanks! Is there any alternative then, to have multiple captions on top?
    – orestisf
    Commented Sep 28, 2020 at 23:31
  • 1
    if you don't use restylefloat then the captions go where you put them, they are not moved, so just place them where you want. Commented Sep 28, 2020 at 23:33
  • If I delete the floatstyle then this happens: i.imgur.com/60OCzyt.png
    – orestisf
    Commented Sep 28, 2020 at 23:36

1 Answer 1

1

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.45\linewidth}
    \captionof{lstlisting}{Appears}
    Inside custom 1
    \end{minipage}\hfill%
    \begin{minipage}{0.45\linewidth}
    \captionof{lstlisting}{Appears}
    Inside custom 2
    \end{minipage}
\end{myfloat}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .