I am trying to get source code and a picture side by side with two captions that are aligned with the upper part of the caption text as suggested in this thread: Having two figures subcaption on the same line.
For the alignment someone suggested the \subcaptionbox environment. However, when trying to insert a lstlising into the \subcaptionbox environment in the following example I get multiple errors:
\begin{figure}[!htbp]
\centering
\subcaptionbox{Example of a parameterized type in Scala adopted from~\cite{2.13-types}}[.45\textwidth]{
\begin{lstlisting}
class TreeMap[A <: Comparable[A], B] { … }
\end{lstlisting}
}
\subcaptionbox{UML representation of parameterized type TreeMap}[.45\textwidth]{
\includegraphics{parameterized-types.pdf}
}
\label{fig:scalaspecific:bounds}
\caption{Examplary UML representation of parameterized types}
\end{figure}
Produced Errors:
! Package inputenc Error: Invalid UTF-8 byte "80.See the inputenc package documentation for explanation.Type H <return> for immediate help.... }
! Argument of \lst@next has an extra }.<inserted text>\par }
...
I basically have two questions now.
First: Is there a fix to this, so that one can put lisitings inside \subcaptionbox environments?
Second: If there is no fix, is there another way to achieve same line caption alignment for a picture and code?


lstlistingenvironment can't be the argument of a macro, instead of\subcaptionbox, you could use thesubfigureenvironment. – Skillmon Dec 05 '20 at 16:21subfigurethe captions are aligned at the bottom, but I want them to be aligned at the top. Is it possible to achieve this with subfigure? – Tilman Zuckmantel Dec 05 '20 at 16:49\lstinputlisting{<file>}instead. This way you should be able to put the listing in the argument of\subcaptionbox. Also, you'll have to change…to...if you're usingpdflatex. – Skillmon Dec 05 '20 at 19:37\lstinputlistingseems to be the best solution, do you want to state an answer yourself, or should i provide a detailed answer ? – Tilman Zuckmantel Dec 07 '20 at 11:40