在 MWE 中我希望编号:
\documentclass[11pt]{book}
%================================================ Begin PREAMBLE
\usepackage{relsize} %Set the font size relative to the current font size
\usepackage[neveradjust]{paralist}%
\usepackage{titlesec}
\usepackage{etoolbox} %what does it do, why is it here?
\usepackage[dotinlabels]{titletoc}
\usepackage{tcolorbox}%
\tcbuselibrary{%Begin load libraries for tcolorbox
skins,%
raster,%
breakable,%
xparse,%
}%End load libraries for tcolorbox
\usepackage[hyperfootnotes=false]{hyperref}%[pdfborder={0 0 0}]
\usepackage{cleveref}% should be the last package
%============== Begin definition of EXAMPLE
\newcounter{XPL}%
\newtcolorbox%
[%beginForReferences
use counter= XPL,
number within=chapter,%
crefname={\textsc{example}}{\textsc{examples}},%
Crefname={\textsc{Example}}{\textsc{Examples}},%
]%endForReferences
{EXAMPLE}%NameEnvironment
[2][]%WhateverThatIs
{%beginDescription
detach title,before upper={\tcbtitle\quad},
left=-1mm,right=-1mm,
breakable,
enhanced,%
%grow to left by=5mm,
fontupper=\sffamily,
colback=white,
colframe=white,
fonttitle=\sffamily,
fonttitle=\bfseries,
coltitle=black,%
title={E\smaller{XAMPLE} \larger{\thetcbcounter}.\notblank{#2}{\hspace{2mm} #2}{}},%
#1,%
}%end Description
%============== End definition of EXAMPLE
%============== Begin definition of DEMO
\newcounter{DMO}%[chapter]
\newtcolorbox%
[%beginForReferences
use counter= DMO,
number within=chapter,%
list inside= DMO,%creates the list under tcblistof
%number freestyle={\noexpand\thechapter.\noexpand\arabic{\tcbcounter}~\noexpand\mytitlemod},%Makes for LONG titles in the references.
crefname={\textsc{demo}}{\textsc{demos}},%
Crefname={\textsc{Demo}}{\textsc{Demos}}%
]%endForReferences
{%beginNameEnvironment
DEMO%
}%endNameEnvironment
[2]%
[]%WhateverThatIs
{%begin Description OUTER tcbox
breakable,
enhanced,%
detach title,
attach title to upper=~,%
lower separated=true,
bicolor,%
boxrule=1mm,%
colframe=white,%controls both the background color for the top and the frame of the bottom
colback=white,%This is the background color below the title.
colbacklower=white,%This is the background color below the title.
top=0pt,
bottom=0pt,
boxsep=0pt,% Sets a common padding between text and frame of box. Added to left, right, top, bottom, and middle.
outer arc=2mm,%when line is thick. Else, can just use arc.
fontupper=\sffamily,
fontlower=\sffamily,
% fonttitle=\small\sffamily,
fonttitle=\bfseries,
coltitle=black,%
title={\textbf{D\smaller{EMO}}\hspace{1.5mm}\textbf{\thetcbcounter} \hspace{2mm} #2},%
#1%
}%end Description OUTER tcbox
%=========== End definition of DEMO
%================= Begin definition of DEFINITION
\newcounter{DFN}%[chapter] %To be entered in Control>ALL
\newtcolorbox%
[%beginForReferences
use counter= DFN,
number within=chapter,
list inside= DFN,%creates the list under tcblistof
%list type=definition,
crefname={\textsc{definition}}{\textsc{definitions}},%
Crefname={\textsc{Definition}}{\textsc{Definitions}},%
]%endForReferences
{%beginNameEnvironment
DEFINITION%
}%EndNameEnvironment
[2][]%Two brackets say to enter one label and one title?
{%beginDescription
detach title,%
before upper={\tcbtitle\quad},%
breakable,%
enhanced,%
arc=0.2mm,%
%fontupper=\sffamily,%NotSerifBecauseNotPartOfText
colback= yellow!30,%
colframe= yellow!35!black,%
fonttitle=\bfseries,%
coltitle=black,%
%code={\gdef\mytitlealert{#2}},%Used to make for LONG titles in the references.
title=D\smaller{EFINITION} \larger{\thetcbcounter\, #2},%
nameref={#2},%
list entry={D\smaller{EFINITION}~\larger{\thetcbcounter ~ #2}},%the default format puts the label upfront
#1,%Required for references.
}%end Description
%==================== End definition of DEFINITION
%================ Begin definition of DEFINITIONrestated as per YASMAR and STURM
\newcounter{DFNrst}
\newtcolorbox%
[%beginForReferences
use counter=DFNrst,
list inside= DFN,
%number within=chapter,%
crefname={definition (Restated)}{definitions (Restated)},%
Crefname={Definition (Restated)}{Definitions (Restated)},%
]%endForReferences
{%begin name environment
DEFINITIONrestated%
}%end name Environment
[3][]%
{%begin Format
detach title,%This prevents the top from being the color of the frame
before upper={\tcbtitle\quad},%This prevents the top from being the color of the frame
%breakable,%WHY NOT?
enhanced,%
arc=0.2mm,%
colback= yellow!30,%
colframe= yellow!35!black,%
fonttitle=\bfseries,%
coltitle=black,%
%begin TITLE
title= D\smaller{EFINITION} ~\larger{\ref{#2}}~(Restated) \nameref{#2},%
nameref={\getrefbykeydefault{#2}{name}{UNDEFINED REFERENCE}},%
list entry= D\smaller{EFINITION} ~\larger{\ref{#2}}~\nameref{#2} (Restated),%Order not the same as in THEOREMrestated
label type={DFNrst},
code={\renewcommand{\theDFNrst}{\getrefnumber{#2}}},
#1%,
%end TITLE
}%end Format
%============================== End definition of DEFINITIONrestated
as per YASMAR and STURM
%================================================ End PREAMBLE
\begin{document}
\chapter{Something}\label{1-0-0}.
\begin{EXAMPLE}[label={XPL:1-1}]{~}
Text
\end{EXAMPLE}
\begin{EXAMPLE}[label={XPL:1-2}]{~}
Text
\end{EXAMPLE}
\begin{EXAMPLE}[label={XPL:1-3}]{~}
Text
\end{EXAMPLE}
\begin{EXAMPLE}[label={XPL:1-4}]{~}
Text
\end{EXAMPLE}
\begin{EXAMPLE}[label={XPL:1-5}]{~}
Text
\end{EXAMPLE}
References: \Cref{XPL:1-1}, \Cref{XPL:1-2}, \Cref{XPL:1-3}
\bigskip
\begin{DEMO}[label={DMO:1-1}]{}
Text
\end{DEMO}
\begin{DEMO}[label={DMO:1-2}]{}
Text
\end{DEMO}
\begin{DEMO}[label={DMO:1-3}]{}
Text
\end{DEMO}
\begin{DEMO}[label={DMO:1-4}]{}
Text
\end{DEMO}
\begin{DEMO}[label={DMO:1-5}]{}
Text
\end{DEMO}
References: \Cref{DMO:1-1}, \Cref{DMO:1-2a}, \Cref{DMO:1-2b}, \Cref{DMO:1-2c}, \Cref{DMO:1-3}
%============================== begin DEFINITION
% \INDEX[]{direct problems} \INDEX[]{reverse problems} \INDEX[]{given reference info} \INDEX[]{given info of concern}
\begin{DEFINITION}[label={DFN:1-1}]{Title}
This is yak, yak.
\end{DEFINITION}
%============================== end DEFINITION
%============================== begin DEFINITION restated
\begin{DEFINITIONrestated}[label={DFN:1-1a}]{DFN:1-1}{~}%
This is now restated as YAK, YAK
\end{DEFINITIONrestated}
%================================== end DEFINITION restated
\end{document}
答案1
更新经过几次后续评论。
为了实现一些自动化,我定义了几个新的tcolorboxes
。
(1)例如模式:正常模式tcolorbox
和第二种模式,与 一起使用(Continuation)
,保留相同的数字并添加单词。
(2)对于 PROCEDURE 模式:普通框、添加了 alpha 计数器的中间 tcolorboxes,以及此模式的最后一个用于重置计数器的框。
(3)包中hyperref
必须装载选项,hypertexnames=false
以避免跳转到错误的地方。https://tex.stackexchange.com/a/3197/161015
我进行了几次测试:
(1)在两种模式下复制并粘贴中间的几个框来测试自动化功能。
(2)开始新的一章,验证第一个数字,并正确初始化。
(3)检查所有链接。
为了使代码更加整洁,我将 EXAMPLE 定义和 DEMOS 定义放在单独的文件中,同样,也将 EXAMPLE 和 PROCEDURE 的使用示例放在单独的文件中。
这是主要代码(已更新)
% !TEX TS-program = pdflatex
\documentclass[11pt]{book}
%================================================ Begin PREAMBLE
%
%%% added <<<<<<<<<<<<<<<<<
\usepackage{xpatch}
\xpretocmd{\chapter}{% reset counters & add some space in list
\setcounter{PROCstore}{0}%
\setcounter{DMOstore}{0}%
\setcounter{DMOm}{0}%
\setcounter{subDMOm}{0}%
\setcounter{PROCm}{0}%
\setcounter{subPROCm}{0}%
\addtocontents{PROC}{\protect\addvspace{10pt}}%
\addtocontents{DMO}{\protect\addvspace{10pt}}}%
{}{}
%% <<<<<<<<<<<<<<<<<<<<<<<<<<<
\usepackage[usenames,dvipsnames,table]{xcolor}
\definecolor{LightGray}{gray}{0.990}%gray is pre-defined; 1 is white
\definecolor{DarkGray}{gray}{0.85}%gray is pre-defined; 1 is white
\colorlet{LightBlue}{blue!3!white}%d color for the rest
\colorlet{DarkBlue}{blue!20!white}%second color for the rest
\newcommand{\INDEX}[2][]{\phantomsection%
\if\relax\detokenize{#1}\relax\index{#2}\label{ind:#2}%
\else\index{#2}\label{ind:#1}\fi%
}%
\newcommand{\DEX}[2][]{%
\if\relax\detokenize{#1}\relax\hyperref[ind:#2]{#2}%
% (\Cpageref{ind:#2})%
\else\hyperref[ind:#1]{#2}%
%(\Cpageref{ind:#1})%
\fi%
}%
\usepackage{relsize} %Set the font size relative to the current font size
\usepackage[neveradjust]{paralist}%
\usepackage{titlesec}
\usepackage{etoolbox} %what does it do, why is it here?
\usepackage[dotinlabels]{titletoc}
\usepackage{tcolorbox}%
\tcbuselibrary{%Begin load libraries for tcolorbox
skins,%
raster,%
breakable,%
xparse,%
}%End load libraries for tcolorbox
\usepackage[hypertexnames=false, hyperfootnotes=false]{hyperref} % changed <<<<<<<<<<<<<<<
\usepackage{cleveref}% should be the last package
\input{EXAMPLE_def} % EXAMPLE tcolorboxes
\input{PROCEDURE_def} % PROCEDURE tcolorboxes needs patch to reset chapter number
\input{DEMO_def} % DEMO tcolorboxes needs patch to reset chapter number
%================================================ End PREAMBLE
\begin{document}
\input{TestingText}
\end{document}
这是文件EXAMPLE_def.tex
%%%%%% file EXAMPLE_def starts G2-3 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
%============== Begin definition of EXAMPLE
\newcounter{XPL}%
\newcounter{XPLm}% just in case
\newtcolorbox%
[%beginForReferences
use counter= XPL,
number within=chapter,%
crefname={\textsc{example}}{\textsc{examples}},%
Crefname={\textsc{Example}}{\textsc{Examples}},%
]%endForReferences
{EXAMPLE}%NameEnvironment
[2][]%WhateverThatIs
{%beginDescription
detach title,
before upper={\tcbtitle\quad},
left=-1mm,right=-1mm,
breakable,
enhanced,%
%grow to left by=5mm,
fontupper=\sffamily,
colback=white,
colframe=cyan,
fonttitle=\sffamily,
fonttitle=\bfseries,
coltitle=black,%
top=0pt,
bottom=0pt,
title={E\smaller{XAMPLE} \larger{\theXPL}.\notblank{#2}{\hspace{2mm} #2}{}},%
#1,%
}%end Description
%============== End definition of EXAMPLE
%============== Begin definition of EXAMPLEcont
\newtcolorbox%
[%beginForReferences
use counter= XPL,
number within=chapter,%
crefname={\textsc{example}}{\textsc{examples}},%
Crefname={\textsc{Example}}{\textsc{Examples}},%
]%endForReferences
{EXAMPLEcont}%NameEnvironment
[2][]%WhateverThatIs
{%beginDescription
detach title,before upper={\tcbtitle\quad},
before title= \addtocounter{XPL}{-1}\addtocounter{XPLm}{1}, % count med in case if needed
left=-1mm,right=-1mm,
breakable,
enhanced,%
%grow to left by=5mm,
fontupper=\sffamily,
colback=white,
colframe=yellow,
fonttitle=\sffamily,
fonttitle=\bfseries,
coltitle=black,%
top=0pt,
bottom=0pt,
title={E\smaller{XAMPLE} \larger{\theXPL}.\notblank{#2}{\hspace{2mm}(Continued) #2}{}},%
#1,%
}%end Description
%============== End definition of EXAMPLEcont
%%%%%% file EXAMPLE_def ends <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
这是文件文件PROCEDURE_def.tex
(根据要求更新)
%%%%%% file PROCEDURE_def starts G4 1 needs patch <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
\newcounter{PROC}%[chapter] % \renewcommand{\thePROC}{\number\numexpr\value{PROC}+1\relax}% Display PROC+1
\newcounter{PROCm}%
\newcounter{PROCstore}%
\newcounter{subPROCm}% a b c .
\newcounter{subPROCpass}%% on off
%============== Begin definition of PROCEDURE
\newtcolorbox[%
auto counter,
number freestyle={\noexpand\thechapter.\noexpand\arabic{PROC}},
number within=chapter,%
list inside= PROC,%creates the list under tcblistof.
crefname={\textsc{procedure}}{\textsc{procedures}},%
Crefname={\textsc{Procedure}}{\textsc{Procedures}}%
]
{PROCEDURE}[2][]{%
code=%
\setcounter{PROC}{\value{PROCstore}}%
\setcounter{subPROCpass}{0}%
\addtocounter{PROC}{1} ,
after title=%
\setcounter{PROCstore}{\value{PROC}},
enhanced,
breakable,
detach title,
attach title to upper=~,%
lower separated=true,
bicolor,%
% boxrule=1mm,%
colframe=DarkBlue,%controls both the background color for the top and the frame of the bottom
colback=DarkBlue,%This is the background color below the title.
colbacklower=LightBlue,%This is the background color below the title.
top=0pt,
bottom=0pt,
boxsep=5pt,% Sets a common padding between text and frame of box. Added to left, right, top, bottom, and middle.
outer arc=2mm,%when line is thick. Else, can just use arc.
fontupper=\sffamily,
fontlower=\sffamily,
coltitle=black,%
nameref={#2},%
list entry={\textbf{P\smaller{ROCEDURE}}\hspace{1.5mm}\textbf{\thetcbcounter}\hspace{2mm} #2},%
title={\textbf{P\smaller{ROCEDURE}}\hspace{1.5mm}\textbf{\thetcbcounter}\hspace{2mm} #2},%
#1%
}
%=========== End definition of PROCEDURE
%============== Begin definition of PROCEDUREsub
\newtcolorbox[%
%use counter= PROC,
auto counter,
number within=chapter,
number freestyle={\noexpand\thechapter.\noexpand\arabic{PROCm}\noexpand\alph{subPROCm}},%
list inside= PROC,%creates the list under tcblistof.
crefname={\textsc{procedure}}{\textsc{procedures}},%
Crefname={\textsc{Procedure}}{\textsc{Procedures}},%
]
{PROCEDUREsub}[2][]{%
code=%
\setcounter{PROCm}{\value{PROCstore}}%
\addtocounter{PROCm}{1}%
\addtocounter{subPROCm}{1},
after title=%
\addtocounter{\tcbcounter}{1} ,
enhanced,
breakable,
detach title,
attach title to upper=~,%
lower separated=true,
bicolor,%
% boxrule=1mm,%
colframe=DarkBlue,%controls both the background color for the top and the frame of the bottom
colback=DarkBlue,%This is the background color below the title.
colbacklower=LightBlue,%This is the background color below the title.
top=0pt,
bottom=0pt,
boxsep=5pt,% Sets a common padding between text and frame of box. Added to left, right, top, bottom, and middle.
outer arc=2mm,%when line is thick. Else, can just use arc.
fontupper=\sffamily,
fontlower=\sffamily,
coltitle=black,%
nameref={#2},%
list entry= {\textbf{P\smaller{ROCEDURE}}\hspace{1.5mm}\textbf{\thetcbcounter}\hspace{2mm} #2},%
title= {\textbf{P\smaller{ROCEDURE}}\hspace{1.5mm}\textbf{\thetcbcounter}\hspace{2mm} #2},%
#1%
}
%=========== End definition of PROCEDURE sub
%============== Begin definition of PROCEDUREend
\newtcolorbox[%
%%use counter= PROCm,
auto counter,
number within=chapter,
number freestyle={\noexpand\thechapter.\noexpand\arabic{PROCm}\noexpand\alph{subPROCm}},%
list inside= PROC,%creates the list under tcblistof.
crefname={\textsc{procedure}}{\textsc{procedures}},%
Crefname={\textsc{Procedure}}{\textsc{Procedures}},%
]
{PROCEDUREend}[2][]{%
code=%
\setcounter{PROCm}{\value{PROCstore}}%
\addtocounter{PROCm}{1}%
\addtocounter{subPROCm}{1}%
\setcounter{subPROCpass}{1} ,
after title=%
\setcounter{PROCstore}{\value{PROCm}}%
\setcounter{subPROCm}{0},
enhanced,
breakable,
detach title,
attach title to upper=~,%
lower separated=true,
bicolor,%
% boxrule=1mm,%
colframe=DarkBlue,%controls both the background color for the top and the frame of the bottom
colback=DarkBlue,%This is the background color below the title.
colbacklower=LightBlue,%This is the background color below the title.
top=0pt,
bottom=0pt,
boxsep=5pt,% Sets a common padding between text and frame of box. Added to left, right, top, bottom, and middle.
outer arc=2mm,%when line is thick. Else, can just use arc.
fontupper=\sffamily,
fontlower=\sffamily,
coltitle=black,%
nameref={#2},%
list entry={\textbf{P\smaller{ROCEDURE}}\hspace{1.5mm}\textbf{\thetcbcounter}\hspace{2mm} #2},%
title={\textbf{P\smaller{ROCEDURE}}\hspace{1.5mm}\textbf{\thetcbcounter}\hspace{2mm} #2},%
#1%
}
%=========== End definition of PROCEDUREend
%%%%%% file PROCEDURE_def ends <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
这是文件 DEMO_def
%%%%%% file DEMO_def starts G4 1 needs patch <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
\newcounter{DMO}%[chapter] % \renewcommand{\theDMO}{\number\numexpr\value{DMO}+1\relax}% Display DMO+1
\newcounter{DMOm}%
\newcounter{DMOstore}%
\newcounter{subDMOm}% a b c
\newcounter{subDMOpass}%% on off
%============== Begin definition of DEMO
\newtcolorbox[%
auto counter,
number freestyle={\noexpand\thechapter.\noexpand\arabic{DMO}},
number within=chapter,%
list inside= DMO,%creates the list under tcblistof.
crefname={\textsc{demo}}{\textsc{demos}},%
Crefname={\textsc{Demo}}{\textsc{Demos}}%
]
{DEMO}[2][]{%
code=%
\setcounter{DMO}{\value{DMOstore}}%
\setcounter{subDMOpass}{0}%
\addtocounter{DMO}{1},
after title=%
\setcounter{DMOstore}{\value{DMO}},
enhanced,
breakable,
detach title,
attach title to upper=~,%
lower separated=true,
bicolor,%
% boxrule=1mm,%
colframe=DarkBlue,%controls both the background color for the top and the frame of the bottom
colback=DarkBlue,%This is the background color below the title.
colbacklower=LightBlue,%This is the background color below the title.
top=0pt,
bottom=0pt,
boxsep=5pt,% Sets a common padding between text and frame of box. Added to left, right, top, bottom, and middle.
outer arc=2mm,%when line is thick. Else, can just use arc.
fontupper=\sffamily,
fontlower=\sffamily,
coltitle=black,%
nameref={#2},%
list entry={\textbf{D\smaller{EMO}}\hspace{1.5mm}\textbf{\thetcbcounter}\hspace{2mm} #2},%
title={\textbf{D\smaller{EMO}}\hspace{1.5mm}\textbf{\thetcbcounter}\hspace{2mm} #2},%
#1%
}
%=========== End definition of DEMO
%============== Begin definition of DEMO sub
\newtcolorbox[%
%use counter= DMO,
auto counter,
number within=chapter,
number freestyle={\noexpand\thechapter.\noexpand\arabic{DMOm}\noexpand\alph{subDMOm}},%
list inside= DMO,%creates the list under tcblistof.
crefname={\textsc{demo}}{\textsc{demos}},%
Crefname={\textsc{Demo}}{\textsc{Demos}}%
]
{DEMOsub}[2][]{%
code=%
\setcounter{DMOm}{\value{DMOstore}}%
\addtocounter{DMOm}{1}%
\addtocounter{subDMOm}{1},
enhanced,
breakable,
detach title,
attach title to upper=~,%
lower separated=true,
bicolor,%
% boxrule=1mm,%
colframe=DarkBlue,%controls both the background color for the top and the frame of the bottom
colback=DarkBlue,%This is the background color below the title.
colbacklower=LightBlue,%This is the background color below the title.
top=0pt,
bottom=0pt,
boxsep=5pt,% Sets a common padding between text and frame of box. Added to left, right, top, bottom, and middle.
outer arc=2mm,%when line is thick. Else, can just use arc.
fontupper=\sffamily,
fontlower=\sffamily,
coltitle=black,%
nameref={#2},%
list entry={\textbf{D\smaller{EMO}}\hspace{1.5mm}\textbf{\thetcbcounter}\hspace{2mm} #2},%
title={\textbf{D\smaller{EMO}}\hspace{1.5mm}\textbf{\thetcbcounter}\hspace{2mm} #2},%
#1%
}
%=========== End definition of DEMO sub
%============== Begin definition of DEMO end
\newtcolorbox[%
%%use counter= DMOm,
auto counter,
number within=chapter,
number freestyle={\noexpand\thechapter.\noexpand\arabic{DMOm}\noexpand\alph{subDMOm}},%
list inside= DMO,%creates the list under tcblistof.
crefname={\textsc{demo}}{\textsc{demos}},%
Crefname={\textsc{Demo}}{\textsc{Demos}}%
]
{DEMOend}[2][]{%
code=%
\setcounter{DMOm}{\value{DMOstore}}%
\addtocounter{DMOm}{1}%
\addtocounter{subDMOm}{1}%
\setcounter{subDMOpass}{1},
after title=%
\setcounter{DMOstore}{\value{DMOm}}%
\setcounter{subDMOm}{0}%
\setcounter{DMOm}{0},
enhanced,
breakable,
detach title,
attach title to upper=~,%
lower separated=true,
bicolor,%
% boxrule=1mm,%
colframe=DarkBlue,%controls both the background color for the top and the frame of the bottom
colback=DarkBlue,%This is the background color below the title.
colbacklower=LightBlue,%This is the background color below the title.
top=0pt,
bottom=0pt,
boxsep=5pt,% Sets a common padding between text and frame of box. Added to left, right, top, bottom, and middle.
outer arc=2mm,%when line is thick. Else, can just use arc.
fontupper=\sffamily,
fontlower=\sffamily,
coltitle=black,%
nameref={#2},%
list entry={\textbf{D\smaller{EMO}}\hspace{1.5mm}\textbf{\thetcbcounter}\hspace{2mm} #2},%
title={\textbf{D\smaller{EMO}}\hspace{1.5mm}\textbf{\thetcbcounter}\hspace{2mm} #2},%
#1%
}
%=========== End definition of DEMOend
%%%%%% file DEMO_def ends <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
答案2
除了对 DEMO 的引用,您可以手动调整计数器和标题
\documentclass[11pt]{book}
%================================================ Begin PREAMBLE
\usepackage{relsize} %Set the font size relative to the current font size
\usepackage[neveradjust]{paralist}%
\usepackage{titlesec}
\usepackage{etoolbox} %what does it do, why is it here?
\usepackage[dotinlabels]{titletoc}
\usepackage{tcolorbox}%
\tcbuselibrary{%Begin load libraries for tcolorbox
skins,%
raster,%
breakable,%
xparse,%
}%End load libraries for tcolorbox
\usepackage[hyperfootnotes=false]{hyperref}%[pdfborder={0 0 0}]
\usepackage{cleveref}% should be the last package
%============== Begin definition of EXAMPLE
\newcounter{XPL}%
\newtcolorbox%
[%beginForReferences
use counter= XPL,
number within=chapter,%
crefname={\textsc{example}}{\textsc{examples}},%
Crefname={\textsc{Example}}{\textsc{Examples}},%
]%endForReferences
{EXAMPLE}%NameEnvironment
[2][]%WhateverThatIs
{%beginDescription
detach title,before upper={\tcbtitle\quad},
left=-1mm,right=-1mm,
breakable,
enhanced,%
%grow to left by=5mm,
fontupper=\sffamily,
colback=white,
colframe=white,
fonttitle=\sffamily,
fonttitle=\bfseries,
coltitle=black,%
title={E\smaller{XAMPLE} \larger{\thetcbcounter}.\notblank{#2}{\ #2}{}},%
#1,%
}%end Description
%============== End definition of EXAMPLE
%============== Begin definition of DEMO
\newcounter{DMO}%[chapter]
\newtcolorbox%
[%beginForReferences
use counter= DMO,
number within=chapter,%
list inside= DMO,%creates the list under tcblistof
%number freestyle={\noexpand\thechapter.\noexpand\arabic{\tcbcounter}~\noexpand\mytitlemod},%Makes for LONG titles in the references.
crefname={\textsc{demo}}{\textsc{demos}},%
Crefname={\textsc{Demo}}{\textsc{Demos}}%
]%endForReferences
{%beginNameEnvironment
DEMO%
}%endNameEnvironment
[2]%
[]%WhateverThatIs
{%begin Description OUTER tcbox
breakable,
enhanced,%
detach title,
attach title to upper=~,%
lower separated=true,
bicolor,%
boxrule=1mm,%
colframe=white,%controls both the background color for the top and the frame of the bottom
colback=white,%This is the background color below the title.
colbacklower=white,%This is the background color below the title.
top=0pt,
bottom=0pt,
boxsep=0pt,% Sets a common padding between text and frame of box. Added to left, right, top, bottom, and middle.
outer arc=2mm,%when line is thick. Else, can just use arc.
fontupper=\sffamily,
fontlower=\sffamily,
% fonttitle=\small\sffamily,
fonttitle=\bfseries,
coltitle=black,%
title={\textbf{D\smaller{EMO}}\hspace{1.5mm}\textbf{\thetcbcounter}#2},%
#1%
}%end Description OUTER tcbox
%=========== End definition of DEMO
%================================================ End PREAMBLE
\begin{document}
\chapter{Something}\label{1-0-0}.
\begin{EXAMPLE}[label={XPL:1-1}]{~}
To remain \textsc{Example} 1.1 with label XPL:1-1
\end{EXAMPLE}
\begin{EXAMPLE}[label={XPL:1-2}]{~}
To remain \textsc{Example} 1.2 with label XPL:1-2
\end{EXAMPLE}
\addtocounter{XPL}{-1}
\begin{EXAMPLE}[]{(Continued)}
To become \textsc{Example} 1.2 (Continued) with no label
\end{EXAMPLE}
\begin{EXAMPLE}[code={\addtocounter{XPL}{-1}}]{(Continued)}
To become \textsc{Example} 1.2 (Continued) with no label
\end{EXAMPLE}
\begin{EXAMPLE}[label={XPL:1-3}]{~}
To be \textsc{Example} 1.3 with label XPL:1-3
\end{EXAMPLE}
References: \Cref{XPL:1-1}, \Cref{XPL:1-2}, \Cref{XPL:1-3}
\bigskip
\begin{DEMO}[label={DMO:1-1}]{}
To remain DEMO 1.1 with label DMO:1-1
\end{DEMO}
\begin{DEMO}[label={DMO:1-2a}]{a}
To become DEMO 1.2a with label DMO:1-2a
\end{DEMO}
\begin{DEMO}[label={DMO:1-2b}, code={\addtocounter{DMO}{-1}}]{b}
To become DEMO 1.2b with label DMO:1-2b
\end{DEMO}
\begin{DEMO}[label={DMO:1-2c}, code={\addtocounter{DMO}{-1}}]{c}
To become DEMO 1.2c with label DMO:1-2c
\end{DEMO}
\begin{DEMO}[label={DMO:1-3}]{ test}
To be DEMO 1.3 with label DMO:1.3
\end{DEMO}
References: \Cref{DMO:1-1}, \Cref{DMO:1-2a}, \Cref{DMO:1-2b}, \Cref{DMO:1-2c}, \Cref{DMO:1-3}
\end{document}