2

I would like to create a new section-type heading called assumption. The header must also appear in the Table of contents. So far I have managed to create the heading, but I ma failing to find a way to have it appear in the table of contents. I would like it to appear as a section would in the toc: Chapter number.headercounter-number, for example: 1.2 Assumption Header 1 Also, I created a new label format and would like the chapter number to also appear. See the attached MWE and kindly advise:

\documentclass[a4paper,12pt]{report}
\usepackage[english]{babel}

\newcounter{assumption}[section]
\newenvironment{assumption}[1][\unskip]{\large\refstepcounter{assumption}\medskip
\noindent{\textbf{Assumption~\thechapter.\theassumption. {\large}#1} \\} \addcontentsline{toc}{assumption} \rmfamily}{\medskip}
\newcommand{\assumptionlabel}[2]{%
\protected@write \@auxout {}{\string \newlabel {#1}{{#2}{}}}
\hypertarget{#1}{#2}}

\begin{document}
\tableofcontents
\chapter{Assumptions Chapter}
\assumption[Assumption Header]
\label{assumptionlabel:some-assumption}
Some assumption text.

\assumption[Assumption Header]
\label{assumptionlabel:some-assumption2}
Some assumption text with reference to Assumption \ref{assumptionlabel:some-assumption}.\\
Instead, I would like:\\
Some assumption text with reference to Assumption 1.1
\end{document}
2

The line

\addcontentsline{toc}{assumption}

does not work, since assumption is no known ToC entry type like section etc, i.e. there is no \l@assumption macro yet, but this can be solved by

\makeatletter
\let\l@assumption\l@section
\makeatother

in order to use the relevant \l@section instead.

Now

\addcontentsline{toc}{assumption}{\protect\numberline{\theassumption}#1}

will provide the number and the title of the assumption in the ToC on section level.

Now for the label issue: Redefine \@currentlabel to make the cross-referencing format as desired, without explicit \hypertarget - statements -- hyperref is sophisticated enough to 'guarantee' correct hyper anchors if there are correct labels.

\documentclass[a4paper,12pt]{report}
\usepackage[english]{babel}
\usepackage{hyperref}

\newcommand{\assumptionname}{Assumption}
\newcounter{assumption}[section]
\makeatletter
\let\toclevel@assumption\toclevel@section% Providing bookmark support
\let\l@assumption\l@section

\newenvironment{assumption}[1][\unskip]{%
  \large\refstepcounter{assumption}%
  % Specific label format
  \protected@edef\@currentlabel{\csname p@assumption\endcsname\assumptionname\ \thechapter.\csname theassumption\endcsname}%
  \medskip%
  \noindent\textbf{\assumptionname~\thechapter.\theassumption.\ \large #1}
  \addcontentsline{toc}{assumption}{\protect\numberline{\thechapter.\theassumption}#1}%
  \medskip% % Empty line here!!!
  \parindent0em

  \rmfamily%
}{\medskip}%
\makeatother


\begin{document}
\tableofcontents
\chapter{Assumptions Chapter}
\begin{assumption}[Assumption Header]
\label{assumptionlabel:some-assumption}%
Some assumption text. \ref{assumptionlabel:some-assumption2}
\end{assumption}

\clearpage
\begin{assumption}[Assumption Header]
  \label{assumptionlabel:some-assumption2}
Some assumption text with reference to \ref{assumptionlabel:some-assumption}.
\end{assumption}
\end{document}

enter image description here

  • Updating for the label issue later on – user31729 Jun 5 '17 at 14:31
  • Thank you for the toc edit. It works well. Looking forward to the labelling issue. – TNP Jun 5 '17 at 14:32
  • @TNP: As it stands, your \assumptionlabel command is not used yet. I don't know what you want to achieve with that, actually. In a normal setup, applying \label and hyperref should do what you want, without explicit \hypertarget calls – user31729 Jun 5 '17 at 14:34
  • Also you're misusing the \assumption -- it should be \begin{assumption}...\end{assumption} rather – user31729 Jun 5 '17 at 14:40
  • With using \label and the hyperref package, I get the "Assumption 1" in the cross-reference. I would like instead "Assumption 1.1". I could have used the native sectioning commands, but I wanted to define my own with that particular format. Is it possible to emulate the "section" cross-referencing format for my created header? – TNP Jun 5 '17 at 14:41

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.