10

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}
egreg
  • 1,121,712
TTurbo
  • 103

3 Answers3

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}
}
Emiel
  • 1,237
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}
cmhughes
  • 100,947
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 is redefined to change all section to small-cap. Package fontenc is used to make bold small-cap to appear in the ToC.

fidekild
  • 151
Jagath
  • 4,287
  • 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