I am using separate counters for (graphics) figures and listings. I am using the caption and subcaption packages. I construct sub-figures using subfigure:
\begin{figure}
\begin{subfigure}{0.34\textwidth}
...
\caption{sub-1}\label{fig:sub1}
\end{subfigure}
\begin{subfigure}{0.34\textwidth}
...
\caption{sub-2}\label{fig:sub2}
\end{subfigure}
\end{figure}
Now I need the same construction for listings. Like
\newsavebox{\verbsavebox}
\begin{figure}
\begin{lrbox}{\verbsavebox}
\begin{minipage}{.34\textwidth}
\begin{Verbatim}
...
\end{Verbatim}
\end{minipage}
\end{lrbox}%
\begin{subfigure}{0.34\textwidth}
\usebox{\verbsavebox}
\caption{sub-1}\label{lst:sub1}
\end{subfigure}
\begin{lrbox}{\verbsavebox}
\begin{minipage}{.34\textwidth}
\begin{Verbatim}
...
\end{Verbatim}
\end{minipage}
\end{lrbox}%
\begin{subfigure}{0.34\textwidth}
\usebox{\verbsavebox}
\caption{sub-2}\label{lst:sub2}
\end{subfigure}
\end{figure}
The problem is that this uses the figure counter, and the main caption is named "Fig...". What I want is use the listings counter and have the main caption named "Listing...".
EDIT Here is another try using lstlisting:
\documentclass{article}
\usepackage{verbatimbox}
\usepackage[T1]{fontenc}
\usepackage{fancyvrb}
\usepackage{listings}
\usepackage[scaled=.73]{beramono}
\fvset{baselinestretch=0.94}
\parindent=0pt
\parskip = 6pt
% "define" Scala
\lstdefinelanguage{scala}{
morekeywords={abstract,case,catch,class,def,%
do,else,extends,false,final,finally,%
for,if,implicit,import,match,mixin,%
new,null,object,override,package,%
private,protected,requires,return,sealed,%
super,this,throw,trait,true,try,%
type,val,var,while,with,yield,then}, % we use `then` in the pseudocode
otherkeywords={=>,<-,<\%,<:,>:,\#,@},
sensitive=true,
morecomment=[l]{//},
morecomment=[n]{/*}{*/},
morestring=[b]",
morestring=[b]',
morestring=[b]"""
}
% activate the language and predefine settings
\lstset{
basicstyle=\linespread{0.94}\ttfamily,%
language=scala,%
commentstyle=\itshape,%
keywordstyle=\bfseries,%
fancyvrb=true,%
mathescape=true,% for pseudocode
captionpos=b, % captions at the bottom
}
\begin{document}
In Fig.~\ref{fig:label} versus Listings~\ref{lst:label1} and \ref{lst:label2}.
\begin{figure}
Empty
\caption{fig}\label{fig:label}
\end{figure}
\begin{figure} % [htp]
\begin{lstlisting}{caption={list1},label={lst:label1}}
trait Sys[S <: Sys[S]] {
type ID <: Ident[S#Tx]
type Tx
}
trait Muta[S <: Sys[S]] {
def id: S#ID
// well defined:
def dispose(tx: S#Tx) =
id.dispose(tx)
}
trait Ident[Tx] {
def dispose(tx: Tx): Unit
}
\end{lstlisting}
\begin{lstlisting}{caption={list2},label={lst:label2}}
trait Sys {
type ID <: Ident[Tx]
type Tx
}
trait Muta[S <: Sys] {
def id: S#ID
// incompatible type:
def dispose(tx: S#Tx) =
id.dispose(tx)
}
\end{lstlisting}
\begin{lstlisting}{caption={list3},label={lst:label3}}
trait Sys {
type ID <: Ident[Tx]
type Tx
}
trait Muta[S <: Sys] {
// evidence required:
val s: S
def id: s.ID
// well defined:
def dispose(tx: s.Tx) =
id.dispose(tx)
}
\end{lstlisting}
\caption{Total caption}\label{lst:total}
\end{figure}
\end{document}
The problem is, the listings box gets numbered "Figure 2" instead of "Listing 1", and there are no sub captions (a) (b) (c). The reference in the text is broken, too. And the three listings should appear in three columns next to each other. So this is how the preceding code looks:

And this is a mock up of how it should look:

EDIT 2
Ok, so I compiled paracol.sty and tried:
\documentclass{article}
\usepackage{verbatimbox}
\usepackage[T1]{fontenc}
\usepackage{fancyvrb}
\usepackage{listings}
\usepackage[scaled=.73]{beramono}
\fvset{baselinestretch=0.94}
\parindent=0pt
\parskip = 6pt
\usepackage{caption}
% "define" Scala
\lstdefinelanguage{scala}{
morekeywords={abstract,case,catch,class,def,%
do,else,extends,false,final,finally,%
for,if,implicit,import,match,mixin,%
new,null,object,override,package,%
private,protected,requires,return,sealed,%
super,this,throw,trait,true,try,%
type,val,var,while,with,yield,then}, % we use `then` in the pseudocode
otherkeywords={=>,<-,<\%,<:,>:,\#,@},
sensitive=true,
morecomment=[l]{//},
morecomment=[n]{/*}{*/},
morestring=[b]",
morestring=[b]',
morestring=[b]"""
}
% activate the language and predefine settings
\lstset{
basicstyle=\linespread{0.94}\ttfamily,%
language=scala,%
commentstyle=\itshape,%
keywordstyle=\bfseries,%
fancyvrb=true,%
mathescape=true,% for pseudocode
captionpos=b, % captions at the bottom
}
\usepackage{capt-of}
\usepackage{paracol}
\begin{document}
In Fig.~\ref{fig:label} versus Listings~\ref{lst:label1} and \ref{lst:label2}.
\begin{paracol}{3}
\begin{lstlisting}[caption={list1},label={lst:label1}]
trait Sys[S <: Sys[S]] {
type ID <: Ident[S#Tx]
type Tx
}
trait Muta[S <: Sys[S]] {
def id: S#ID
// well defined:
def dispose(tx: S#Tx) =
id.dispose(tx)
}
trait Ident[Tx] {
def dispose(tx: Tx): Unit
}
\end{lstlisting}
\switchcolumn
\begin{lstlisting}[caption={list2},label={lst:label2}]
trait Sys {
type ID <: Ident[Tx]
type Tx
}
trait Muta[S <: Sys] {
def id: S#ID
// incompatible type:
def dispose(tx: S#Tx) =
id.dispose(tx)
}
\end{lstlisting}
\switchcolumn
\begin{lstlisting}[caption={list3},label={lst:label3}]
trait Sys {
type ID <: Ident[Tx]
type Tx
}
trait Muta[S <: Sys] {
// evidence required:
val s: S
def id: s.ID
// well defined:
def dispose(tx: s.Tx) =
id.dispose(tx)
}
\end{lstlisting}
\end{paracol}
\begin{figure}
Empty
\caption{fig}\label{fig:label}
\end{figure}
\end{document}
This produces three identical caption numbers and not 1a, 1b, 1c:


subfloatbecause the cross references with it are broken, I have to usesubfigure. – Emit Taste Nov 05 '13 at 23:40Verbatimaslistings? If you use thelistingspackage, there arecaptionandlabeloptions and they will be labeled as "Listings" instead of figures. – masu Nov 05 '13 at 23:43\begin{lstlistings}, I think it had to do with the impossibility of putting three columns next to each other? – Emit Taste Nov 05 '13 at 23:45listings. – masu Nov 05 '13 at 23:58mdframedbox and theafterlastframeandaftersingleframeoptions with a custom counter. This approach has a design flaw in pagebreaking which I tried to get a solution for. – masu Nov 06 '13 at 11:57