我有一个 c++ 源文件,正在使用 Listings 包将其导入到 Latex。我发现一个模糊的提及,即使用 formfeed 在导入过程中创建新页面。
我的尝试:首先,我将 formfeed 添加到 listingStyle
然后我在我的 C++ 源代码中添加了以下注释(以便被识别为换页符):
我的代码:
\documentclass[a4paper]{article} % Use A4 paper by default, remove 'a4paper' for US letter
\usepackage{graphicx} % Required for including images
\setkeys{Gin}{width=\linewidth, totalheight=\textheight, keepaspectratio} % Default images settings
\graphicspath{{./Figures/}} % Specifies where to look for included images (trailing slash required)
\usepackage{float}
\usepackage{amsmath, amsfonts, amssymb, amsthm} % For math equations, theorems, symbols, etc
\usepackage{units} % Non-stacked fractions and better unit spacing
\usepackage{hyperref}
\usepackage{booktabs} % Required for better horizontal rules in tables
\usepackage{listings}
\usepackage{xcolor}
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codeblue}{rgb}{0.0,0.67,0.95}
\definecolor{codeorange}{rgb}{1,0.49,0}
\definecolor{backcolour}{rgb}{0.95,0.95,0.96}
\lstdefinestyle{mystyle}{
backgroundcolor=\color{backcolour},
commentstyle=\color{codegreen},
keywordstyle=\color{codeblue},
numberstyle=\tiny\color{codegray},
stringstyle=\color{codeorange},
basicstyle=\ttfamily\footnotesize,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
numbers=left,
numbersep=5pt,
showspaces=false,
showstringspaces=false,
showtabs=false,
formfeed = \newpage,
tabsize=2,
xleftmargin=10pt,
}
\lstset{style=mystyle}
\title{3+1D Exercise}
\author{Rahul V. Silva}
\date{\today} % Date, use \date{} for no date
%----------------------------------------------------------------------------------------
\begin{document}
\maketitle % Print the title section
\lstinputlisting[language=C++, caption={C++ code for 3+1D exercise},label={lst:3+1D code}, mathescape=true, firstline=25]{3+1D code.cpp}
\end{document}
导入的代码(3+1D代码.cpp): https://pastebin.com/T2J8q469
输出: