0

I use the minted package for creating highlighted code listings in my text, and I have a need to display several snippets under one float. Firstly, I've tried to use the \subcaptionbox command from subcaption package like this:

\begin{lsg}{code:basic-id-transform}{Scoped identifier transformation}
    \begin{cppcode}
        // simple.hpp
        namespace foo {
                void bar(int a);
            }
    \end{cppcode}
    \subcaptionbox{Original file\label{code:basic-id-transform:orig}}{\usebox{\verbsavebox}}\hfill
    \begin{cppcode}
        // libsimple-c.h
        #ifdef __cplusplus
        #    define EXTERN       extern "C"
        #    define EXTERN_OPEN  extern "C" {
        #    define EXTERN_CLOSE }  // extern "C"
        #else
        #    define EXTERN
        #    define EXTERN_OPEN
        #    define EXTERN_CLOSE
        #endif
        EXTERN void foo_bar(int a);
    \end{cppcode}
    \subcaptionbox{Generated header\label{code:basic-id-transform:orig}}{\usebox{\verbsavebox}}\hfill
    \begin{cppcode}
        #include "libsimple-c.h"
        #include "simple.hpp"
        void foo_bar(int a) {
                (::foo::bar(a));
            }
    \end{cppcode}
    \subcaptionbox{Generated implementation\label{code:basic-id-transform:orig}}{\usebox{\verbsavebox}}\hfill
\end{lsg}

This code gives labels properly, but the result looks like this: enter image description here

Using \subcaption command, however, makes the total caption be treated as a subcaption, so that the whole float is not present in list of listings.

The problem is that all the solutions I found in internet are for the lstlisting package.

1 Answer 1

0

Found out a solution with minipage environment and a subcaption command.

\begin{lsg}{code:basic-id-transform}{Scoped identifier transformation}
  \begin{minipage}[b]{1\linewidth}
    \begin{cppcode}
        // simple.hpp
        namespace foo {
                void bar(int a);
            }
    \end{cppcode}
    \subcaption{Original file\label{code:basic-id-transform:orig}}
  \end{minipage}
  % ... and so on for every sub-listing ...
\end{lsg}

By giving fractional values in the third argument (e.g. \begin{minipage}[b]{0.5\linewidth}) it is possible to render listings in several columns.

You must log in to answer this question.

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