[Tex/LaTex] Splitting verbatim inside figure across pages

floatspage-breakingverbatim

I want to include a long section of verbatim text, which is too long for a single page, inside a figure with a caption.
Unfortunately, when the verbatim environment is put into a figure, it does not automatically split across pages.
Here is a MWE that illustrates the problem which I am facing.

\documentclass[a4paper]{article}

\usepackage{showframe} % show diagram of page layout

\begin{document}
\begin{figure}[h!]
\begin{verbatim}
This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013)
 restricted \write18 enabled.
entering extended mode
(./2014-01-30.tex
LaTeX2e <2011/06/27>
Babel <3.9f> and hyphenation patterns for 78 languages loaded.
(/usr/local/texlive/2013/texmf-dist/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/local/texlive/2013/texmf-dist/tex/latex/base/size10.clo))
No file 2014-01-30.aux.
[1{/usr/local/texlive/2013/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]
(./2014-01-30.aux) )</usr/local/texlive/2013/texmf-dist/fonts/type1/public/amsf
onts/cm/cmr10.pfb>
Output written on 2014-01-30.pdf (1 page, 8170 bytes).
SyncTeX written on 2014-01-30.synctex.gz.
Transcript written on 2014-01-30.log.



This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013)
 restricted \write18 enabled.
entering extended mode
(./2014-01-30.tex
LaTeX2e <2011/06/27>
Babel <3.9f> and hyphenation patterns for 78 languages loaded.
(/usr/local/texlive/2013/texmf-dist/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/local/texlive/2013/texmf-dist/tex/latex/base/size10.clo))
No file 2014-01-30.aux.
[1{/usr/local/texlive/2013/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]
(./2014-01-30.aux) )</usr/local/texlive/2013/texmf-dist/fonts/type1/public/amsf
onts/cm/cmr10.pfb>
Output written on 2014-01-30.pdf (1 page, 8170 bytes).
SyncTeX written on 2014-01-30.synctex.gz.
Transcript written on 2014-01-30.log.



This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013)
 restricted \write18 enabled.
entering extended mode
(./2014-01-30.tex
LaTeX2e <2011/06/27>
Babel <3.9f> and hyphenation patterns for 78 languages loaded.
(/usr/local/texlive/2013/texmf-dist/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/local/texlive/2013/texmf-dist/tex/latex/base/size10.clo))
No file 2014-01-30.aux.
[1{/usr/local/texlive/2013/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]
(./2014-01-30.aux) )</usr/local/texlive/2013/texmf-dist/fonts/type1/public/amsf
onts/cm/cmr10.pfb>
Output written on 2014-01-30.pdf (1 page, 8170 bytes).
SyncTeX written on 2014-01-30.synctex.gz.
Transcript written on 2014-01-30.log.
\end{verbatim}
\caption{Three copies of output of \texttt{pdflatex}.}
\end{figure}
\end{document}

enter image description here

Best Answer

Floating objects don't admit page breaks; you can use the listings package to typeset your verbatim text; you can use the caption key to provide a caption and (unless you declare the listing as a float), it will admit page breaks:

\documentclass[a4paper]{article}
\usepackage{showframe} % show diagram of page layout
\usepackage{listings}

\lstset{
  basicstyle=\small\ttfamily,
  breaklines=true,
  columns=fullflexible
}

\begin{document}

\begin{lstlisting}[caption={Three copies of output of \texttt{pdflatex}.}]
This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013)
 restricted \write18 enabled.
entering extended mode
(./2014-01-30.tex
LaTeX2e <2011/06/27>
Babel <3.9f> and hyphenation patterns for 78 languages loaded.
(/usr/local/texlive/2013/texmf-dist/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/local/texlive/2013/texmf-dist/tex/latex/base/size10.clo))
No file 2014-01-30.aux.
[1{/usr/local/texlive/2013/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]
(./2014-01-30.aux) )</usr/local/texlive/2013/texmf-dist/fonts/type1/public/amsf
onts/cm/cmr10.pfb>
Output written on 2014-01-30.pdf (1 page, 8170 bytes).
SyncTeX written on 2014-01-30.synctex.gz.
Transcript written on 2014-01-30.log.



This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013)
 restricted \write18 enabled.
entering extended mode
(./2014-01-30.tex
LaTeX2e <2011/06/27>
Babel <3.9f> and hyphenation patterns for 78 languages loaded.
(/usr/local/texlive/2013/texmf-dist/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/local/texlive/2013/texmf-dist/tex/latex/base/size10.clo))
No file 2014-01-30.aux.
[1{/usr/local/texlive/2013/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]
(./2014-01-30.aux) )</usr/local/texlive/2013/texmf-dist/fonts/type1/public/amsf
onts/cm/cmr10.pfb>
Output written on 2014-01-30.pdf (1 page, 8170 bytes).
SyncTeX written on 2014-01-30.synctex.gz.
Transcript written on 2014-01-30.log.



This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013)
 restricted \write18 enabled.
entering extended mode
(./2014-01-30.tex
LaTeX2e <2011/06/27>
Babel <3.9f> and hyphenation patterns for 78 languages loaded.
(/usr/local/texlive/2013/texmf-dist/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/local/texlive/2013/texmf-dist/tex/latex/base/size10.clo))
No file 2014-01-30.aux.
[1{/usr/local/texlive/2013/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]
(./2014-01-30.aux) )</usr/local/texlive/2013/texmf-dist/fonts/type1/public/amsf
onts/cm/cmr10.pfb>
Output written on 2014-01-30.pdf (1 page, 8170 bytes).
SyncTeX written on 2014-01-30.synctex.gz.
Transcript written on 2014-01-30.log.
\end{lstlisting}

\end{document}

enter image description here

Related Question