我只是想在我的文本中引用我的一个例子,但它总是标有上方的前一个计数器(这里是章节编号)。
我的示例环境被定义为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}