In the following MWE, the subsection numbering within a given appendix is to be customized to look like 'Aw nnn: XXX mmmm', where 'Aw' should appear at the start of each header, 'nnn' is a running number (from 1 through 137), 'XXX' and 'mmmm' are identifiers pulled from a script generated LaTeX 'database'. In addition, the label is autogenerated and will be referenced throughout the other chapters.

The code below works fine, as far as the appendix itself is concerned:

enter image description here

However, the TOC shows only the subsection number; I would like it to show 'Aw 1', 'Aw 2', etc.:

enter image description here

(Also due to the cutting of chapter and section number in the TOC, it appears that the whitespace may need to be shrunk a little but that's a secondary concern.)

I have tried to internalize the information in the memoir documentation, but in vain. Here's the MWE (polyglossia and hyperref retained though not directly relevant in the event there are side effects):

% !TEX TS-program = xelatexmk


    pdftitle={Karljürgen G. Feuerherm---Abum--waqar and His Circle},
    pdfauthor={Karljürgen G. Feuerherm},

\newcommand{\awset}[3]{% #1 specifies document number, #2 the field, and #3 the value
\expandafter\def\csname aw#2\roman{awcounter}\endcsname{#3}%
% The following is extracted from a larger script-generated database setup.

% In the real application, this counter is cycled through 137 texts.


\chapter{Main Matter Chapter}

\chapter{Appendix Chapter}
% From here on, the format of subsection headers should be as follows:
% * normal font, centred
% * subsection headers should show only their own counter, prefixed by 'aw'.
\setsecnumformat{\textsc{aw~}\csname the#1\endcsname:\quad}
% There will be one subsection for each document, identified by counter
    \expandafter\csname awcoll\roman{awednum}\endcsname~%
    \expandafter\csname awcollno\roman{awednum}\endcsname%
Body text for first document with reference to document number \ref{aw:1}.

    \expandafter\csname awcoll\roman{awednum}\endcsname~%
    \expandafter\csname awcollno\roman{awednum}\endcsname%
Body text for second document with reference to document number \ref{aw:2}.


Following up on Werner's solution below:

Werner's first solution is precisely what I needed: only this portion of this particular appendix should behave this way (each subsection governs the edition of a particular ancient text), and in this way, each is referenceable.

I omitted to mention, however, that the page headers should also reflect this, which I solved with an alteration to the pagestyle, as follows:

    \createmark{chapter}{both}{shownumber}{\@chapapp\ }{:\space}
    \createmark{subsection}{right}{shownumber}{\textsc{aw}}{:\ }

This works, though I am not sure whether this is the best comprehensive solution....

1 Answer 1


Two cases present itself:

  1. All of your \subsections have the AW-style numbering;

  2. Some of your \subsections have the AW-style numbering.

In the second case, the following provides a solution. Immediately before calling your first AW-style \subsection, add the lines

\addtocontents{toc}{\protect\renewcommand{\protect\cftsubsectionpresnum}{\textsc{aw}}}% Prefix to number for \subsection in ToC
\addtocontents{toc}{\protect\setlength{\protect\cftsubsectionnumwidth}{3em}}% Width of number for \subsection in ToC

These lines insert an adjustment to the macros responsible for setting the \subsection number and its width within the ToC. The strategic placement of these commands ensure that they only affect those \subsections following this statement.

As soon as you want the above adjustments to revert back to the original, or to something else altogether, you can write another change to the ToC. For example,

\addtocontents{toc}{\protect\renewcommand{\protect\cftsubsectionpresnum}{}}% Remove prefix to number for \subsection in ToC
\addtocontents{toc}{\protect\setlength{\protect\cftsubsectionnumwidth}{4em}}% Width of number for \subsection in ToC

Alternatively, one can also write a scoping \begingroup...\endgroup pair to the ToC within which changes can be automatically restored once the group is closed/left.

enter image description here

In the first case (with all \subsections having the same AW-style, you can update \cftsubsectionpresnum and the length \cftsubsectionnumwidth within the preamble, rather than writing content to the ToC. The effect will be global to the document rather than having limited scope.

  • First solution does what I originally said I needed though I omitted to note the requirement to echo this in the appendix page headers; edited the original question with a potential solution to this aspect of the problem. Oct 25, 2017 at 14:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .