2

I have an alltt environment for which I'd like to add captions and sometimes subcaption, in the form: Example 1a: some description. However, I am only able to achieve : a: some description. I realize it would be easier with a float but, I need the environment to be able to span from one page to another. This is what I have so far:

\documentclass{article}
\usepackage{newfloat}
\usepackage{caption}
\DeclareFloatingEnvironment[fileext=frm,placement={!ht},name=example] {example}
\DeclareCaptionSubType{example}
\usepackage{alltt}
\usepackage[english]{babel}
\usepackage{blindtext}

\begin{document}

\begin{alltt}
\blindtext
\end{alltt}
\captionof{subexample}{Some description}

\end{document}
  • Sorry! Somehow when I copied the code over a bracket was lost - it should work now. – Lars Christian Jensen Aug 20 '17 at 9:34
3

The \DeclareCaptionSubType{example} macro does only provide the subexample type of the relevant example type, but not its name, this must be done separately with \captionsetup[subtype]{name=Example} (or choose any other name than Example)

If the counter of subexample should be reset with each example step, use \DeclareCaptionSetupType*{example} instead.

The a in a: some description comes from \thesubexample which is defined as \@nameuse{alph{subexample}}, which is effectively the same as \alph{subexample} here.

Perhaps \renewcommand{\thesubexample}{\Alph{subexample}} would be better here, but that is matter of taste.

\documentclass{article}
\usepackage{newfloat}
\usepackage{caption}
\DeclareFloatingEnvironment[fileext=frm,placement={!ht},name=example]{example}
\DeclareCaptionSubType*{example}
\captionsetup[subexample]{name=Example}

\renewcommand{\thesubexample}{\theexample\alph{subexample}}

\usepackage{alltt}
\usepackage[english]{babel}
\usepackage{blindtext}

\begin{document}


\stepcounter{example}% Faking an already existing usage of `example` 
\begin{alltt}
\blindtext
\end{alltt}
\captionof{subexample}{Some description}

\end{document}

enter image description here

  • I must admit that I do not really understand how the parent example and the subexample comes into action in the really O.P. document – user31729 Aug 20 '17 at 10:12
  • @LarsChristianJensen: Happy TeXing then ;-) – user31729 Aug 20 '17 at 10:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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