6

I'm looking to have different 'styles' (not sure if this is the right word) for my section headers depending on whether they're listed in the TOC or the body. That's probably not clear, so let me demonstrate.

In the body, I'd like to see:

Article I. Intro 
....
Article II. Methods
....

But in the TOC I'd like to see

I. Intro .......... 5
II. Methods ........10

without the "Article" bit.

Right now, I'm using this to set the section headers:

\renewcommand{\thesection}{Article \Roman{section}.}

I should mention I'm using the article class.

  • Welcome to TeX.sx!. Have you considered using the report class for this? – Mario S. E. Apr 30 '13 at 0:24
  • 1
    Don't change that command as you did. You can use another word to insert in the TOC. Just write \section[to appear in TOC]{to appear in the body}. – Sigur Apr 30 '13 at 0:33
  • @Sigur I think what you're suggesting is \section[Intro]{Article I. Intro}. But then the TOC shows 1 Intro ... 5 but the body shows 1 Article I. Intro which is not what I want. I could use /section* but then I need to \addcontentsline all of the time. – EPK Apr 30 '13 at 0:40
  • @MarioS.E. I'm unclear on how report would help. Doesn't this just add an extra chapter level? – EPK Apr 30 '13 at 0:45
  • @user1591288 You can check the differences here: tex.stackexchange.com/questions/36988/… – Mario S. E. Apr 30 '13 at 0:47
7

The titlesec package was used to add "Article" before the section number and the dot after the number. The tocloft package was used to add the dot after the number in the table of contents entries and also to increase the space reserved for the number:

\documentclass{article}
\usepackage{titlesec}
\usepackage{tocloft}

\renewcommand\thesection{\Roman{section}}
\titleformat{\section}
  {\normalfont\Large\bfseries}{Article~\thesection.}{1em}{}
\renewcommand\cftsecaftersnum{.}
\addtolength\cftsecnumwidth{1em}

\begin{document}

\tableofcontents
\section{Introduction}
\section{Methods}

\end{document}

enter image description here

  • Thank you! Took a little debugging to get the spacing right, but this fixed my problem, and is really simple. – EPK Apr 30 '13 at 2:14
3

You could use the method described on p. 26f. of "The LaTeX Companion" to generate the following output:

enter image description here

\documentclass{article}
\renewcommand{\thesection}{\Roman{section}}
\makeatletter
%% The "\@seccntformat" command is an auxiliary command
%% (see pp. 26f. of 'The LaTeX Companion,' 2nd. ed.)
\def\@seccntformat#1{\@ifundefined{#1@cntformat}%
  {\csname the#1\endcsname\ }%   default
  {\csname #1@cntformat\endcsname}% enable individual control
}
%% Put everything together by defining the macros 
%% '\...@seccntformat', where ... can be 'section', 
%% 'subsection', etc.
\newcommand{\section@cntformat}{Article \thesection. }
\makeatother

\begin{document}
\tableofcontents
\section{Intro}
\section{Methods}
\end{document}

Addendum: You've probably noticed that this method does not insert a period (full stop) after the Roman section number in the table of contents. (I'm not a fan of providing punctuation marks needlessly...) If you do require the dots following the Roman section numbers in the ToC, be sure load the tocloft package and issue the command \renewcommand\cftsecaftersnum{.} (in the preamble, of course). And, if you need the line of dots between the ToC-style section headers and the associated page numbers, you should issue the command \renewcommand\cftsecleader{\cftdotfill{\cftdotsep}} after loading the tocloft package.

  • You may also wish to update the ToC entries to print a period after the number. Most likely a redefinition of \numberline using a similar technique or otherwise. – Werner Apr 30 '13 at 1:42
  • @Werner - I personally don't think it's good form to provide (unnecessary) periods. However, I'll provide a comment to show how one might add them to the ToC listing, if they're needed. – Mico Apr 30 '13 at 1:44
  • Good advice. One could include it for completeness, and reference your own personal style. Whichever you prefer... – Werner Apr 30 '13 at 1:47

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.