In some papers and books you see that author uses §1.3 instead of section 1.3. How § sign can be added before section (or part, chapter, ...) number automatically? Please mention any useful tip about this style.
see also: Fancy cross-referencing
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this communityIn some papers and books you see that author uses §1.3 instead of section 1.3. How § sign can be added before section (or part, chapter, ...) number automatically? Please mention any useful tip about this style.
see also: Fancy cross-referencing
You could use the cleveref
package and redefine \crefname{section}
:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{cleveref}
\crefname{section}{§}{§§}
\Crefname{section}{§}{§§}
\begin{document}
\section{foo}\label{sec:foo}
Some text.
\section{bar}
As explained in \cref{sec:foo}~\dots
\end{document}
hyperref
provides \autoref{<label>}
that checks the counter used in the reference and sets a label with a prepended \<counter>autorefname
. Here's a small example:
\documentclass{article}
\usepackage{hyperref}% http://ctan.org/pkg/hyperref
\renewcommand{\sectionautorefname}{\S}
\begin{document}
\section{A section}
See~\autoref{another-section}.
\section{Another section}\label{another-section}
\end{document}
\subsectionautorefname
and \subsubsectionautorefname
to be the same as \sectionautorefname
so that you can get "See § 2.1" or "See § 3.2.1". If one also uses autopageref
, one can also redefine \pageautorefname
to "p." to get "See § 3.2 on p. 4"
Jun 14, 2012 at 18:39
\def\Snospace~{\S{}}
, then \renewcommand*\sectionautorefname{\Snospace}
instead. ```
Jul 27, 2020 at 19:02
Often forgotten is the macro \p@<counter>
. If LaTeX generates a reference value, this is
not just \the<counter>
but \p@<counter>\the<counter>
. If a new counter is defined,
\p@<counter>
is defined empty. But it can be redefined to add a prefix, for example.
Thus there is no need for additional packages.
\documentclass{article}
\makeatletter
\renewcommand*{\p@section}{\S\,}
\renewcommand*{\p@subsection}{\S\,}
\makeatother
\begin{document}
\section{Hello World}
\label{sec:hello}
\subsection{Subsection A}
\subsection{Subsection B}
\subsection{Subsection C}
\label{sec:C}
See \ref{sec:C} inside \ref{sec:hello}.
\end{document}
I spent a little time figuring the solution for me so I thought I'd share. In case, like me:
cleveref
(cf lockstep's answer) because it is incompatible with the showonlyrefs
option of the package mathtools
\ref
and \autoref
hyperref
package and Werner's solution but it does not work because you are using the package babelHere is the fix, found here:
\addto\extrasenglish{
\def\sectionautorefname{\S}
}
Here it is in a minimal working example:
\documentclass{article}
\usepackage[english]{babel}
\usepackage{mathtools}
\usepackage{hyperref}
\mathtoolsset{showonlyrefs=true}
\addto\extrasenglish{%
\def\sectionautorefname{\S}%
}
\begin{document}
\section{Foo}
Cf \autoref{sec:bar}.
\section{Bar}\label{sec:bar}
\end{document}
babel
prevent Werner's solution from working? Also what is the purpose of the %
markers at the end of the two lines where you apply your solution?
Dec 14, 2017 at 15:57
%
at the end of line is for Tex to ignore the newline when {...}
spans multiple lines. I'm not too clear about the mechanics, but it does solve errors.
Mar 12, 2018 at 13:35