환경 \tcolorbox 및 개인 제목과 함께 레이블 사용

환경 \tcolorbox 및 개인 제목과 함께 레이블 사용

저는 라텍스 문서에서 라벨을 사용하는 것에 대해 조금 서툴러서 먼저 이 명령을 사용하여 개인 제목을 만들었습니다.

\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};
}

그 후 나는 다음 코드에서 이것을 사용합니다

\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,

}

문제는 \ref{}를 수행할 때 생성된 숫자가 \newtcolorbox의 숫자와 일치하지 않기 때문에 이 환경에서 \label{}을 사용하는 방법을 모른다는 것입니다.

정말 감사합니다.

내 생각엔 이 코드가 컴파일될 것 같아

\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}

이제 효과가 있는 것 같아요

답변1

\nodea 와 a를 혼합할 필요가 없습니다 tcolorbox. a만 있으면 tcolorbox모든 것이 가능합니다. 더욱이 \newtcbtheorem명령을 사용하면 테오렘과 해당 측면을 선언할 수 있습니다( tcolorbox문서 참조 또는https://tex.stackexchange.com/a/236230/1952).

일단 선언되면 정리 상자에는 정리 제목과 추가 참조를 위한 레이블이라는 두 개의 매개변수가 있습니다. 이 라벨은 의 다섯 번째 매개변수 newtcbtheorem와 a label separator( :기본값) 로 구성된 접두사에 추가되는 접미사입니다 .

다음 코드에서 시작할 수 있습니다. 불필요하거나 중복된 패키지가 많기 때문에 코드에서 서문을 정리했습니다. 를 제공하면 답변하기가 더 쉽습니다 minimum working (or not) example. 여기서 최소는 가능한 한 짧다는 것을 의미합니다. 귀하의 경우 본문은 짧았지만 서문은 그렇지 않았습니다.

\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}

여기에 이미지 설명을 입력하세요

관련 정보