4

when I try following code, everything works as expected:

\documentclass{article}
%\renewcommand{\thesubsubsection}{\alph{subsubsection})}
\begin{document}
\section{A Section}
\subsection{A Subsection}
\subsubsection{A Subsubsection}
\label{testlabel}
Hello world.
\par
In \ref{testlabel} I wrote: Hello world.
\end{document}

This will print 1.1.1.

But if I enable the command in the comment, I just get a) instead of the expected 1.1.a)

In fact I want the section to appear as a) ... and the reference as 1.1.a without brace.

Any ideas?

3
  • The section or the subsubsection should appear as a) and the reference as 1.1.a, effectively vice versa?
    – user31729
    Apr 26, 2015 at 17:53
  • Sorry for the confusion. But David Carlisle has given a working answer already. Thx all
    – musicman
    Apr 26, 2015 at 18:08
  • 1
    Ok, I'll delete my version then, it's of no use
    – user31729
    Apr 26, 2015 at 18:24

3 Answers 3

3

enter image description here

For any LaTeX counter the macro \[email protected] is the prefix used in references. Normally it is used in nested enumerate to get exactly the effect where the list label just shows one level and a reference shows the expanded form.

The default macros assume that the print form of the final counter is the same in both places, so as you want to lose the ) you need the prefix macro to remove it, as here, or as in egreg's answer not add it to the counter format, and instead consider the ) part of the section heading format.

\documentclass{article}
\renewcommand{\thesubsubsection}{\alph{subsubsection})}
\makeatletter
\renewcommand{\p@subsubsection}{\thesubsection.\protect\eatbracket}
\makeatother
\def\eatbracket#1#2{#1\ifx)#2\else#2\fi}

\begin{document}
\section{A Section}
\subsection{A Subsection}
\subsubsection{A Subsubsection}
\label{testlabel}
Hello world.
\par
In \ref{testlabel} I wrote: Hello world.
\end{document}
6
  • How about adding some mortar to this?
    – Werner
    Apr 26, 2015 at 18:10
  • @Werner you mean that documentation thing? Apr 26, 2015 at 18:12
  • ...riiiight. :)
    – Werner
    Apr 26, 2015 at 18:15
  • Note that this exploits the alphabetic counter; it will not work with numeric counters, after the ninth subsubsection.
    – egreg
    Apr 26, 2015 at 18:16
  • 1
    @egreg but this is an alphabetic counter:-) Apr 26, 2015 at 18:17
4

It's better to add the parenthesis where it belongs, rather than removing it afterwards. This can be accomplished by a simple redefinition of \@seccntformat:

\documentclass{article}

\makeatletter
\renewcommand{\@seccntformat}[1]{%
  \csname the#1\endcsname
  \csname suffix@#1\endcsname % this does nothing unless \suffix@... is defined
  \quad
}
% the subsubsection number is just a letter
\renewcommand{\thesubsubsection}{\alph{subsubsection}}
% but references will also have “section.subsection.” in front of the letter
\renewcommand{\p@subsubsection}{\thesubsection.}
% define \suffix@subsubsection
\newcommand{\suffix@subsubsection}{)}
\makeatother

\begin{document}

\section{A Section}
\subsection{A Subsection}
\subsubsection{A Subsubsection}\label{testlabel}

Hello world.

In \ref{testlabel} I wrote: Hello world.

\end{document}

enter image description here

This is also scalable. Suppose you want a normal interword space between the a) and the title, while keeping the \quad for higher levels. Then you can modify the code as

\makeatletter
\renewcommand{\@seccntformat}[1]{%
  \csname the#1\endcsname
  \@ifundefined{suffix@#1}%
    {\quad}%
    {\csname suffix@#1\endcsname}%
}
% the subsubsection number is just a letter
\renewcommand{\thesubsubsection}{\alph{subsubsection}}
% but references will also have “section.subsection.” in front of the letter
\renewcommand{\p@subsubsection}{\thesubsection.}
% define \suffix@subsubsection
\newcommand{\suffix@subsubsection}{) }% parenthesis and space
\makeatother

enter image description here

The second solution with also a fix for the table of contents (again, between the parenthesis and the title just a normal space seems best).

\documentclass{article}

\makeatletter
\renewcommand{\@seccntformat}[1]{%
  \csname the#1\endcsname
  \@ifundefined{suffix@#1}
    {\quad}%
    {\csname suffix@#1\endcsname}%
}
% the subsubsection number is just a letter
\renewcommand{\thesubsubsection}{\alph{subsubsection}}
% but references will also have “section.subsection.” in front of the letter
\renewcommand{\p@subsubsection}{\thesubsection.}
% define \suffix@subsubsection
\newcommand{\suffix@subsubsection}{) }% parenthesis and space
\renewcommand{\l@subsubsection}[2]{%
  \@dottedtocline{3}{3.8em}{3.2em}{\let\numberline\subsubsection@numberline#1}{#2}%
}
\def\subsubsection@numberline#1{#1) }
\makeatother

\begin{document}

\tableofcontents

\section{A Section}
\subsection{A Subsection}
\subsubsection{A Subsubsection}
\label{testlabel}
Hello world.
\par
In \ref{testlabel} I wrote: Hello world.

\section{Whatever}
\end{document}

enter image description here

2
  • This would generally be the better approach, I guess. And nice addition with the space. I just saw in the real life case that in the TOC I get a with your solution, in Davids a). But this has to be a)
    – musicman
    Apr 26, 2015 at 18:28
  • 1
    @musicman Added the fix for the table of contents
    – egreg
    Apr 26, 2015 at 19:36
2

You need to give the \thesubsubsection the contents of \thesubsection as well

\documentclass{article}
\renewcommand{\thesubsubsection}{\thesubsection.\alph{subsubsection})}
\begin{document}
\section{A Section}
\subsection{A Subsection}
\subsubsection{A Subsubsection}
\label{testlabel}
Hello world.
\par
In \ref{testlabel} I wrote: Hello world. 
\end{document}

Yielding

enter image description here

3
  • The reference still appears with the parenthesis which is not desired; I think a more complicated approach is required to make it not appear i nthe reference. Apr 26, 2015 at 17:50
  • Hmm I understand the problem. But I want a) in the section heading and the full reference 1.1.a in \ref.
    – musicman
    Apr 26, 2015 at 17:53
  • 2
    @musicman: Please make it clear if you mean the section heading or the subsubsection heading for a) ... this is a little bit confusing.
    – user31729
    Apr 26, 2015 at 17:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .