11

I'm writing a book in which I would like certain sections to have a "surtitle" like this:

enter image description here

I would probably like the table of contents entry to look like "Science and Society: The Galileo Affair," and the page header to say "The Galileo Affair."

The closest I can think of is something like this:

\section[The Galileo Affair]{Science and Society: The Galileo Affair}

But this won't give me the visual layout shown above, and the initial part of the title won't appear in the TOC.

Is there any package that gives a straightforward way to accomplish this?

3
  • titlesec may be able to do this, but with complicated layouts I generally just start a document class from scratch. Then again, I have a tendency to re-invent the wheel. Jan 10, 2015 at 20:06
  • Is this the equivalent of the \part? Jan 10, 2015 at 20:18
  • @UweZiegenhagen: No, the surtitle only applies to section 1.7 in my example. Section 1.8 would not be about science and society.
    – user6853
    Jan 10, 2015 at 20:27

2 Answers 2

15

You can try this code. Use \sectionsurtitle{....} before the sections where you want the surtitle. Note that you can used a starred version \sectionsurtitle* for unnumbered sections.

\documentclass{scrartcl}
\usepackage{lipsum}

\usepackage{suffix}

\newcommand\sectionsurtitle[1]{\surtitletoc{#1}\printsectionsurtitle{#1}}
\WithSuffix\newcommand\sectionsurtitle*[1]{\printsectionsurtitle{#1}}

\makeatletter
\newcommand{\printsectionsurtitle}[1]{%
  {\parindent0pt\vspace*{20pt}%
  \sffamily\uppercase{#1}%
  \par\nobreak}
  \@afterheading%
}
\newcommand{\surtitletoc}[1]{%
  \addtocontents{toc}{%
    \protect\contentsline{section}%
    {\mdseries\sffamily\protect\scriptsize\uppercase{#1}}{}{}}
  \addtocontents{toc}{\vskip-10pt}%
}
\makeatother

\begin{document}
\tableofcontents

\bigskip

\sectionsurtitle{Science and society}
\section{The Galileo Affair}
\lipsum[1]

\sectionsurtitle{Art}
\section{The Michelangelo Affair}
\lipsum[1]

\section{A normal section}
\lipsum[1]

\sectionsurtitle*{Nothing}
\section*{A unnumbered section}
\lipsum[1]
\end{document} 

Output:

enter image description here


EDIT

After your comment I think that you can use this code:

\documentclass{scrbook}
\usepackage{lipsum}

\usepackage{suffix}

\newcommand\sectionsurtitle[2]{\printsectionsurtitle{#1}\section[#1: #2]{#2}\sectionmark{#2}}
\WithSuffix\newcommand\sectionsurtitle*[2]{\printsectionsurtitle{#1}\section*{#2}}

\makeatletter
\newcommand{\printsectionsurtitle}[1]{%
  {\parindent0pt\vspace*{20pt}%
  \sffamily\uppercase{#1}%
  \par\nobreak}
  \@afterheading%
}
\makeatother

\begin{document}
\tableofcontents

\bigskip

\chapter{Test}

\sectionsurtitle{Science and society}{The Galileo Affair}
\lipsum[1]

\sectionsurtitle{Art}{The Michelangelo Affair}
\lipsum[1]

\section{A normal section}
\lipsum[1]

\sectionsurtitle*{Nothing}{A unnumbered section}
\lipsum[1]
\end{document} 

Output:

enter image description here

and the ToC

enter image description here

2
  • Thanks, that was very helpful! I had in mind something slightly different for the table of contents. Also, since I have leading dots in my ToC, your code produced an extra line of them. What worked for me was to do the following variation on your code: \newcommand\sectionwithsurtitle[3]{\printsectionsurtitle{#1}\section[#1: #3]{#2}\sectionmark{#3}}
    – user6853
    Jan 10, 2015 at 21:03
  • @BenCrowell You're welcome. See the edit. Jan 10, 2015 at 21:54
6

I'd go with a key-value syntax:

\documentclass[openany]{book}
\usepackage{titlesec}
\usepackage{xparse}

\titleformat{\section}
  {\normalfont\Large\sffamily\printcurrentsurtitle}
  {\thesection}
  {1em}
  {}

\ExplSyntaxOn

\keys_define:nn { crowell/section }
 {
  surtitle .tl_set:N = \l_crowell_section_surtitle_tl,
  toc      .tl_set:N = \l_crowell_tocentry_tl,
  header   .tl_set:N = \l_crowell_header_tl,
 }

\NewDocumentCommand{\Section}{sO{}m}
 {
  \keys_set:nn { crowell/section }
   {
    surtitle = {},
    toc = { #3 },
    header = { #3 },
    #2
   }
  \IfBooleanTF{#1}
    {\section*{#3}}
    {
     \section[
       \tl_if_empty:NF \l_crowell_section_surtitle_tl
        { \l_crowell_section_surtitle_tl : ~ }
       \l_crowell_tocentry_tl
     ]{#3}
     \markright{\l_crowell_header_tl}
    }
 }

\NewDocumentCommand{\printcurrentsurtitle}{ }
 {
  \tl_if_empty:NF \l_crowell_section_surtitle_tl
   {
    \mbox{\normalsize\MakeUppercase{\l_crowell_section_surtitle_tl}}\par
   }
 }

\ExplSyntaxOff

\begin{document}

\tableofcontents

\chapter{Title}

\Section[surtitle=Science and Society]{The Galileo Affair}

\Section{No surtitle for this one}

\Section*[surtitle=Unnumbered]{Section}

\Section[
  surtitle=Science and Society,
  header=TGA,
  toc=Abbrev
]{The Galileo Affair}

\newpage
\mbox{}

\end{document}

enter image description here

Here is the TOC

enter image description here

Note that the value given for toc= is what's added next to the surtitle in the TOC; in the header you'll get the section title, or what's specified as value for header= (in this case page 3 will have “TGA”.

You must log in to answer this question.