因此,我尝试使用该软件包为我listings
的文档添加一些代码示例。当我将verbatim
章节转换为标题时,标题消失了。我附加了一些示例代码,其前言与我的实际文档相同。有人看到会导致这种情况的原因吗?lstlisting
paragraph
前:
后:
\documentclass{article}
% New commands
\newcommand{\HRule}{\rule{\linewidth}{0.5mm}}
\newcommand{\superscript}[1]{\ensuremath{^{\textrm{#1}}}}
%%%%% Packages and configuration %%%%%
\usepackage[firstpage]{draftwatermark}
\SetWatermarkText{\textsc{Confidential}}
\SetWatermarkScale{4}
\SetWatermarkColor[gray]{0.9}
\usepackage{tabularx}
\usepackage[table]{xcolor}
\definecolor{dark-red}{rgb}{0.4,0.15,0.15}
\definecolor{dark-blue}{rgb}{0.15,0.15,0.4}
\definecolor{medium-blue}{rgb}{0,0,0.5}
\definecolor{light-grey}{gray}{0.8}
\usepackage[hidelinks]{hyperref}% keep at end
\hypersetup{
colorlinks,
linkcolor={black},
citecolor={dark-blue},
urlcolor={medium-blue}
}
\usepackage[margin=0.5in]{geometry}
%\usepackage{color}
\usepackage{listings}
\lstset{ %
language=C, % choose the language of the code
basicstyle=\footnotesize, % the size of the fonts that are used for the code
%numbers=left, % where to put the line-numbers
%numberstyle=\footnotesize, % the size of the fonts that are used for the line-numbers
%stepnumber=1, % the step between two line-numbers. If it is 1 each line will be numbered
numbersep=5pt, % how far the line-numbers are from the code
%backgroundcolor=\color{white}, % choose the background color. You must add \usepackage{color}
showspaces=false, % show spaces adding particular underscores
showstringspaces=false, % underline spaces within strings
showtabs=false, % show tabs within strings adding particular underscores
%frame=single, % adds a frame around the code
tabsize=4, % sets default tabsize to 4 spaces
captionpos=b, % sets the caption-position to bottom
breaklines=true, % sets automatic line breaking
breakatwhitespace=false, % sets if automatic breaks should only happen at whitespace
%escapeinside={\%*}{*)} % if you want to add a comment within your code
}
\usepackage{mdwlist}
\usepackage{underscore}
\usepackage{tikz}
\usepackage{float}
\begin{document}
\setcounter{tocdepth}{3} % Only display to subsubsection
\setcounter{secnumdepth}{5} % Number to paragraph
\tableofcontents
\section{Section A}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas nec malesuada dolor. Quisque ornare suscipit cursus. Donec posuere neque quis urna vulputate euismod. Proin a elit nec mauris molestie sodales ac a mauris. Praesent nec mauris ut odio varius cursus non ac sapien. Fusce metus ante, aliquet in vestibulum et, dictum non tortor. Phasellus luctus purus lacinia nisl posuere in rhoncus lorem semper. Nulla at diam sed urna volutpat porta eget eu turpis. Curabitur rutrum euismod convallis. Vestibulum nec justo risus, id pulvinar tellus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Morbi semper metus id augue dignissim vel pretium diam dictum.
\subsection{Sub Section A}
Aliquam facilisis sagittis pellentesque. Duis pharetra quam eget quam blandit quis ultrices risus ultrices. Aenean non tortor aliquet justo convallis condimentum a a metus. Suspendisse ipsum urna, eleifend egestas vehicula vel, fermentum ac ipsum. Fusce cursus massa vestibulum nulla imperdiet suscipit. Curabitur at tortor at nunc sagittis facilisis nec sed lectus. Fusce vitae lacus quam, eget lobortis turpis. Sed quam ligula, porta quis bibendum et, condimentum id felis. Fusce nisi lorem, congue nec pharetra ut, scelerisque sit amet dui. \\
\begin{lstlisting}
typedef enum
{
CODE_HERE /* comment here */
} enum_name;
\end{lstlisting}
\subsubsection{Sub Sub Section}
Vivamus vel mi leo, dictum semper lacus. Aliquam erat volutpat. Nam laoreet luctus diam vitae consequat. Fusce sit amet metus vitae nunc accumsan feugiat sed quis arcu. Aliquam erat volutpat. Morbi nec neque in turpis suscipit volutpat vitae vitae magna. Donec sed neque quis ipsum varius fringilla id at magna. Fusce tristique vehicula nisi nec pellentesque. Suspendisse volutpat pharetra dolor, non mattis purus aliquet in. Vivamus vitae felis ac elit porttitor porttitor porttitor ut sem. Sed posuere elementum facilisis. Curabitur sagittis, dui nec imperdiet tincidunt, lacus metus placerat arcu, eget rutrum ipsum nisi a sapien. Donec congue tempus elementum. Suspendisse blandit fermentum ultricies. Nullam elementum dignissim interdum.
\paragraph{Paragraph A}
\begin{lstlisting}
void foo( void );
\end{lstlisting}
Phasellus porta lorem vitae risus volutpat laoreet. Nullam a nisl nunc. Morbi eu lorem eget purus pretium volutpat ac a lorem. Praesent bibendum, lorem sed fermentum mollis, nisi sapien pellentesque diam, at dapibus lacus eros sed sapien. Nullam at dapibus magna. In eget fermentum dui. Vestibulum at fermentum quam. Curabitur porta dignissim dui, facilisis imperdiet dui placerat vitae. Praesent ornare sapien eget enim convallis pellentesque.
\paragraph{Paragraph B}
\begin{lstlisting}
void bar( void );
\end{lstlisting}
Maecenas eget nisl at sem imperdiet facilisis. Cras a massa sit amet massa dignissim faucibus eget sed risus. Phasellus dapibus dignissim consequat. Nullam malesuada hendrerit orci, ac lacinia turpis ultrices vel. Aliquam vitae dui vestibulum justo malesuada feugiat. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Maecenas ullamcorper, risus sit amet vehicula consequat, justo eros fermentum magna, sed tempus sem arcu ac tellus. Sed metus justo, dictum sed semper vel, rutrum at diam. Mauris porta blandit pretium. Donec ipsum lorem, rutrum nec commodo vitae, vulputate quis sapien. Vestibulum fringilla elit ut diam pellentesque vehicula. Proin volutpat urna non massa facilisis nec varius elit gravida. Nullam ut lacinia erat. Maecenas adipiscing sagittis erat in malesuada. Pellentesque in nulla eget metus venenatis convallis.
\end{document}
答案1
整洁的 ;-)。
\leavevmode
您可以通过添加(或一些文本)来解决该问题:
\documentclass{article}
\usepackage{listings}
\begin{document}
\paragraph{Paragraph A}
\leavevmode
\begin{lstlisting}
abcdefgh
\end{lstlisting}
\end{document}