8

I am trying to change "chapter" to "Chapter" when autoreferencing the label

enter image description here

I have looked for a solution and some comment in this closed question Change text in LaTeX chapter titles from "Chapter" to "chapter" suggested to use renew command

I have used "babel" as well as "renewcommand" but nothing has changed.enter image description here

Can someone please help? Minimum working example below.

%% *** Add any desired options. ***
\documentclass{book}

\usepackage{siunitx}
\usepackage{nomencl}
\usepackage{amsmath}
\usepackage{nicefrac}
\usepackage{nomencl}
\usepackage{amsmath}
\usepackage{amsthm}     
\usepackage{amssymb}
\usepackage[english]{babel}
\usepackage{hyperref}
\renewcommand{\chaptername}{chapter}
\begin{document}
       \chapter{Before We Begin}
       In \autoref{Chapter2}, we will talk about how to live a full life.
       \chapter{Begin}
       \label{Chapter2}
\end{document}
3
13

The manual of the hyperref package explains how to achive this on page 17.

Edit: This answer assumes that you actually want to use the babel package. If this is not the case, just redefine \chapterautorefname at the \begin{document} hook: see Bernard’s answer for instructions on how to do this.

\documentclass{book}

% \usepackage{siunitx}
% \usepackage{nomencl}
% \usepackage{amsmath}
% \usepackage{nicefrac}
% \usepackage{nomencl}
% \usepackage{amsmath}
% \usepackage{amsthm}     
% \usepackage{amssymb}
\usepackage[english]{babel}
\usepackage{hyperref}
\addto\extrasenglish{%
  \def\chapterautorefname{Chapter}%
}
\begin{document}
       \chapter{Before We Begin}
       In \autoref{Chapter2}, we will talk about how to live a full life.
       \chapter{Begin}
       \label{Chapter2}
       Live until you die\textellipsis~:-)
\end{document}

Here’s the output I get:

Output of the code

Addition

Of course, the same mechanism works for other titles as well:

\documentclass{book}

\usepackage[english]{babel}
\usepackage{hyperref}
\addto\extrasenglish{%
  \def\chapterautorefname{Chapter}%
  \def\sectionautorefname{Section}%
  \def\subsectionautorefname{Subsection}%
  \def\subsubsectionautorefname{Subsubsection}%
  \def\paragraphautorefname{Paragraph}%
  \def\subparagraphautorefname{Subparagraph}%
}
\begin{document}
       \chapter{Before We Begin}
       In \autoref{Chapter2}, we will talk about how to live a full life.
       \chapter{Begin}
       \label{Chapter2}
       Live until you die\textellipsis~:-)
\end{document}

For a complete list of the available names, see the file hyperref.sty at lines, say, 3220–3235.

2
  • Is there a way to do this for section also? Or is it what I think "\addto\extrasenglish{% \def\sectionautorefname{Section}% }"
    – Fraïssé
    May 21 '17 at 23:34
  • @ProcrastinationSage: See Addition.
    – GuM
    May 22 '17 at 6:43
9

Whether you use babel or not, this works (no problem if you only use the English language – otherwise @Gustavo Mezzeti's answer is more appropriate):

\documentclass[english]{book}

\usepackage{siunitx}
\usepackage{nomencl}
\usepackage{amsmath}
\usepackage{nicefrac}
\usepackage{amsthm}
\usepackage{amssymb}
%
\usepackage{babel}
\usepackage{hyperref}
\AtBeginDocument{\def\chapterautorefname{Chapter}}%

\begin{document}

       \chapter{Before We Begin}
       In \autoref{Chapter2}, we will talk about how to live a full life.
       \chapter{Begin}
       \label{Chapter2}

\end{document} 
5
  • I bet, however, that one is going to have issues if more than one language is used (not very likely, admittedly).
    – GuM
    May 21 '17 at 22:49
  • @Gustavo Mezzetti: That was my implicit hypothesis. Should I be clearer?
    – Bernard
    May 21 '17 at 22:51
  • In general, I think it is a matter of mental order to keep distinct the two scenarios “babel used” vs. “babel not used”, and to give separate instructions for the two. Please note the my implicit hypothesis, in my answer, is that the OP actually wanted to use babel, and this, reading more carefully, doesn’t seem to be the case. So your answer is probably better: +1.
    – GuM
    May 21 '17 at 22:58
  • Hi is the way to capitalize "Section" and "Subsection" done in the same way?
    – Fraïssé
    May 21 '17 at 23:39
  • Yes. See lines 3220-3235 in hyperref.sty.
    – Bernard
    May 21 '17 at 23:42
0

I get annoyed all the time, not just for chapters, but also for sections. I also found using subsection and subsubsection in text would not be appealing, when it is possible to use Chapter 1, Section 5, Section 3.1 and Section 2.5.4.

Add this at the beginning of your tex file:

\renewcommand{\chapterautorefname}{Chapter} 
\renewcommand{\sectionautorefname}{Section} 
\let\subsectionautorefname\sectionautorefname 
\let\subsubsectionautorefname\sectionautorefname

Screenshots:

enter image description here enter image description here enter image description here

Not the answer you're looking for? Browse other questions tagged or ask your own question.