0

I'm a bit stack about using labels in my latex document, first, I have used this command to create a personal title

\newcommand {\mytitleTeo}[1]{                     
   \node[fill=red!30,
      rounded corners,
      draw=black,
      text=black,
      line width=1pt,
      inner sep=4pt,
      anchor=west,
      xshift=11pt]
   at (frame.north west){\bfseries #1};
}

After that Im using this in the next code

\newtcolorbox[auto counter,number within=chapter, number freestyle={\noexpand\thechapter.\noexpand\arabic{\tcbcounter}}]{theo}[1]{%
colback = white,
enhanced,
overlay unbroken and first={\mytitleTeo{\textbf{Teorema~\thetcbcounter: #1}}},  
colframe=black,
boxrule=1pt,
arc=3mm,
breakable,
top=15pt,
before=\vskip18pt,

}

The problem is that I don't know how to use \label{} in this environment because when I do \ref{} the number it generates don't coincide with the number of the \newtcolorbox

Thanks a lot.

I think this code will compile

\documentclass[12pt,oneside,onecolumn,openright]{book} 
\usepackage[T1]{fontenc}
\usepackage{titlesec, blindtext, color}
\definecolor{gray75}{gray}{0.75}
\newcommand{\hsp}{\hspace{20pt}}
\titleformat{\chapter}[hang]{\Huge\bfseries} 
{\thechapter\hsp\textcolor{gray75}{|}\hsp}{0pt}{\Huge\bfseries}
\usepackage {graphicx}
\usepackage{amsfonts, amsmath, amsthm, amssymb, amscd, latexsym 
,cancel,stmaryrd}
\usepackage{pifont}
\usepackage{wrapfig}
%\usepackage[margin=2cm, font=scriptsize, small, bf]{caption}
\usepackage{appendix}
\usepackage{eso-pic}

\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{dsfont}
\usepackage{subfigure,caption}
\usepackage{listings}
\usepackage{mathtools}
\usepackage{tcolorbox}
\tcbuselibrary{breakable,skins}
\usepackage{helvet}
\usepackage[full]{textcomp}
%\usepackage{xcolor}
\usepackage{nameref}
\makeindex
\usepackage{pstricks}
\usepackage{natbib}
\usepackage{xparse}
\usepackage{xargs}
\usepackage{multicol}
%\usepackage[ruled,vlined,lined,linesnumbered,algochapter]{algorithm2e} 
\usepackage{framed}
\usepackage{titletoc} 
%usepackage{etoolbox}
%\usepackage{algorithm}
%\usepackage{algorithmic}
\usepackage[breaklinks,colorlinks=true, pdfstartview=FitV, linkcolor=blue, 
citecolor=blue, urlcolor=blue]{hyperref}
\usepackage{ upgreek }
%\usepackage{pgf,tikz}
%\usepackage{mathrsfs}
\usetikzlibrary{arrows}
\usetikzlibrary{positioning ,shadows ,backgrounds ,arrows.meta, 
circuits.ee.IEC} 
%\usepackage{amsmath}
\usepackage{bm}
\usepackage{lmodern}
%\usepackage{fancyhdr}
%\usepackage{mathrsfs}
%\usetikzlibrary{arrows}
\usepackage{enumerate} 
%\usepackage[dvipsnames]{xcolor}
%\usepackage{vmargin}
\usepackage[spanish]{babel}
\usepackage[utf8]{inputenc}
\usepackage[margin=3cm]{geometry} 
\usepackage{makeidx}
\setlength{\parindent}{0cm}
%\usepackage{ mathrsfs }
%\usepackage{ amssymb }
%\usepackage{fancybox, calc}
%\usepackage{framed, color}
%\usepackage{graphicx}
%\usepackage{apacite}
\usepackage{float}
\usepackage{latexsym}
\usepackage{amssymb,amsfonts,amsthm}
\usepackage{pdfpages}
\usepackage{epstopdf}
\usepackage[all]{xy}
\usepackage{hyperref}
%\usepackage[colorlinks=false]{hyperref}
\usepackage{verbatim}
\usepackage[colorinlistoftodos]{todonotes}
%\usepackage[hidelinks]{hyperref}
\newcommand {\mytitleTeo}[2]{                    
\node[fill=red!30,
  rounded corners,
  draw=black,
  text=black,
  line width=1pt,
  inner sep=4pt,
  anchor=west,
  xshift=11pt]
  at (frame.north west){\bfseries #1};
  \label{#2},
    }
  \newtcolorbox[auto counter,number within=chapter, number freestyle= 
  {\noexpand\thechapter.\noexpand\arabic{\tcbcounter}}]{theo}[2]{%
     colback = white,
     enhanced,
     overlay unbroken and first={\mytitleTeo{\textbf{Teorema~\thetcbcounter: 
   #1}}{#2}}, 
     colframe=black,
     boxrule=1pt,
     arc=3mm,
     breakable,
     top=15pt,
     before=\vskip18pt,
    }
\hypersetup{colorlinks=true,linkcolor=Blue}
\begin{document}
\chapter{asdg}
\begin{theo}{Envoltura convexa, afín y positiva}{hola} \label{hola}
  wergregf
\end{theo}
\begin{theo}{sg}{hola} \label{hola2}
   wergregf
\end{theo}
\hyperref[hola]{Teorema \thechapter.\ref{hola}}
\hyperref[hola2]{Teorema \thechapter.\ref{hola2}}
\chapter{jjkk}
\begin{theo}{Envoltura convexa, afín y positiva}{} \label{hola3}
  wergregf
\end{theo}
\begin{theo}{sg}{hola} 
\label{hola4}
   wergregf
\end{theo}
\end{document}

Now I think it works

2
  • Welcomme. Please, add a compileable code.
    – AndréC
    Commented Aug 8, 2019 at 10:44
  • Still not compileable: Package kvsetkeys Error: Undefined key "with linkbordercolor) citecolor"
    – AndréC
    Commented Aug 8, 2019 at 12:06

1 Answer 1

1

You don't need to mix a \node with a tcolorbox, with just a tcolorbox can do it all. Even more, with a \newtcbtheorem command, you can declare the teorem and its aspect (see tcolorbox documentation or https://tex.stackexchange.com/a/236230/1952).

Once declared, the theorem box has two parameters, the teorem title and a label for further reference. This label is a suffix which will be added to a prefix formed by the fifth parameter in newtcbtheorem and a label separator (: by default).

You can start from following code. I've cleaned the preamble from your code because you had a lot of unnecessary or duplicated packages. It's easier to answer if you provide us with a minimum working (or not) example, where minimum means as short as possible. In your case the body was short, but the preamble not.

\documentclass[a4paper]{book} 
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage[margin=3cm]{geometry} 
\usepackage{lmodern}

\usepackage[most]{tcolorbox}

\setlength{\parindent}{0cm}

\tcbset{%
    mytheostyle/.style={
        enhanced,
        colback=white,
        colframe=black,
        fonttitle=\bfseries,
        colbacktitle=red!30,
        coltitle=black,
        boxrule=1pt,
        attach boxed title to top left={%
            yshift*=-\tcboxedtitleheight/2, 
            xshift=5mm},
        boxed title style={colframe=black}
    }
}

\newtcbtheorem[auto counter, number within=chapter]{mytheorem}{Teorema}{mytheostyle}{Teo}

\begin{document}

\chapter{uno}

\begin{mytheorem}{Un teorema}{1}
Esto es un teorema
\end{mytheorem}

\begin{mytheorem}{Otro teorema}{2}
Este es el teorema~\ref{Teo:2}, diferente del teorema~\ref{Teo:1}
\end{mytheorem}

Este es el teorema~\ref{Teo:2}, diferente del teorema~\ref{Teo:1} y diferente del teorema~\ref{Teo:3}

\chapter{dos}

\begin{mytheorem}{Otro teorema más}{3}
Este es el primer teorema del segundo capítulo
\end{mytheorem}

\end{document}

enter image description here

You must log in to answer this question.

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