单列报告中附录中的两列代码列表

单列报告中附录中的两列代码列表

如何在单列报告中放置两列附录?我希望在附录的开头采用单列模式,然后在附录中以 2 列格式放置一些源代码列表。

谢谢

答案1

对于列表的多列排版,该listings包提供了multicols=n选项,它实际上是该包的内置接口multicol

\documentclass{report} 
\usepackage{listings,multicol}
\usepackage{lipsum}
\begin{document}
\chapter{foo}
\lipsum[1]
\begin{lstlisting}[numbers=left,xleftmargin=3em, multicols=2]
First line.
Second line.
Third line.
Next line.
Next Line
Next line.
Next Line
Next line.
Next Line
Next line.
Next Line
\end{lstlisting}
\lipsum[2]
\end{document}

请注意,您必须在序言中multicol明确加载。\usepackage{multicol}

答案2

您可以使用该包,也可以通过新模式multicol切换文档:\twocolumn

\documentclass{report} 
\usepackage{listings}
\usepackage{multicol}
\usepackage{lipsum}
\begin{document}
\chapter{foo}
\lipsum[1]
\begin{multicols}{2}
\begin{lstlisting}[numbers=left,xleftmargin=3em]
First line.
Second line.
Third line.
Next line.
Next Line
Next line.
Next Line
Next line.
Next Line
Next line.
Next Line
\end{lstlisting}
\end{multicols}
\lipsum[2]
\clearpage
\twocolumn
\lipsum[1]
\lipsum[2]
\begin{lstlisting}[numbers=left,xleftmargin=3em]
First line.
Second line.
Third line.
Next line.
Next Line
Next line.
Next Line
Next line.
Next Line
Next line.
Next Line
\end{lstlisting}
\lipsum[2]
\end{document}

答案3

使用标准报告类,您可以用来\twocolumn切换到双列模式:

\documentclass[a5paper]{report}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{listings}

\begin{document}
\blinddocument
\appendix
\twocolumn
\chapter{Here and now! The two column listing}
\lstinputlisting[{language=[LaTeX]TeX},breaklines=true]{\jobname.tex}

\onecolumn
\chapter{One more chapter in one column mode}
\blindtext

\end{document}

但是这样,在 之后可能没有额外的一列文本\chapter。使用 KOMA-Script\chapter可以在 的可选参数中使用\twocolumn

\documentclass[a5paper]{scrreprt}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{listings}

\begin{document}
\blinddocument
\appendix
\twocolumn[%
  \chapter{Here and now! The two column listing}
  \blindtext

  \vspace*{\baselineskip}
]


\lstinputlisting[{language=[LaTeX]TeX},breaklines=true]{\jobname.tex}

\onecolumn
\chapter{One more chapter in one column mode}
\blindtext

\end{document}

但是对于标准课程也有一个全面的建议:多色

\documentclass[a4paper]{report}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{listings}
\usepackage{multicol}

\begin{document}
\blinddocument
\appendix
\chapter{Here and now! The two column listing}
\blindtext

\begin{multicols}{2}
\lstinputlisting[{language=[LaTeX]TeX},breaklines=true]{\jobname.tex}
\end{multicols}

\chapter{One more chapter in one column mode}
\blindtext

\end{document}

这确实和

\documentclass[a4paper]{report}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{listings}
\usepackage{multicol}

\begin{document}
\blinddocument
\appendix
\chapter{Here and now! The two column listing}
\blindtext

\lstinputlisting[{language=[LaTeX]TeX},breaklines=true,multicols=2]{\jobname.tex}

\chapter{One more chapter in one column mode}
\blindtext

\end{document}

请注意,如果您使用选项,则multicols必须加载 multicol 包。包列表本身不会加载 multicol 包!

有关更多信息,\begin{multicols}{…}[…]请参阅包装手册。

相关内容