Document ClassesSuppress page number in TOC

Information and discussion about specific document classes and how to create your own document classes.
Post Reply
nettel
Posts: 14
Joined: Wed Oct 08, 2008 11:25 pm

Suppress page number in TOC

Post by nettel »

I need to supress pagenumbers in TOC against only one section. For e.g. I dont want a page number against acknowledgements in the table of contents for the example code i have supplied. Also how do I get rid of the dotted lines on the acknowlegdement line ONLY (in toc).

Note: Not asking to suppress section numbers in toc (using*)....just the PAGE number on a certain line (in this case the ackknowledgements line in toc)

Cheers

Code: Select all

\documentclass[a4paper]{article}
\usepackage{titletoc}
\titlecontents{section}[1.5em]
  {\bfseries}
  {\contentslabel{2em}}
  {\hspace*{-2.3em}}
  {\titlerule*[1pc]{.}\contentspage}

\renewcommand{\thesection}{\Roman{section}} % Numbering format for TOC
\renewcommand{\thesubsection}{\Alph{subsection}}
\renewcommand{\thesubsubsection}{\arabic{subsubsection}}

\begin{center}
\tableofcontents
\end{center}

\begin{document} 

\begin{center}
\section{Introduction}\label{intro} % 1st chapter
\end{center}
\subsection{Background} % sub heading under 1st chapter
   some text....
\subsection{Aim}
   some more text....
\subsection{Scope}
   more text....
\begin{center}
\section{Project Methodology}\label{prometh} % 2nd chapter
\end{center}

\subsection{Requirement for the Project} % sub heading under 2nd chapter
   text.....
\subsection{Redesign of a New Model} % sub heading under 2nd chapter
   text....
\subsection{Summary} % sub heading under 2nd chapter
   text... 
\addcontentsline{toc}{section}{Acknowledgements}
\section*{Acknowledgements} % Want no page number for this in toc

     
\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Suppress page number in TOC

Post by localghost »

You can add your acknowledgments without pagenumber by a slightly different command.

Code: Select all

\section*{Acknowledgements}            % Want no page number for this in toc
\addtocontents{toc}{Acknowledgements}
You may have to format this entry a little bit in the second argument (i.e. \bfseries, \large, ...) to get it suitable as a section entry.


Best regards
Thorsten¹
nettel
Posts: 14
Joined: Wed Oct 08, 2008 11:25 pm

Suppress page number in TOC

Post by nettel »

Thanks for the help that worked and as you mentioned now comes the formatting. Im new to Latex and i dont quite understand how to apply formating to make it look like say the Introduction line in the toc from example code. i.e. make it ragged left, bold, and larger text. Im sure this is a simple amendment so if someone could help it would be appreciated.

cheers

amended code example below...need to make acknowlegement line in toc as follows....ragged left, bold, and larger text (just like intoduction line but keep it as no page number or section number)
\documentclass[a4paper]{article}
\usepackage{titletoc}
\titlecontents{section}[1.5em]
{\bfseries}
{\contentslabel{2em}}
{\hspace*{-2.3em}}
{\titlerule*[1pc]{.}\contentspage}

\renewcommand{\thesection}{\Roman{section}} % Numbering format for TOC
\renewcommand{\thesubsection}{\Alph{subsection}}
\renewcommand{\thesubsubsection}{\arabic{subsubsection}}

\begin{center}
\tableofcontents
\end{center}

\begin{document}

\begin{center}
\section{Introduction}\label{intro} % 1st chapter
\end{center}
\subsection{Background} % sub heading under 1st chapter
some text....
\subsection{Aim}
some more text....
\subsection{Scope}
more text....
\begin{center}
\section{Project Methodology}\label{prometh} % 2nd chapter
\end{center}

\subsection{Requirement for the Project} % sub heading under 2nd chapter
text.....
\subsection{Redesign of a New Model} % sub heading under 2nd chapter
text....
%\subsection{Summary} % sub heading under 2nd chapter
text...

\section*{Acknowledgements} % Want no page number for this in toc
\addtocontents{toc}{Acknowledgements}

\end{document}
nettel
Posts: 14
Joined: Wed Oct 08, 2008 11:25 pm

Re: Suppress page number in TOC

Post by nettel »

Can anyone help here?
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Suppress page number in TOC

Post by Juanjo »

Try this:

Code: Select all

\documentclass[a4paper]{article}

% ----- ToC format -----
\usepackage{titletoc}
\titlecontents{section}[2em]
{\addvspace{1.0em plus 1pt}\bfseries}
{\contentslabel{2em}}
{\hspace*{-2em}}
{\titlerule*[0.8pc]{.}\contentspage}

\titlecontents{subsection}[4.8em]
{}
{\contentslabel{2.8em}}
{\hspace*{-2.8m}}
{\titlerule*[0.8pc]{.}\contentspage}
% ----------------------

% ----- Redefinition of \section -----
% Needed to center its title
\makeatletter
\renewcommand\section{\@startsection{section}{1}{0pt}%
             {-3.5ex plus -1ex minus -.2ex}%
             {2.3ex plus.2ex}%
             {\normalfont\Large\bfseries\centering}}
\makeatother
% ------------------------------------

\renewcommand{\thesection}{\Roman{section}} % Numbering format for TOC
\renewcommand{\thesubsection}{\Alph{subsection}}
\renewcommand{\thesubsubsection}{\arabic{subsubsection}}

\usepackage{lipsum} % Just to write blind text. Defines \lipsum

\begin{document} 

\tableofcontents
\section{Introduction}\label{intro} % 1st chapter

\subsection{Background} % sub heading under 1st chapter
\lipsum[1]
\subsection{Aim}
\lipsum[2]
\subsection{Scope}
\lipsum[3]

\section{Project Methodology}\label{prometh} % 2nd chapter

\subsection{Requirement for the Project} % sub heading under 2nd chapter
\lipsum[4]
\subsection{Redesign of a New Model} % sub heading under 2nd chapter
\lipsum[5]
\subsection{Summary} % sub heading under 2nd chapter
\lipsum[6] 

% Redefinition of the ToC format for sections, adapted to Acknowledgements
\titlecontents{section}[2em]
{\addvspace{1.0em plus 1pt}\bfseries}
{\contentslabel{2em}}
{\hspace*{-2em}}
{}

\section*{Acknowledgements} % Want no page number for this in toc
\addcontentsline{toc}{section}{Acknowledgements}
\lipsum[7]
\end{document}
Remarks:
  • Your code wasn't compilable. The center environment in the preamble yields an error. The preamble is reserved for settings and definitions. No text intended to appear in the document should be written there.
  • It is a bad idea to put sectioning commands inside environments to modify their format. Don't write \section inside center. Just redefine \section. This can be done directly or by means of a package (titlesec, sectsty...)
  • If you change the ToC format of sections, you should also modify, at least, that of subsections accordingly. If not, the shape of the dotted lines is inconsistent.
  • From the {\contentslabel{2em} command in your code, I guess that you want to add 0.5em to the label width of sections in the ToC. with respect to the usual width. I've added it also to subsections.
  • The \titlecontents command can be used anywhere in the document. That's the trick to change specifically the format of the acknowledgements in the ToC.
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
nettel
Posts: 14
Joined: Wed Oct 08, 2008 11:25 pm

Suppress page number in TOC

Post by nettel »

Thankyou Juanjo...worked perfectly and thanks for the other suggestions as well. Just curious though what part of the code made the numbers disappear in the TOC?


Cheers

Code: Select all

% Redefinition of the ToC format for sections, adapted to Acknowledgements
\titlecontents{section}[2em]
{\addvspace{1.0em plus 1pt}\bfseries}
{\contentslabel{2em}}
{\hspace*{-2em}}
{}
phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

Re: Suppress page number in TOC

Post by phi »

The sixth argument for \titlecontents receives the text that should be printed as page number. For all sections but the acknowledgment, this was "\titlerule*[0.8pc]{.}\contentspage" (i.e., a horizontal rule and the page number); for the acknowledgment section, it is just made empty.
nettel
Posts: 14
Joined: Wed Oct 08, 2008 11:25 pm

Re: Suppress page number in TOC

Post by nettel »

Thankyou makes sense.
Post Reply