3

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
\documentclass{memoir}

\setsecnumdepth{subsection}
\settocdepth{subsection}

\usepackage{libertine}
\usepackage{polyglossia}
    \setdefaultlanguage[variant=british]{english}
    \setotherlanguage[]{french}
    \setotherlanguage[spelling=old]{german}
\usepackage[%
    xetex,bookmarks,
    colorlinks=true,linkcolor=blue,citecolor=blue,filecolor=black,urlcolor=blue,breaklinks=true,
    pdftitle={Karljürgen G. Feuerherm---Abum--waqar and His Circle},
    pdfauthor={Karljürgen G. Feuerherm},
    unicode
    ]{hyperref}

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

% In the real application, this counter is cycled through 137 texts.
\newcounter{awednum}
\setcounter{awednum}{1}

\begin{document}
\frontmatter
\tableofcontents

\mainmatter
\chapter{Main Matter Chapter}

\appendix
\chapter{Appendix Chapter}
\section{Editions}\label{A.1}
% 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'.
\setsubsecheadstyle{\normalfont\centering}
\counterwithout{subsection}{section}
\setsecnumformat{\textsc{aw~}\csname the#1\endcsname:\quad}
% There will be one subsection for each document, identified by counter
\subsection{%
    \expandafter\csname awcoll\roman{awednum}\endcsname~%
    \expandafter\csname awcollno\roman{awednum}\endcsname%
}\label{aw:\arabic{awednum}}
Body text for first document with reference to document number \ref{aw:1}.

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

\end{document}

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:

\makepagestyle{olmseditions}
\makeevenhead{olmseditions}{\thepage}{\leftmark}{}
\makeoddhead{olmseditions}{}{\rightmark}{\thepage}
\makeatletter
\makepsmarks{olmseditions}{%
    \createmark{chapter}{both}{shownumber}{\@chapapp\ }{:\space}
    \makeatother
    \createmark{subsection}{right}{shownumber}{\textsc{aw}}{:\ }
    \createplainmark{toc}{both}{\contentsname}
    \createplainmark{lof}{both}{\listfigurename}
    \createplainmark{lot}{both}{\listtablename}
    \createplainmark{bib}{both}{\bibname}
    \createplainmark{index}{both}{\indexname}
    \createplainmark{glossary}{both}{\glossaryname}
}

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

1 Answer 1

2

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.

1
  • 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. Commented 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 .