2

Usually a \ref to a \subsubsection gives 1.1.1 (from the parent \subsection). Sample:

\documentclass{book}

\begin{document}

\chapter{chap}
\section{sec}
\subsection{sub}
\subsubsection{subsub}
label \label{subsub}

\section{sec2}
\ref{subsub}

\end{document}

enter image description here

However, if I add and use a counter, indicated line breaks output of \ref{subsub}:

\documentclass{book}
\newcounter{someCounter}

\begin{document}

\chapter{chap}
\label{chap}
\refstepcounter{someCounter} %ok

\section{sec}
\label{sec}
\refstepcounter{someCounter} %ok

\subsection{sub}
\label{sub}
\refstepcounter{someCounter} %this breaks \ref{subsub}

\subsubsection{subsub}
\label{subsub}
\refstepcounter{someCounter} %ok

\section{sec2}
\ref{chap} :: \ref{sec} :: \ref{sub} :: \ref{subsub}

\end{document}

Output (last 3 should be 1.1.1:

enter image description here

What is the reason for this unexpected behavior? How to avoid it?

3

This is the expected behavior. \subsubsection{subsub} does not have a number, thus it cannot be referenced. Internally \refstepcounter{subsubsection} is not called, because the default setting of counter secnumdepth excludes \subsubsection and the lower section commands \paragraph and \subparagraph from getting numbers. \label{subsub} therefore references the \subsection before in the first case and the \refstepcounter{someCounter} before in the second case.

Unnumbered sections can be referenced by name and page number

The example uses package nameref for referencing the name, another package is titleref:

\documentclass{book}
\newcounter{someCounter}
\usepackage{nameref}

\begin{document}

\chapter{chap}
\label{chap}
\refstepcounter{someCounter} %ok

\section{sec}
\label{sec}
\refstepcounter{someCounter} %ok

\subsection{sub}
\label{sub}
\refstepcounter{someCounter} %this breaks \ref{subsub}

\subsubsection{subsub}
\label{subsub}
\refstepcounter{someCounter} %ok

\section{sec2}
\ref{chap} :: \ref{sec} :: \ref{sub} ::
section ``\nameref{subsub}'' on page \pageref{subsub}

\end{document}

Result reference by name and page number

Subsubsections with number:

The section numbering depth can be increased by \stepcounter{secnumdepth} or setting it to \setcounter{secnumdepth}{3} for numbering section levels including subsubsections:

\documentclass{book}
\newcounter{someCounter}

\setcounter{secnumdepth}{3}

\begin{document}

\chapter{chap}
\label{chap}
\refstepcounter{someCounter} %ok

\section{sec}
\label{sec}
\refstepcounter{someCounter} %ok

\subsection{sub}
\label{sub}
\refstepcounter{someCounter} %this breaks \ref{subsub}

\subsubsection{subsub}
\label{subsub}
\refstepcounter{someCounter} %ok

\section{sec2}
\ref{chap} :: \ref{sec} :: \ref{sub} :: \ref{subsub}

\end{document}

Result with numbered subsubsection

  • No number, no reference. Seems reasonable. So the "1.1.1" is actually the "unexpected" part. – Jack Miller Aug 20 '15 at 11:11

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.