# Reusing same labels across different chapters

I am writing my thesis which uses classicthesis.sty style. The thesis brings together a collection of papers and put them as individual chapters (all the chapters are included in main.tex). Some of the labels for figures, sections, tables etc. in two or more papers are the same and putting them together causes a problem. I would like to find a clean way of resolving this problem.

Based on the assumption that each of the \refs inside a paper only refers to \labels inside the paper itself, you can introduce \label prefixes that should make the references unique:

\documentclass{article}

\AtBeginDocument{% ...if you're using hyperref
\let\oldlabel\label% Copy original version of \label
\let\oldref\ref% Copy original version of \ref
}

\renewcommand{\label}[1]{\oldlabel{#1-##1}}% Update \label
\renewcommand{\ref}[1]{\oldref{#1-##1}}% Update \ref
}
\newcommand{\removelabelprefix}{%
\renewcommand{\label}{\oldlabel}% Restore \label
\renewcommand{\ref}{\oldref}% Restore \ref
}

\begin{document}

% Hypothetical first paper

\section{A section}\label{sec:section}
See section~\ref{sec:section}.

% Hypothetical second paper


Note that the references work as expected despite the same label sec:section.
• @Bishoksan: classicthesis uses hyperref, which in turn redefines the way \label and \ref works. So, you'll have to delay the storing of \oldlabel and \oldref until \AtBeginDocument. I've updated my answer to reflect this. – Werner May 29 '16 at 17:38
• @Bishoksan: You need to place \addlabelprefix{blah} before \include{Chapters/2/Chapter02} which should add blah in front of every \label and \ref used in the second chapter. – Werner May 30 '16 at 14:19