1

The number of section does not appear when need referring label. This the code that use, see also the picture

 \documentclass[a4paper,11pt,reqno]{amsart}
    \usepackage{hyperref}
    \usepackage[T1]{fontenc}
    \usepackage[utf8]{inputenc}
    \usepackage[most]{tcolorbox}
    
    
    \newtcbtheorem[auto counter, number within=section]{TcbThm}{\textsc{Theorem}}{breakable, enhanced,
        label separator=-,
        left=1mm,
        after skip=10pt,
        before skip=10pt,
        sharp corners,fontupper=\itshape,
        attach boxed title to top left={xshift=-1.5mm, yshift=-3mm, yshifttext=-1mm},
        boxed title style={opacityback=0,colframe=white,size=fbox,arc=0mm},
        fonttitle=\bfseries, coltitle=black, colbacktitle=white,
        colback=white, colframe=black,
        borderline east={4pt}{-2pt}{white},
        borderline north={4pt}{-2pt}{white},
        separator sign none, description delimiters parenthesis}{th}
    
    \NewDocumentEnvironment{thm}{ O{} O{} } % two optional arguments
    {\TcbThm{#1}{#2}}
    {\endTcbThm}
    
    
    
    \newtcbtheorem[auto counter, number within=section]{TcbDef}{\textsc{Definition}}{breakable, enhanced,
        label separator=-,
        left=1mm,
        after skip=10pt,
        before skip=10pt,
        sharp corners,fontupper=\itshape,
        attach boxed title to top left={xshift=-1.5mm, yshift=-3mm, yshifttext=-1mm},
        boxed title style={opacityback=0,colframe=white,size=fbox,arc=0mm},
        fonttitle=\bfseries, coltitle=black, colbacktitle=white,
        colback=white, colframe=black,
        borderline east={4pt}{-2pt}{white},
        borderline north={4pt}{-2pt}{white},
        separator sign none, description delimiters parenthesis}{def}
    
    \NewDocumentEnvironment{defin}{ O{} O{} } % two optional arguments
    {\TcbDef{#1}{#2}}
    {\endTcbDef}
    
    
    \newtcbtheorem[auto counter, number within=section]{TcbLem}{\textsc{Lemma}}{breakable, enhanced,
        label separator=-,
        left=1mm,
        after skip=10pt,
        before skip=10pt,
        sharp corners,fontupper=\itshape,
        attach boxed title to top left={xshift=-1.5mm, yshift=-3mm, yshifttext=-1mm},
        boxed title style={opacityback=0,colframe=white,size=fbox,arc=0mm},
        fonttitle=\bfseries, coltitle=black, colbacktitle=white,
        colback=white, colframe=black,
        borderline east={4pt}{-2pt}{white},
        borderline north={4pt}{-2pt}{white},
        separator sign none, description delimiters parenthesis}{def}
    
    \NewDocumentEnvironment{lem}{ O{} O{} } % two optional arguments
    {\TcbLem{#1}{#2}}
    {\endTcbLem}
    
    
    
    \begin{document}
    \section{section}
    \begin{thm}\label{thm1}
    kdd
    \end{thm}
    \ref{thm1}
    \section{section}
    \begin{thm}\label{thm2}
        kdd
    \end{thm}
    \ref{thm2}
    \section{section}
    \section{section}
    \end{document}

enter image description here

1 Answer 1

1

First, hyperref should be loaded after all other packages but before user-defined tcolorbox environments/boxes.

Your thm environment needs to be labeled as \begin{thm}[]{thm1} then referenced with label name th-thm1, in which the prefix th and separator - are set by

\newtcbtheorem[...]{TcbThm}{\textsc{Theorem}}{
  ...,
  label separator=-,
  ...
}{th}

In usage \begin{thm}\label{thm1}, the value of current section, instead of theorem, is recorded.

\documentclass[a4paper,11pt,reqno]{amsart}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[most]{tcolorbox}
\usepackage{hyperref}


\newtcbtheorem[auto counter, number within=section]{TcbThm}{\textsc{Theorem}}{breakable, enhanced,
    label separator=-,
    left=1mm,
    after skip=10pt,
    before skip=10pt,
    sharp corners,fontupper=\itshape,
    attach boxed title to top left={xshift=-1.5mm, yshift=-3mm, yshifttext=-1mm},
    boxed title style={opacityback=0,colframe=white,size=fbox,arc=0mm},
    fonttitle=\bfseries, coltitle=black, colbacktitle=white,
    colback=white, colframe=black,
    borderline east={4pt}{-2pt}{white},
    borderline north={4pt}{-2pt}{white},
    separator sign none, description delimiters parenthesis}{th}

\NewDocumentEnvironment{thm}{ O{} O{} } % two optional arguments
{\TcbThm{#1}{#2}}
{\endTcbThm}



\newtcbtheorem[auto counter, number within=section]{TcbDef}{\textsc{Definition}}{breakable, enhanced,
    label separator=-,
    left=1mm,
    after skip=10pt,
    before skip=10pt,
    sharp corners,fontupper=\itshape,
    attach boxed title to top left={xshift=-1.5mm, yshift=-3mm, yshifttext=-1mm},
    boxed title style={opacityback=0,colframe=white,size=fbox,arc=0mm},
    fonttitle=\bfseries, coltitle=black, colbacktitle=white,
    colback=white, colframe=black,
    borderline east={4pt}{-2pt}{white},
    borderline north={4pt}{-2pt}{white},
    separator sign none, description delimiters parenthesis}{def}

\NewDocumentEnvironment{defin}{ O{} O{} } % two optional arguments
{\TcbDef{#1}{#2}}
{\endTcbDef}


\newtcbtheorem[auto counter, number within=section]{TcbLem}{\textsc{Lemma}}{breakable, enhanced,
    label separator=-,
    left=1mm,
    after skip=10pt,
    before skip=10pt,
    sharp corners,fontupper=\itshape,
    attach boxed title to top left={xshift=-1.5mm, yshift=-3mm, yshifttext=-1mm},
    boxed title style={opacityback=0,colframe=white,size=fbox,arc=0mm},
    fonttitle=\bfseries, coltitle=black, colbacktitle=white,
    colback=white, colframe=black,
    borderline east={4pt}{-2pt}{white},
    borderline north={4pt}{-2pt}{white},
    separator sign none, description delimiters parenthesis}{def}

\NewDocumentEnvironment{lem}{ O{} O{} } % two optional arguments
    {\TcbLem{#1}{#2}}
    {\endTcbLem}



\begin{document}
\setcounter{section}{41}
\section{section}
\begin{thm}[][thm1]\label{sec:thm1}
kdd
\end{thm}
Theorem~\ref{th-thm1} and Section~\ref{sec:thm1}
\section{section}
\begin{thm}[][thm2]\label{sec:thm2}
    kdd
\end{thm}
Theorem~\ref{th-thm2} and Section~\ref{sec:thm2}
\section{section}
\section{section}
\end{document}

enter image description here

1
  • That works perfectly, thanks Commented May 12 at 15:55

You must log in to answer this question.

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