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?

orestisf
  • 308

1 Answers1

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}

orestisf
  • 308