1

Question

How can I exclude a custom titling command (sectioning command) from the table of contents? Note that I do not want to simply inherit the \paragraph, because it is reserved for and extra deeper layer of sectioning.

Example

I would like to create a section called \minisec with titlesec, that is

  • numbered, yet does not show the number (for possible future decisions regarding numbering).
  • It does not show up in the table of contents.
  • It is lower than \paragraph

Sample Code

\titleclass{\minisec}{straight}[\paragraph]
\newcounter{minisec}
\setcounter{secnumdepth}{5}
\titleformat{\minisec}[hang]{\normalsize\bfseries}{}{0pt}{#1}
\titlespacing*{\minisec}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
\newcommand{\minisecautorefname}{minisec}

I adapted this code from https://tex.stackexchange.com/a/17278/13552

  • 1
    Whether \titleclass{\minisec}{straight}[\paragraph] \newcounter{minisec} \setcounter{secnumdepth}{5} \titleformat{name=\minisec,numberless}[hang]{\normalsize\bfseries}{}{0pt}{#1} \titlespacing*{\minisec}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex} is OK for you? – user11232 Feb 4 '15 at 13:01
  • That causes an error !Missing number, treated as zero. \minisec{Presettings}. Could that have something to do with the fact that I am using the explicit option in titlesec? – Jonathan Komar Feb 4 '15 at 13:28
  • You should use \minisec*{Presettings} Note the star. – user11232 Feb 4 '15 at 13:47
  • Ok, I found the problem and it is just caused by the setcounter{secnumdepth}{5}. Using starred commands are not an option for me. Also, my \paragraph has been reassigned to work like a \subsubsubsection, so the code you provided will not work. – Jonathan Komar Feb 4 '15 at 13:51
  • KOMA-script provides a command minisec by default ;-) – Johannes_B Feb 4 '15 at 15:29
2

The following example addresses all three questions (the code includes comments):

\documentclass{article}
\usepackage[explicit]{titlesec}
\usepackage{hyperref}

\titleclass{\minisec}{straight}[\paragraph]

\newcounter{minisec}

% Change 0pt to a positive value once the representation for the counter has been established
\titleformat{\minisec}[hang]
  {\normalsize\bfseries}{\theminisec}{0pt}{#1}
\titlespacing*{\minisec}
  {0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
\newcommand{\minisecautorefname}{minisec}

% minisecs will be numebered
\setcounter{secnumdepth}{5}
% minisecs won't appear in the ToC
\setcounter{tocdepth}{4}

% Provisional empty definition for the counter representation
\renewcommand\theminisec{}

% Settings for the bookmarks and the ToC entries (change the second 
% and third arguments of \@dottedtocline if minisecs should go to the ToC)
\makeatletter
  \def\toclevel@minisec{5}
  \def\l@minisec{\@dottedtocline{5}{3.8em}{3.2em}}
\makeatother

\begin{document}

\tableofcontents

\section{A test section}
In \autoref{sec:minitest} we have an example of
\subsection{A test subsection}
\subsubsection{A test subsubsection}
\paragraph{A test paragraph}
\minisec{A test minisec}
\label{sec:minitest}

\end{document}

enter image description here

  • Thank you very much for such a thorough answer that explains each part! Very helpful :) – Jonathan Komar Feb 4 '15 at 21:50

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.