我在计数器方面遇到问题:newtcbtheorem
的计数器与newtheorem
的计数器相冲突。我该如何解决我的问题?非常感谢。希望我的问题清楚。
\PassOptionsToPackage{svgnames, x11names}{xcolor}
\documentclass[openany]{book}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[italian]{babel}
\usepackage[utf8]{inputenc}
\usepackage[a4paper,top=3cm,bottom=3cm,left=1.5cm,right=1.5cm]{geometry}
\usepackage[svgnames,x11names]{xcolor}
\usepackage{amscd}
\usepackage{color}
\usepackage{stix}
\usepackage{mathtools}
\usepackage{amsthm}
\usepackage{imakeidx}
\usepackage[tight, italian]{minitoc}
\usepackage[most]{tcolorbox}
\tcbuselibrary{breakable,theorems,skins}
\usepackage[colorlinks=true]{hyperref}
\hypersetup{pdfstartview=FitH}
\usepackage{cleveref}
% New Exercises
\newtcbtheorem[number within=subsection] {exercise}{Esercizio}{%
enhanced, colback=red!5!white, colframe=gray, sharpish corners, breakable, fonttitle=\bfseries, coltitle=green, separator sign={\ ---},#1, description delimiters={$\bigl($}{$\bigr)$}}{ex}
\newtcbtheorem[use counter from=exercise] {solex}{}{enhanced, colback=red!5!white, colframe=gray, sharpish corners, breakable, separator sign none, fonttitle=\bfseries, coltitle=green, #1}{solex}
\newtheorem{esercizio}{Esercizio}[subsection]
% Per le soluzioni
\tcbset{exercise ref/.initial=,}
\newtcbtheorem[number within=subsection]{SolEx}{Soluzione dell'\Exref{\pgfkeysvalueof{/tcb/exercise ref}}}{enhanced, colback=red!5!white, colframe=black, sharpish corners, breakable, separator sign none, fonttitle=\bfseries, coltitle=orange}{ex}
% Nuove ref
\newcommand{\Exref}[1]{\textcolor{red}{Esercizio} \ref{ex:#1}}
\begin{document}
\Large
\begin{exercise}{Esercizio d'esempio}{EX1}
\end{exercise}
\begin{SolEx*}[exercise ref={EX1}]
\end{SolEx*}
\begin{esercizio}
\end{esercizio}
Problem with counter: I'd like this\\
\textbf{Esercizio 0.0.0.2}
\end{document}
答案1
因此您必须将 tcb-environmentexercise
的计数器放入第一个可选参数中,即tcb@cnt@exercise
。
使用
\makeatletter
\newtheorem{esercizio}[tcb@cnt@exercise]{Esercizio}
\makeatother
代替
\newtheorem{esercizio}{Esercizio}[subsection]
将工作。