When I write the following


I get \verb illegal in command argument. Seems that isn't possible to define a verbatim environment inside a \subfloat.

When I use \subfloat[caption]{\label{fig:xxxx}\texttt{xxxx}} it works, but I need multiple lines, so I have to use verbatim

What alternatives do I have? Maybe another package?

  • 2
    If you don't really need verbatim mode and \texttt is sufficient, then \parbox{5cm}{\ttfamily text} will do. Adjust the dimension. Otherwise you should present an example.
    – egreg
    Feb 2, 2012 at 12:58
  • If you need multiple lines, \verb won't get you far. Does \begin{verbatim}...\end{verbatim} work?
    – krlmlr
    Feb 2, 2012 at 13:19
  • 2
    It would be useful if you provided a Minimal Working Example. A package alltt might be useful.
    – yo'
    Feb 2, 2012 at 17:20
  • 2
    You could use the subfigure environment, offered by the/my subcaption package. \verb+xxxx+ will work here.
    – user2574
    Feb 4, 2012 at 7:21

2 Answers 2


You can't use \verb in the argument to another command. If you really need verbatim mode in your subfloat, then something like

\newsavebox{\verbbox} % in the preamble


will do. Inside the lrbox you can also put a minipage, for longer verbatim snippets:

Some verbatim
on more than one line

The subcaption package has features similar to subfig and subfloats are realized as environments, where verbatim is allowed.


See Section 6.9 ("How do I put a verbatim environment in a sub-float?") of the manual of the Subfig package. Basically, the manual suggests that you define the SubFloat environment in your preamble:

{ \egroup

Then, use the SubFloat environment as follows:

\begin{SubFloat}[Black box]{\label{fig:label1}Caption 1.}%
\rule{4cm}{3cm}%...blackbox subfigure...
\begin{SubFloat}{\label{fig:label2}Caption 2.}%...verbatim subfigure with
\begin{minipage}[b]{0.3\linewidth}% a minipage to control the width...
abc def ghi jkl
xx x xxx
abc def ghi jkl
\caption{Main Caption.}
  • 1
    No, while it's in the manual of a package, this is not the way to solve this problem - it's a very crude hack. Feb 9, 2013 at 22:48

You must log in to answer this question.

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