I have a common document type (grant application) which expects listed aims, usually enumerated as Aim 1, Aim 2, etc. In the MWE below, an article class works fine to format the subsection headings appropriately within the document, but I'm having trouble with the TOC. I'm changing \thesubsection and using \titleformat from the titlesec package in anticipation of using the titletoc package to change the toc formatting of entries from within a defined aims environment. I want the aims to be listed in the TOC as Aim 1, Aim 2, etc.
What I'm running into:
- The
\titlecontentssettings I set as part of theaimsenvironment appears to persist after the end of the environment. This is different from the\titleformatsettings, which are local. - Unlike the
\titleformatsettings in thetitlesecpackage, the default\titlecontentsintitletocare not listed in the documentation, so my attempt to alter the default settings is trial and error (at this point, all error, since I can't get it working). Thetitlesecexamples are invaluable; are there similar examples fortitletoc?
MWE follows
\documentclass[11pt]{article}
\usepackage {blindtext}
\usepackage {titlesec}
\usepackage {titletoc}
\newenvironment {aims} {
\renewcommand{\thesubsection}{{\arabic{subsection}}}
\titleformat{\subsection}{\normalfont\large\bfseries}{Aim
\thesubsection}{1em}{}
% example from titletoc docs to show that \titlecontents
% changes persist outside the group
\titlecontents{subsection} [3.8em]
{}{\contentslabel{5em}}{\hspace*{-5em} Aim }
{\titlerule*[1pc]{.}\contentspage}
}{}
\title {A document}
\author{me}
\begin{document}
\maketitle
\tableofcontents
\section {Introduction}
\blindtext
\begin {aims}
\section {Aims}
\subsection {This is an aim}
\blindtext
\subsection {This is another aim}
\blindtext
\end {aims}
\section {Details}
\blindtext
\subsection {Some more details}
\blindtext
\end{document}

aimsenvironment). So, of course, modifying\titlecontentswould have an effect outside theaimsenvironment. Why not create a different macro for your aims so that you can treat them differently in the ToC? – Werner Jan 7 at 6:28\titlecontentsthat I could slot in at the closing of theaimsenvironment. Even if I created a different macro for aims, rather than temporarily hijacking the\subsectionformatting, I'd still use the examples if I had them. – GTK Jan 7 at 6:48