2

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? –  Feb 04 '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 04 '15 at 13:28
  • You should use \minisec*{Presettings} Note the star. –  Feb 04 '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 04 '15 at 13:51
  • KOMA-script provides a command minisec by default ;-) – Johannes_B Feb 04 '15 at 15:29
  • @macmadness86 You didn't mention before that you have \subsubsubsection, so how could we have guessed that? Please, instead of just useless snippets, add to your question a complete, yet minimal, document showing (only) the relevant settings related to your question. – Gonzalo Medina Feb 04 '15 at 16:40
  • Thanks Johannes, I know that it is, but I am switching from KOMA-script and I need a substitute. – Jonathan Komar Feb 04 '15 at 21:41

1 Answers1

3

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

Gonzalo Medina
  • 505,128