TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
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 '12 at 12:58
If you need multiple lines, \verb won't get you far. Does \begin{verbatim}...\end{verbatim} work? – krlmlr Feb 2 '12 at 13:19
It would be useful if you provided a Minimal Working Example. A package alltt might be useful. – yo' Feb 2 '12 at 17:20
You could use the subfigure environment, offered by the/my subcaption package. \verb+xxxx+ will work here. – Axel Sommerfeldt Feb 4 '12 at 7:21
up vote 8 down vote accepted

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.

share|improve this answer
@EmitTaste Thanks for the correction! – egreg Feb 9 '13 at 21:07

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.}
share|improve this answer
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. – Martin Schröder Feb 9 '13 at 22:48

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.