2

A list of all of the packages used:

\usepackage{caption}
\usepackage{blindtext}
\usepackage{pifont,mdframed}
\usepackage{enumitem}
\usepackage{amssymb}
\usepackage{amsmath} % For using \text in equations
\usepackage{hyperref} % Hyperlinks
\usepackage[nameinlink,noabbrev,capitalise]{cleveref} % Better in-doc refs
\usepackage[numbered]{bookmark}
\usepackage{endnotes}
\input{hyperendnotes.sty}
\usepackage{etoolbox}
\usepackage[title,toc,titletoc,page]{appendix}
\usepackage{multirow}
\usepackage[margin=2cm]{geometry}
\usepackage{graphicx}
\usepackage{float} % Better figure and table placements
\usepackage{tabularx}
\usepackage{csquotes} % For blockquote
\usepackage[labelfont=it, labelsep=period]{caption}
\usepackage{subcaption}
\usepackage{color}
\usepackage{xcolor,colortbl}
\usepackage[final]{pdfpages} % used to include pdf to appendicies
\usepackage{lipsum}
\usepackage{microtype} % Slightly tweak font spacing for aesthetics
\usepackage{lettrine}
\usepackage{longtable}
% \usepackage{ragged2e}
\usepackage[export]{adjustbox}
\usepackage{wrapfig}
\usepackage{float}
\usepackage{tabularray}
\usepackage{microtype} % Slightly tweak font spacing for aesthetics
\usepackage{xpatch}

Other setup:

\definecolor{purple}{RGB}{101,48,165}

\hypersetup{
  pdftitle={},
  pdfauthor={},
  pdfkeywords={},
  bookmarksnumbered=true,
  bookmarksopen=false,
  bookmarksopenlevel=1,
  colorlinks=true,
  breaklinks,
  linktoc=section,
  linkcolor=purple,
  linkbordercolor=white,
  citecolor=purple,
  urlcolor=purple,
  pdfborder = {0 0 1},
  pdfview={XYZ null 0 null}
}

\crefformat{section}{\S#2#1#3}
\crefformat{subsection}{\S#2#1#3}
\crefformat{subsubsection}{\S#2#1#3}

Result: § is not colored.

enter image description here

2
  • 1
    Put it after #2
    – egreg
    Mar 25, 2023 at 21:43
  • Do you want a space between the section symbol and associated number?
    – Mico
    Mar 26, 2023 at 0:29

1 Answer 1

6

It should be

\crefformat{section}{#2\S#1#3}
\crefformat{subsection}{#2\S#1#3}
\crefformat{subsubsection}{#2\S#1#3}

because #2 stands for “begin of link” and #3 for “end of link”.

\documentclass{article}

\usepackage{xcolor}
\usepackage{hyperref} % Hyperlinks
\usepackage[nameinlink,noabbrev,capitalise]{cleveref} % Better in-doc refs

\definecolor{purple}{RGB}{101,48,165}

\hypersetup{
  pdftitle={},
  pdfauthor={},
  pdfkeywords={},
  bookmarksnumbered=true,
  bookmarksopen=false,
  bookmarksopenlevel=1,
  colorlinks=true,
  breaklinks,
  linktoc=section,
  linkcolor=purple,
  linkbordercolor=white,
  citecolor=purple,
  urlcolor=purple,
  pdfborder = {0 0 1},
  pdfview={XYZ null 0 null}
}

\crefformat{section}{#2\S#1#3}
\crefformat{subsection}{#2\S#1#3}
\crefformat{subsubsection}{#2\S#1#3}

\begin{document}

\section{Test section}\label{a}

\subsection{Test subsection}\label{b}

\subsubsection{Test subsubsection}\label{c}

\cref{a}

\cref{b}

\cref{c}

\end{document}

enter image description here

For your information, none of the package you load should go after cleveref, and only bookmark should go after hyperref.

You must log in to answer this question.

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