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.

Mico
  • 506,678
EPK
  • 63
  • Welcome to TeX.sx!. Have you considered using the report class for this? – Mario S. E. Apr 30 '13 at 00: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 00: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 00: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 00:45
  • @user1591288 You can check the differences here: http://tex.stackexchange.com/questions/36988/book-vs-report-vs-article-document-class – Mario S. E. Apr 30 '13 at 00:47
  • You have to lead with two different things: the formating of section header and the type of section counter. You have to change it to Roman and insert an extra word in front of the section name. – Sigur Apr 30 '13 at 00:47
  • @Sigur thank you for being so patient with me. I am still a little confused. What did my \renewcommand command do? Did it format the section headers, or change the type of section counter? If you could provide me with an example, I'd really appreciate it! Thanks. – EPK Apr 30 '13 at 00:50
  • \thesection prints the section counter. You are redefining that counter to print a word and the counter. This is not a good idea. For example, try \section{title}\label{key} In section \ref{key}... with you redefined command. – Sigur Apr 30 '13 at 00:58
  • @Sigur OK, now I understand why I don't want to use the command I tried above. What's my solution? Ultimately, it seems that I need to change the way the section headers are generated (both the work "Article" and the counter from arabic to Roman) but not let this affect the TOC. I'm sorry -- very slow tonight. – EPK Apr 30 '13 at 01:03
  • Look here for titlesec package. – Sigur Apr 30 '13 at 01:19

2 Answers2

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

Gonzalo Medina
  • 505,128
  • 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 02: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.

Mico
  • 506,678
  • 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 01: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 01:44
  • Good advice. One could include it for completeness, and reference your own personal style. Whichever you prefer... – Werner Apr 30 '13 at 01:47