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.

I'm struggeling a little bit with the display of table of contents. I had previously a problem using natbib , and now the same issue with listings. Maybe I'm mixing something up with documentclass article and how to reat it.

That's a sample stating the issue:

\documentclass
[
a4paper,
english,
twoside,
11pt
]
{article}

\usepackage[pdftex]{graphicx}
\usepackage{float}           
\usepackage{amstext}         
\usepackage{enumerate}        
\usepackage[bottom]{footmisc} 
\usepackage{array}            
\usepackage{ntheorem}
\usepackage{theorem}
\usepackage{pdfpages}         
\usepackage{parskip}          
\usepackage{xcolor}           
\usepackage[hyphens]{url}     
\usepackage{makeidx}          
\usepackage{multicol}         
\usepackage[numbers, square]{natbib}  
\usepackage{listings}
\usepackage{hyperref}
\hypersetup{%
    pdfborder = {0 0 0}
}
%\usepackage{url}
\sloppy

\makeindex 



\setlength{\unitlength}{1cm}
\setlength{\oddsidemargin}{0.3cm}
\setlength{\evensidemargin}{0.3cm}
\setlength{\textwidth}{15.5cm}
\setlength{\topmargin}{-1.2cm}
\setlength{\textheight}{23cm}
\columnsep 0.5cm

\renewcommand{\bibsection}{\section{\refname}}


\begin{document}


%%%%%%%%%%



\normalsize

%%%%%%%%%%
\pagestyle{plain}
\pagenumbering{arabic}
\setcounter{page}{3}
\tableofcontents
\cleardoublepage


%%%%%%%%%%%

\cleardoublepage
%\phantomsection

%\nocite{*}
%\bibliographystyle{plainnat} 
%\setlength{\bibsep}{3mm} 





\lstset{language=[Objective]C, breakindent=20pt, breaklines, tabsize=1,
caption={Change Identifiers}}
\small
\begin{lstlisting}

- (void) myMethod
{
    NSLog(@"Hello there");
}

\end{lstlisting}

\cleardoublepage
\addcontentsline{toc}{chapter}{Listings}
\lstlistoflistings
%\interlinepenalty=100

%%%%%%%%%%%
\newpage                                    
\pagestyle{empty}
\centering

\  






\end{document}

The Listings is dipslayed as Listings1, but the pagenumber should be right aligned. Can someone point me to the solution, or what I'm doing wrong?

share|improve this question
    
Your example is using the report documentclass. Also, compiling your example as-is shows Contents with an entry for the (List of) Listings. T he provided listing has the appropriate page number (5) right aligned, similar to the Contents. Perhaps the above example does not duplicate your problem? –  Werner Aug 23 '11 at 19:51
    
Hey Werner, I'm sorry I was messing around figuring out the problem, indee changing the document to report, the listing is displayed correct in the TOC, but my actual document uses article sorry for the confusion! –  80leaves Aug 23 '11 at 20:20

1 Answer 1

up vote 3 down vote accepted

Instead of

\addcontentsline{toc}{chapter}{Listings}

you can use

\addcontentsline{toc}{section}{\protect\numberline{1}{Listings}}

to produce a section-like entry with the listing number and the page number, or

\addcontentsline{toc}{section}{\protect\numberline{}{Listings}}

if you don't want the listing number to appear, but you want to preserve the indentation of an section-like entry, or

\addcontentsline{toc}{section}{Listings}

if you don't want the listing number nor the indentation. A little example showing the three options:

\documentclass{article}

\begin{document}
\tableofcontents
\addcontentsline{toc}{section}{\protect\numberline{1}{Listings}}
\addcontentsline{toc}{section}{\protect\numberline{}{Listings}}
\addcontentsline{toc}{section}{Listings}
\end{document}

enter image description here

P.S.: note that the article document class doesn't support chapter-like sectional units.

share|improve this answer
    
Thx Gonzalo, that sorted out my confusion! :P –  80leaves Aug 23 '11 at 22:48

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.