![我對“tcolorbox”的引用不起作用](https://rvso.com/image/400386/%E6%88%91%E5%B0%8D%E2%80%9Ctcolorbox%E2%80%9D%E7%9A%84%E5%BC%95%E7%94%A8%E4%B8%8D%E8%B5%B7%E4%BD%9C%E7%94%A8.png)
我只是想在文本中引用我的示例之一,但它總是標有上一個計數器(此處為節號)。
我的範例環境被定義為exmp
環境tcolorbox
本身。我知道問題可能來自我的newtcolorbox
定義,但我找不到從哪裡。如果您有任何想法,請告訴我。
我正在使用pdfLaTex
編譯器,這是我的最小程式碼:
\documentclass[justified,notoc,numbers]{tufte-handout}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{color}
\usepackage[most]{tcolorbox}
%-----------FOR DEMO-----------
\usepackage{lipsum}
%=======================================================
% FONT STYLE
%=======================================================
\renewcommand{\rmdefault}{ptm}
%=======================================================
% COUNTERS
%=======================================================
\newcounter{theexample}[section]
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
%=======================================================
% COLORS
%=======================================================
\definecolor{grey}{rgb}{0.9,0.9,0.9}
\definecolor{myColor}{rgb}{0.0, 0.5, 1.0}
\newtcolorbox{exmp}[1][]{
breakable,
enhanced,
borderline west={2pt}{0pt}{myColor},
sharp corners,
boxrule=0pt,
fonttitle={\large\bfseries},
coltitle={black},
title= {\textcolor{myColor}{Exemple \stepcounter{theexample}\thesection.\arabic{theexample}:} #1\\},
attach title to upper,
right=0pt,
top=0pt,
bottom=0pt,
frame hidden,
colback=white!80!gray,
}
\title{test - tex.stackexchange.com}
\author[Author Name \& Firstname]{Author Name \& Firstname}
%=======================================================
% GEOMETRY
%=======================================================
\geometry{
left=15mm, % left margin
textwidth=140mm, % main text block
headsep=10mm,
headheight = 0mm,
marginparsep=7mm, % gutter between main text block and margin notes
marginparwidth=50mm, % width of margin notes
bottom = 1.5cm,
top = 1.7cm
}
%=======================================================
% DOCUMENT
%=======================================================
\begin{document}
\section{Chapter 1:}
\subsection{Section 1.}
[![\subsection{Section 2.}][1]][1]
\begin{exmp}[My example's title]
\label{EX1}
\lipsum[1]
\end{exmp}
Try to reference to my example counter using \texttt{ref\{EX1\}}: \ref{EX1}
\end{document}
所以這裡的結果是
當我想要的是
多謝。
答案1
解決了:
問題確實出在我的參數聲明上,我需要 2 個而不是 1 個參數。 #1 是我的選擇,而 #2 將是我的標題。這是解決方案的程式碼:
\documentclass[justified,notoc,numbers]{tufte-handout}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{color}
\usepackage[most]{tcolorbox}
%-----------FOR DEMO-----------
\usepackage{lipsum}
%=======================================================
% FONT STYLE
%=======================================================
\renewcommand{\rmdefault}{ptm}
%=======================================================
% COUNTERS
%=======================================================
\newcounter{theexample}[section]
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
%=======================================================
% COLORS
%=======================================================
\definecolor{grey}{rgb}{0.9,0.9,0.9}
\definecolor{myColor}{rgb}{0.0, 0.5, 1.0}
\newtcolorbox{exmp}[2][]{
breakable,
enhanced,
borderline west={2pt}{0pt}{myColor},
sharp corners,
boxrule=0pt,
fonttitle={\large\bfseries},
coltitle={black},
title= {\textcolor{myColor}{Exemple \stepcounter{theexample}\thesection.\arabic{theexample}:} #2\\},
attach title to upper,
right=0pt,
top=0pt,
bottom=0pt,
frame hidden,
colback=white!80!gray,
#1,
}
\title{test - tex.stackexchange.com}
\author[Author Name \& Firstname]{Author Name \& Firstname}
%=======================================================
% GEOMETRY
%=======================================================
\geometry{
left=15mm, % left margin
textwidth=140mm, % main text block
headsep=10mm,
headheight = 0mm,
marginparsep=7mm, % gutter between main text block and margin notes
marginparwidth=50mm, % width of margin notes
bottom = 1.5cm,
top = 1.7cm
}
%=======================================================
% DOCUMENT
%=======================================================
\begin{document}
\section{Chapter 1:}
\subsection{Section 1.}
\subsection{Section 2.}
\begin{exmp}[label = EX1]{My example's title}
\lipsum[1]
\end{exmp}
Try to reference to my example counter using \texttt{ref\{EX1\}}: 1.1
\end{document}