Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

So, I'm trying to use the listings package for some code samples in my document. When I converted my verbatim sections to lstlisting my paragraph titles disappeared. I've attached some example code with an identical preamble to my actual document. Any one see anything that would cause this?

Before:

before

After:

after

\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}
share|improve this question
    
A MWE should actually illustrate the problem - in this case there is no use of the lstlisting environment. –  Peter Grill Sep 14 '12 at 16:30
1  
\paragraph titles are set in-line; add \mbox{} after the title. –  egreg Sep 14 '12 at 16:31
    
Whoops. Made the examples in reverse order and accidentally posted the wrong one. Edited original post to have correct example. –  blitzvergnugen Sep 14 '12 at 16:38
add comment

1 Answer

up vote 6 down vote accepted

Neat ;-).

You can get around the problem by adding a \leavevmode (or some text):

\documentclass{article}
\usepackage{listings}
\begin{document}
\paragraph{Paragraph A}
\leavevmode
\begin{lstlisting}
abcdefgh
\end{lstlisting}
\end{document}
share|improve this answer
    
Annoying that the commands interact this way, but thanks for the solution. –  blitzvergnugen Sep 14 '12 at 17:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.