1

I have a project consisting of Parts, each with multiple Chapters. The Parts are written in main.tex, with each Chapter included as a separate \subfile of main.tex.

Is there a way to automatically include part and chapter numbering when cross-referencing a section (or lower level)?

Example main.tex

\documentclass{book}
\usepackage{xr-hyper}
\usepackage[colorlinks=true, allcolors=blue]{hyperref}

\begin{document}

% Part 1 \part{} \label{part: 1}

% Include chapter 1 \subfile{Pt1/Ch1}

\end{document}

Example chapter subfile

\documentclass[../main.tex]{subfiles}

\begin{document}

\Chapter{My first chapter}

\section{My first section}

\subsection{My first subsection} \label{SS: My first subsection}

\section{My second section}

In \ref{SS: My first subsection} we discussed...

\end{document}

where I'm looking for the \ref command to generate a cross-reference of the form:

In Pt 1, Ch 1, 1.1 we discussed...

Thank you for your help.

Bells12
  • 37
  • 5
  • 1
    This https://tex.stackexchange.com/questions/252994/changing-the-output-of-ref-depending-on-the-position-of-the-corresponding-labe will helps you – MadyYuvi Jan 03 '24 at 12:46

1 Answers1

1

Does this achieve what you want?

You can define the label format for section and subsection using command \labelformat{<target heading>}{<format>}.

Such as:

main.tex

\documentclass{book}
\usepackage{xr-hyper}
\usepackage[colorlinks=true, allcolors=blue]{hyperref}
\usepackage{subfiles}
\labelformat{section}{Pt~\arabic{part}, Ch~\thechapter, \thesection}
\labelformat{subsection}{Pt~\arabic{part}, Ch~\thechapter, \thesubsection}

\begin{document}

% Part 1 \part{} \label{part: 1}

% Include chapter 1 \subfile{Pt1/Ch1}

\end{document}

chapter subfile

\documentclass[../main.tex]{subfiles}

\begin{document}

\chapter{My first chapter}

\section{My first section} \label{S: My first section} \subsection{My first subsection} \label{SS: My first subsection}

\section{My second section}

In \ref{SS: My first subsection} we discussed... In \ref{S: My first section} we discussed...

\end{document}

enter image description here

Tom
  • 7,318
  • 4
  • 21