3

I would like to create a new command \exsec that behaves like \section with the properties below. I am using the book class.

  1. It produces a heading with the same formatting as \section, except it is numbered alphabetically rather than numerically.

  2. \subsection should be subordinate to \exsec. (This isn't strictly necessary.)

  3. It has an independent counter from \section that is reset with each \part but not reset with each chapter.

  4. It produces entries in the table of contents just like \section does except labelled alphabetically.

  5. It produces entries in the PDF index just like \section does.

(Note: I am not trying to label my sections alphabetically. I want to have two commands, \section and \exsec that behave independently.)

I have achieved 1-4 with the following code:

\documentclass{book}

\usepackage{chngcntr}
\usepackage[colorlinks=true]{hyperref}



\counterwithout{section}{chapter}

\newcounter{exsec}
\setcounter{exsec}{0}
\renewcommand{\theexsec}{\Alph{exsec}}


\makeatletter
\let\exsecmark\@gobble

\def\l@exsec#1#2{ \@dottedtocline{1}{1.5em}{2.3em}{#1}{#2}}
\long\def\exsec#1{%
\setcounter{subsection}{0}
\renewcommand{\thesubsection}{\Alph{exsec}.\arabic{subsection}}
\@startsection {exsec}{1}{\z@ }{-3.5ex \@plus -1ex \@minus -.2ex}{2.3ex \@plus .2ex}{\normalfont \Large \bfseries }{#1}
}

\long\def\section#1{%
\setcounter{subsection}{0}
\renewcommand{\thesubsection}{\arabic{section}.\arabic{subsection}}
\@startsection {section}{1}{\z@ }{-3.5ex \@plus -1ex \@minus -.2ex}{2.3ex \@plus .2ex}{\normalfont \Large \bfseries }{#1}
}

\makeatother



\begin{document}

\tableofcontents

\part{The first part}

\section{A section}

\exsec{The other kind of section}

\section{Another section}

In the PDF table of contents, this section is listed as a subsection of Section A.

\exsec{Another one of the other kind}

\chapter{A chapter}

This one is also listed as a subsection instead of a chapter.


\end{document}

As indicated above, this code fails to achieve 5. What is the right way to do this to make 5 work as well? Thanks for your help.

2

The following seems to adhere to your requirements:

enter image description here

\documentclass{book}

\usepackage{chngcntr}
\usepackage{bookmark}% Loads hyperref
\hypersetup{colorlinks=true}

\newcounter{exsec}

\counterwithout{section}{chapter}
\counterwithout{exsec}{chapter}
\counterwithin{subsection}{exsec}
\counterwithin*{exsec}{part}

\renewcommand{\theexsec}{\Alph{exsec}}

\makeatletter
\def\toclevel@exsec{1}
\let\exsecmark\@gobble

\let\l@exsec\l@section
\long\def\exsec#1{%
  \renewcommand{\thesubsection}{\theexsec.\arabic{subsection}}%
  \renewcommand{\theHsubsection}{ex.\theexsec.\arabic{subsection}}%
  \@startsection {exsec}{1}{\z@ }{-3.5ex \@plus -1ex \@minus -.2ex}{2.3ex \@plus .2ex}{\normalfont \Large \bfseries }{#1}%
}

\long\def\section#1{%
  \renewcommand{\thesubsection}{\thesection.\arabic{subsection}}%
  \renewcommand{\theHsubsection}{\theexsec.\arabic{subsection}}%
  \@startsection {section}{1}{\z@ }{-3.5ex \@plus -1ex \@minus -.2ex}{2.3ex \@plus .2ex}{\normalfont \Large \bfseries }{#1}%
}
\makeatother

\begin{document}

\tableofcontents

\part{The first part}

\section{A section}

\exsec{The other kind of section}
\subsection{A subsection}

\section{Another section}
\subsection{Another subsection}

\exsec{Another one of the other kind}

\chapter{A chapter}

\section{A section}

\exsec{The other kind of section}
\subsection{A subsection}

\section{Another section}
\subsection{Another subsection}

\exsec{Another one of the other kind}

\end{document}

For proper hyperlinking of content at the same structural level (\exsec and \section), you need to be careful. Adjustment of appropriate H-counters is also required, otherwise your hyperlinking will not work as expected.

  • How would I need to change it in order to behave like \chapter rather than \section? – Joel Duscha May 21 '16 at 23:47
  • @JoelDuscha: Both \chapter and \section is used in the example. If you have a follow-up question, I'd suggest asking anew. – Werner May 22 '16 at 6:12

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.