I'm trying to create a Table of Contents but I am having some trouble getting it to look how I want.

At the moment I have the section headings underlined in the document and because of this when the table of contents is generated it underlines all the section headings. So my question is, is there a way to remove the unwanted underlines from the table of contents and keep them in the document.

My .tex file.

\documentclass{article}
\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage[english]{babel}
\usepackage{hyperref}
\hypersetup{
linktoc=all,     %set to all if you want both sections and subsections linked
}
\pagestyle{fancy}
\fancyfoot{} % clear all footer fields
\renewcommand{\footrulewidth}{1pt} % line in footer
\fancyfoot[RE,LO]{\begin{flushleft}\large
name\newline title\end{flushleft}
\begin{flushright} \thepage\end{flushright}}
\begin{document}
\begin{titlepage}
\begin{center}

\end{center}
\end{titlepage}
\tableofcontents
\listoffigures
\listoftables
\newpage

\section{\underline{The Client}}
\subsection{Sub section 1}

\section{\underline{Scope}}
\subsection{Sub Section 2}

\end{document}


Any help would be appreciated.

-

## migrated from stackoverflow.comDec 1 '12 at 14:26

This question came from our site for professional and enthusiast programmers.

Thanks, that will help immensely. However, are all those packages needed to reproduce the problem? Since the problem occurs if you remove all those packages that are not related to the TOC, or the underlined section headings. I might perhaps leave hyperref and the associated code as that does have an effect on the TOC (but problem occurs with or without it). –  Peter Grill Nov 30 '12 at 3:27
@PeterGrill Yes, I need all those packages and I would like to keep the typerref package functionality as im planning on doing my final year thesis in latex. –  user1864284 Nov 30 '12 at 3:37
Yes I know you need those packages, but are they related to this specific problem? They certainly don't appear to be as I get identical results without them. –  Peter Grill Nov 30 '12 at 3:39
@PeterGrill I am new to Latex so I'm not sure. I have noticed that some commands dont work when certain packages are used but im not getting an errors so I presume the packages are not the problem. –  user1864284 Nov 30 '12 at 3:41

Your minimal example produces a ToC that looks like this (in code form):

\contentsline {section}{\numberline {1}\relax $\@@underline {\hbox {The Client}}\mathsurround \z@$\relax }{2}{section.1}
\contentsline {subsection}{\numberline {1.1}Sub section 1}{2}{subsection.1.1}
\contentsline {section}{\numberline {2}\relax $\@@underline {\hbox {Scope}}\mathsurround \z@$\relax }{2}{section.2}
\contentsline {subsection}{\numberline {2.1}Sub Section 2}{2}{subsection.2.1}


Note that each of the \contentsline entries for a \section contains \@@underline. A crude solution would be to redefine \@@underline to be a "no-op" (do nothing) when processing \tableofcontents:

{\makeatletter
\def\@@underline#1{#1}
\tableofcontents
\makeatother}


If only some of your sections require this "special treatment", then manual underlining is most likely the way to go, together with the correction above, or by using the optional argument for sections:

\section[The Client]{\underline{The Client}}


However, for more far-reaching or consistent requirement across your entire document, consider using a package dedicated to sectional titles. For example, sectsty provides an example in its documentation doing exactly this:

\documentclass{article}
\usepackage{sectsty}% http://ctan.org/pkg/secsty
\usepackage[normalem]{ulem}% http://ctan.org/pkg/ulem
\usepackage{xcolor,hyperref}% http://ctan.org/pkg/{xcolor,hyperref}
\hypersetup{
linktoc=all,     %set to all if you want both sections and subsections linked
}
\begin{document}
\tableofcontents
\newpage

\sectionfont{\underline}

\section{The Client}
\subsection{Sub section 1}

\section{Scope}
\subsection{Sub Section 2}

\end{document}


Note the difference in the underlining between the choice of sectsty and that of a manual underline.

-