我對在乳膠文件中使用標籤有點了解,首先,我使用此命令建立個人標題
\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,
}
問題是我不知道如何在這種環境中使用 \label{} 因為當我執行 \ref{} 時它產生的數字與 \newtcolorbox 的數字不一致
多謝。
我認為這段程式碼可以編譯
\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
您不需要將 a\node
與 a混合使用tcolorbox
,只需 atcolorbox
即可完成所有操作。更重要的是,使用\newtcbtheorem
命令,您可以聲明定理及其方面(請參閱tcolorbox
文件或https://tex.stackexchange.com/a/236230/1952)。
聲明後,定理框有兩個參數,即定理標題和進一步參考的標籤。此標籤是一個後綴,將添加到由第五個參數 innewtcbtheorem
和 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}