23

I'm using the \autoref command from the hyperref package. I have the following code:

\subsection{Foo}
\label{ssec:bar}
This is the overview.

\subsubsection{Bar}
\label{sssec:bar}
This is the small part.

Later in the text, we refer to `\autoref{ssec:foo}` and `\autoref{sssec:bar}`.

After compiling, this shows the following text:

I.A. Foo

This is the overview.

I.A.1. Bar

This is the small part.

Later in the text, we refer to subsection I.A. and subsubsection I.A.1.

The problem I have with this is that \autoref is showing "subsection" and "subsubsection", when I'd rather it just show "section". Is there any way to override this in the hyperref package so it doesn't put any of the "subs" in there?

2 Answers 2

24

The names are stored in macros <counter>autorefname. The following examples redefines them using the same meaning as \sectionautorefname:

\documentclass{article}
\usepackage[colorlinks]{hyperref}
\renewcommand*{\thesection}{\Roman{section}}
\renewcommand*{\thesubsection}{\thesection.\Alph{subsection}}

\let\subsectionautorefname\sectionautorefname
\let\subsubsectionautorefname\sectionautorefname

\begin{document}
\section{Section}
\subsection{Foo}
\label{ssec:foo}
This is the overview.

\subsubsection{Bar}
\label{sssec:bar}
This is the small part.

Later in the text, we refer to \autoref{ssec:foo} and \autoref{sssec:bar}.
\end{document}

Result

8
  • 1
    @Heiko Oberdiek: It isn't working for me. I added \let\subsubsectionautorefname\subsectionautorefname and \let\subsubsubsectionautorefname\subsectionautorefname after calling hyperref but the outputs are still the same (Subsubsection and Subsubsubsection should be just Subsection). What Am I missing?
    – Claudia
    Jun 29, 2016 at 15:40
  • 4
    @Claudia If you are using package babel: example for language ngerman: \addto\extrasngerman{<autoref name definitions>} Jul 1, 2016 at 17:30
  • @Heiko Oberdiek: I use babel for brazilian language. I am not sure how to add those definitions. Aren't they already set?
    – Claudia
    Jul 4, 2016 at 21:45
  • @Claudia If babel is loaded before hyperref, then hyperref can detect the supported languages. Jul 4, 2016 at 21:47
  • 2
    I personnaly use \addto\extrasenglish{ \renewcommand{\sectionautorefname}{Sect.} \let\subsectionautorefname\sectionautorefname \let\subsubsectionautorefname\sectionautorefname } and feel very happy with it!
    – Clément
    Apr 10, 2018 at 18:17
3

I personally prefer to rename subsection and subsubsection like this:

\documentclass{article}

\usepackage[colorlinks]{hyperref}
\renewcommand{\sectionautorefname}{Section}
\renewcommand{\subsectionautorefname}{Section}
\renewcommand{\subsubsectionautorefname}{Section}

\begin{document}

\section{Prologue}

We can refer to \autoref{sec:lorem}, \autoref{ssec:foo} and \autoref{sssec:bar}.

\section{Lorem}
\label{sec:lorem}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus consectetur.

\subsection{Foo}
\label{ssec:foo}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus vel.

\subsubsection{Bar}
\label{sssec:bar}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque pulvinar.

\end{document}

Result

2
  • Welcome to tex.sx. If all are shown in cross references as "Section". why not combine them as "Sections 2, 2.1, ,,,"? Dec 4, 2022 at 17:05
  • I wrote them one after the other just to show as an example what it looks like Dec 4, 2022 at 18:14

You must log in to answer this question.

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