跨页面拆分图形中的逐字内容

跨页面拆分图形中的逐字内容

我想将一段很长的verbatim文本(对于一页来说太长)放在带有标题的图形中。不幸的是,当将verbatim环境放入图形中时,它不会自动跨页拆分。以下是 MWE,说明了我面临的问题。

\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}

在此处输入图片描述

答案1

浮动对象不允许分页;您可以使用listings包来排版您的逐字文本;您可以使用键caption来提供标题,并且(除非您将列表声明为浮点数),它将允许分页符:

\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}

在此处输入图片描述

答案2

如果你想给你的首饰增添一点“光彩” verbatim,你可以使用tcolorbox包裹。

截屏

在下面的代码中,我定义了一个新的newtcblisting调用cmhlisting,它接受两个强制参数和一个可选参数:

  • [#1]是您希望传递给listings环境的可选参数
  • {#2}是标题
  • {#3}\label可以用于\ref和朋友的

这是完整的代码 - 如果您想要它float,那么您只需取消注释详细说明float和的行floatplacement。手册详细介绍了许多其他选项 - 这只是帮助您入门的东西。

% arara: pdflatex
\documentclass[a4paper]{article}
\usepackage{showframe}
\usepackage{listings}
\usepackage{tcolorbox}
% tcolorbox libraries
\tcbuselibrary{breakable,skins,listings}

\makeatletter
\tcbset{
    addtolol/.style={list entry={\kvtcb@title},add to list={lol}{lstlisting}},
}
\makeatother

\newtcblisting[use counter=lstlisting]{cmhlisting}[3][]{%
    width=\textwidth,
    breakable,
    colback=blue!5!white,
    colframe=white!85!black,
    listing only,
    listing options={#1},
    center title,
    %float,
    %floatplacement=!ht,
    title={\color{black}{\scshape Listing \thetcbcounter}: ~#2},label={#3},
    addtolol,
}

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

reference: \ref{lst:yourlabelhere}

\begin{cmhlisting}{Three copies of output of \texttt{pdflatex}}{lst:yourlabelhere}
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{cmhlisting}
\end{document}

相关内容