8

I'm new to LaTeX and already facing my first problem. I want to change all section titles to small caps in the table of contents but not in the text.

I'm using WriteLaTeX and article as document class.

This is how my document is structured

\documentclass{article}

\begin{document}

\tableofcontents

\newpage
\section{Section 1}
\subsection{Section 1.1}
\subsection{Section 1.2}

\newpage
\section{Section 2}

\newpage
\section{Section 3}
\end{document}
  • 1
    See How to make bold all of the TOC by default?. It might help. – karlkoeller Jul 11 '13 at 9:44
  • You mean section titles only or subsections too? – egreg Jul 11 '13 at 9:55
  • Only section titles – TTurbo Jul 11 '13 at 11:23
  • 1
    The tocloft package will solve your problems, see my answer. But this question could be generalized to something like "How do I change the style of a part of the table of contents?" Answer: The tocloft manual (pp 8-12) provides an overview of all relevant commands. You're likely to find something there. \ctfsecfont, in this case, but tocloft provides commands for parts, chapters, subsections, paragraphs, figures etc. – Emiel Jul 11 '13 at 12:35
11

Optimal Solution

Load the tocloft package and put \renewcommand{\cftsecfont}{\scshape} after it in the preamble. MWE:

\documentclass[11pt]{article}
\usepackage{tocloft}
\renewcommand{\cftsecfont}{\scshape}
\begin{document}

\title{My document}
\maketitle

\tableofcontents

\section{first section}
bla

\subsection{a subsection}
bla

\section{second section}
bla
\end{document}

This will only change the TOC, not your headings.

Subpar solution

If, for any reason, you cannot load tocloft, this is the ugliest hack ever:

% make your sections using \newsection{title}

\newcommand{\newsection}[1]{
\stepcounter{section}
\section*{\arabic{section}. #1}
\addcontentsline{toc}{section}{\scshape \arabic{section}. #1}
}
  • 2
    Note that \sc has been deprecated since 1994; prefer \scshape instead. – egreg Jul 11 '13 at 13:10
  • 1
    Also the \renewcommand{\cftsecfont}{\scshape} should be in the preamble. – egreg Jul 11 '13 at 13:19
  • Noted and edited! – Emiel Jul 11 '13 at 13:35
2

Just for comparison, here's a solution using the titletoc package, the important part is

\titlecontents{section}
[0pt]                                               % left margin
{}%
{\contentsmargin{0pt}                               % numbered entry format
    \thecontentslabel\enspace%
    \large\scshape}
{\contentsmargin{0pt}\large}                        % unnumbered entry format
{\titlerule*[.5pc]{.}\contentspage}                 % filler-page format (e.g dots)
[]                                                  % below code (e.g vertical space)

I loaded the hyperref package just for demonstration.

Here's a complete MWE to play with.

% arara: pdflatex

\documentclass{article}
\usepackage{titletoc}
\usepackage{hyperref}

\titlecontents{section}
[0pt]                                               % left margin
{}%
{\contentsmargin{0pt}                               % numbered entry format
    \thecontentslabel\enspace%
    \large\scshape}
{\contentsmargin{0pt}\large}                        % unnumbered entry format
{\titlerule*[.5pc]{.}\contentspage}                 % filler-page format (e.g dots)
[]                                                  % below code (e.g vertical space)


\begin{document}

\tableofcontents
\loop
\section{Section text}
\ifnum\value{section}<5\repeat

\end{document}
0

The following code will change all the section heading to small-cap font:

\documentclass{article}

\usepackage[T1]{fontenc}

\makeatletter
\renewcommand*\l@section[2]{%
  \ifnum \c@tocdepth >\z@
    \addpenalty\@secpenalty
    \addvspace{1.0em \@plus\p@}%
    \setlength\@tempdima{1.5em}%
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode \bfseries
      \advance\leftskip\@tempdima
      \hskip -\leftskip
      \scshape #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
    \endgroup
  \fi}
\makeatother

\begin{document}

\tableofcontents

\newpage
\section{Section 1}
\subsection{Section 1.1}
\subsection{Section 1.2}

\newpage
\section{Section 2}

\newpage
\section{Section 3}
\end{document}

The command l@section redefined to change all section to small-cap. Package fontenc used to make bold small-cap to appear in the toc.

  • Thanks for your answer but i need just the section titles not the subsection titles to be in small caps – TTurbo Jul 11 '13 at 11:19
  • Ok. Now I updated the code with \l@section redefined for the specific requirement. – Jagath Jul 11 '13 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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