12

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?

14

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

  • @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 '16 at 15:40
  • 3
    @Claudia If you are using package babel: example for language ngerman: \addto\extrasngerman{<autoref name definitions>} – Heiko Oberdiek Jul 1 '16 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 '16 at 21:45
  • @Claudia If babel is loaded before hyperref, then hyperref can detect the supported languages. – Heiko Oberdiek Jul 4 '16 at 21:47
  • 1
    I personnaly use \addto\extrasenglish{ \renewcommand{\sectionautorefname}{Sect.} \let\subsectionautorefname\sectionautorefname \let\subsubsectionautorefname\sectionautorefname } and feel very happy with it! – Clément Apr 10 '18 at 18:17

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.