我已经阅读了本网站上的几个关于练习解答。但不幸的是他们没有帮助我。
这是我的目标:我想创造一个新的tcolorbox 环境我有2 个强制参数,第一个是\Exref
这样定义的,
\newcommand{\Exref}[1]{Exercise \ref{ex:#1}}
第二个必须标记整个环境(此标签必须具有某种前缀,即“solex”)并且必须是这种类型\label{solex:<Solution of the Exercise to which it refers>}
。我该怎么办?在下面发布的代码中,我尝试了某种方式并且它有效(每次我都必须手动构建它并且浪费了很多时间)。非常感谢代码(我希望我的问题很清楚)
\documentclass{book}
%\usepackage[italian]{babel}
\usepackage[english]{babel}
\usepackage[a4paper,top=3cm,bottom=3cm,left=1.5cm,right=1.5cm]{geometry}
\usepackage[svgnames,x11names]{xcolor}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{amsthm}
\usepackage{stix}
\usepackage[most]{tcolorbox}
\tcbuselibrary{theorems}
\usepackage{imakeidx}
\usepackage[tight,english]{minitoc}
%New Tcolorboxed Exercise
% 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=,}
\newtcbox{\SolEx}[1]{enhanced, colback=red!5!white, colframe=gray, sharpish corners, breakable, fonttitle=\bfseries, coltitle=green, title={#1}}
%\newtcbtheorem[use counter from=exercise] {solex}{Soluzione dell'\Exref{\pgfkeysvalueof{/tcb/exercise ref}}}{enhanced, colback=red!5!white, colframe=gray, sharpish corners, breakable fonttitle=\bfseries, coltitle=green, exercise ref={#1}}{ex}
% New ref
\newcommand{\Exref}[1]{Exercise \ref{ex:#1}}
\begin{document}
\title{\Huge\textcolor{red}{\textbf{Proof Book}}}
\author{\color{blue}{\Huge{\textbf{???}}}}
\maketitle
\dominitoc
\begin{tcolorbox}[enhanced,title=\Huge{Contents},colframe=orange,colback=Silver!75,colbacktitle=Gold1,fonttitle=\bfseries,coltitle=red,attach boxed title to top center={yshift=-0.25mm-\tcboxedtitleheight/2,yshifttext=2mm-\tcboxedtitleheight/2},boxed title style={boxrule=0.5mm, frame code={ \path[tcb fill frame]([xshift=-4mm]frame.west) -- (frame.north west) -- (frame.north east) -- ([xshift=4mm]frame.east) -- (frame.south east) -- (frame.south west) -- cycle; },interior code={ \path[tcb fill interior] ([xshift=-2mm]interior.west) -- (interior.north west) -- (interior.north east) -- ([xshift=2mm]interior.east) -- (interior.south east) -- (interior.south west) -- cycle;} }] %\csname @starttoc\endcsname{toc}
\makeatletter \@starttoc{toc} \makeatother
\end{tcolorbox}
%\tableofcontents
\part[Second Example Part]{\Huge\textcolor{red}{Second Example Part}}
\chapter[Tcolorboxed Exerxises]{\huge Tcolorboxed Exercises}
\minitoc
\mtcskip
\section[Exercise: \LaTeX--function]{\Large Exercise: \LaTeX--function}
\subsection[With Tcolorbox--package]{\large With Tcolorbox--package}
\begin{exercise}{Exercise example}{Exercise example}
Un Exercise example with Tcolorbox--package.
\end{exercise}
\begin{exercise}{How much $1+1$ ?}{1+1}
Calculate $1+1$.
\end{exercise}
\begin{solex*}{Solution of \Exref{1+1} at page \pageref{ex:1+1}} %{Solex 1+1}
Answer: 2
\end{solex*}
\end{document}
最后用一张图片来简化我的问题: