1

I customize the title's appearance of the document (chapter, section, sub-section, ...) by defining new commands (see the latex code).

However, when I want to make a crossref to the chapter, section, sub-section, ... with the \autoref command this gives the result "section" only as shown in the picture below. While I want to have the following result:

section 1.1

Subsection 1.2.1

etc.

I'm convinced that the problem comes from the titles redefining but how to solve the problem while keeping the same configuration?

Kind regards


\documentclass[a4paper,12pt,oneside,final,french]{book}

\headheight = 15pt 
\usepackage[margin=2.5cm, left=3cm, top=2.5cm, bottom=2.5cm]{geometry}

\usepackage[utf8]{inputenc} 
\usepackage[T1]{fontenc}

\usepackage{helvet} 
\renewcommand{\familydefault}{\sfdefault}


\usepackage{varioref}
\usepackage[pdftex,pdfborder={0 0 0},linkcolor =coolBlue,citecolor=coolRed,urlcolor=coolGreen]{hyperref}

%-----------------------Titles defining--------------------
\newcounter{poolChapter}
\newcounter{poolSection}[poolChapter]
\newcounter{poolSubSection}[poolSection]
\newcounter{poolSubSubSection}[poolSubSection]

\newcommand{\poolChapter}[1]{
    \newpage
    \stepcounter{poolChapter}
    \phantomsection 
    \addcontentsline{toc}{chapter}{\arabic{poolChapter}. #1}
    \begin{center}
        {   
            \null
            \vspace{-1.2\baselineskip}
            \vspace{4mm}
            \fontsize{16pt}{0}\selectfont
            \textbf{CHAPTER \arabic{poolChapter}}\\
            \vspace{7mm}
            \textbf{\uppercase{#1}}
        }
    \end{center}
}


\newcommand{\poolSection}[1]{
    \stepcounter{poolSection}
    \phantomsection
    \addcontentsline{toc}{section}{\arabic{poolChapter}.\arabic{poolSection}. #1}
    {\fontsize{14pt}{0}\selectfont \textbf{\arabic{poolChapter}.\arabic{poolSection}. #1}}
}

\newcommand{\poolSubSection}[1]{
    \stepcounter{poolSubSection}
    \phantomsection
    \addcontentsline{toc}{subsection}{\arabic{poolChapter}.\arabic{poolSection}.\arabic{poolSubSection}. #1}
    {\textbf{\arabic{poolChapter}.\arabic{poolSection}.\arabic{poolSubSection}. #1}}
}

\newcommand{\poolSubSubSection}[1]{
    \stepcounter{poolSubSubSection}
    \phantomsection
    \addcontentsline{toc}{subsubsection}{\arabic{poolChapter}.\arabic{poolSection}.\arabic{poolSubSection}.\arabic{poolSubSubSection}. #1}
    {\textbf{\arabic{poolChapter}.\arabic{poolSection}.\arabic{poolSubSection}.\arabic{poolSubSubSection}. #1}}
}


\newcommand{\poolDummyChapter}[1]{
    \newpage
  
    \begin{center}
        {   
            \null
            \vspace{-1.6\baselineskip}
            \vspace{1.4cm}
            \large\textbf{#1}
        }
    \end{center}
}


%-----------------------------------------------------------------


\begin{document}
\poolChapter{Materials and methods}

\poolSection{Materials}

See \autoref{methods}

\poolSection{Methods} \label{methods}

See \autoref{method1}

\poolSubSection{Method 1} \label{method1}

\end{document}

Sample rendering

1 Answer 1

1

Don't use \phantomsection but \refstepcounter, and define the autoref names:

\documentclass[a4paper,12pt,oneside,final,french]{book}

\headheight = 15pt
\usepackage[margin=2.5cm, left=3cm, top=2.5cm, bottom=2.5cm]{geometry}

\usepackage[T1]{fontenc}

\usepackage{helvet}
\renewcommand{\familydefault}{\sfdefault}


\usepackage{varioref}
\usepackage[pdfborder={0 0 0},linkcolor =coolBlue,citecolor=coolRed,urlcolor=coolGreen]{hyperref}

%-----------------------Titles defining--------------------
\newcounter{poolChapter}
\newcounter{poolSection}[poolChapter]
\newcounter{poolSubSection}[poolSection]
\newcounter{poolSubSubSection}[poolSubSection]

\newcommand{\poolChapter}[1]{
    \newpage
    \refstepcounter{poolChapter}
    %\phantomsection
    \addcontentsline{toc}{chapter}{\arabic{poolChapter}. #1}
    \begin{center}
        {
            \null
            \vspace{-1.2\baselineskip}
            \vspace{4mm}
            \fontsize{16pt}{0}\selectfont
            \textbf{CHAPTER \arabic{poolChapter}}\\
            \vspace{7mm}
            \textbf{\uppercase{#1}}
        }
    \end{center}
}


\newcommand{\poolSection}[1]{
    \refstepcounter{poolSection}
    %\phantomsection
    \addcontentsline{toc}{section}{\arabic{poolChapter}.\arabic{poolSection}. #1}
    {\fontsize{14pt}{0}\selectfont \textbf{\arabic{poolChapter}.\arabic{poolSection}. #1}}
}

\newcommand{\poolSubSection}[1]{
    \refstepcounter{poolSubSection}
    %\phantomsection
    \addcontentsline{toc}{subsection}{\arabic{poolChapter}.\arabic{poolSection}.\arabic{poolSubSection}. #1}
    {\textbf{\arabic{poolChapter}.\arabic{poolSection}.\arabic{poolSubSection}. #1}}
}

\newcommand{\poolSubSubSection}[1]{
    \refstepcounter{poolSubSubSection}
    %\phantomsection
    \addcontentsline{toc}{subsubsection}{\arabic{poolChapter}.\arabic{poolSection}.\arabic{poolSubSection}.\arabic{poolSubSubSection}. #1}
    {\textbf{\arabic{poolChapter}.\arabic{poolSection}.\arabic{poolSubSection}.\arabic{poolSubSubSection}. #1}}
}


\newcommand{\poolDummyChapter}[1]{
    \newpage

    \begin{center}
        {
            \null
            \vspace{-1.6\baselineskip}
            \vspace{1.4cm}
            \large\textbf{#1}
        }
    \end{center}
}

\newcommand\poolSectionautorefname{Pool section}
\newcommand\poolSubSectionautorefname{Pool subsection}

%-----------------------------------------------------------------


\begin{document}
\poolChapter{Materials and methods}

\poolSection{Materials}

See \autoref{methods}

\poolSection{Methods} \label{methods}

See \autoref{method1}

\poolSubSection{Method 1} \label{method1}

\end{document}

enter image description here

To get a different label redefine the counter representations, e.g. \thepoolSubSection:

\renewcommand\thepoolSubSection{\arabic{poolChapter}.\arabic{poolSection}.\arabic{poolSubSection}}

Be aware that your definition don't give real sectioning commands: they don't suppress page breaks before the next line, don't set headers. Normally it is better to create new sectioning variants with \@startsection which then takes case of such details.

2
  • Thank you for the promptness with which you responded to my concern. The proposed solution is satisfactory but not complete. Indeed, after defining autoref names and removing the \phantomsection, I get a result like subsection 1 instead of subsection 1.2.1. Thank you again and I hope you find the time to help me with my request. Commented Sep 8, 2021 at 23:17
  • I added a remark at the end. But your question was about autoref, not about how to generally create a sectioning commands. So if you have more questions better ask a new question. Commented Sep 9, 2021 at 6:37

You must log in to answer this question.

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