0

In the MWE I would like the numbering:

enter image description here

\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}
46
  • What's the reason for tcolorbox when you essentially use no box?
    – egreg
    May 7 at 22:05
  • You should see the Magnum Opus! I use them with a vengeance. I just thought of the continued example to replace "In \Cref{XPL:1-n}" in a couple of places. As for the DEMOs, normally, I use a DEMO after each PROCEDURE but in a few places I need more than one DEMO after the PROCEDURE and I thought it would be better to keep the numbering of the DEMOS matched.with the numbering of the PROCEDURES. So, it;s not crucial but I sure hope you can fix it.
    – schremmer
    May 8 at 13:02
  • Hi, who are you directing this comment to? ("it;s not crucial but I sure hope you can fix it") May 9 at 13:19
  • @Simon Dispa That one was, before there was any answer, for egreg who, by the way, later cleaned up my MWE a bit. But I did send you a comment which should appear below your answer.
    – schremmer
    May 9 at 21:56
  • I have added DEFINITION and DEFINITIONrestated as per YASMAR and STURM as a possible clue to the reference issue.
    – schremmer
    May 9 at 22:13
1

UPDATE after several follow-up comments.

To get some automation, I defined several new tcolorboxes.

(1) For EXAMPLE mode: the normal tcolorbox and a second, used with the (Continuation), which keeps the same number and adds the word.

(2) For PROCEDURE mode: the normal box, the middle tcolorboxes with an alpha counter added, and the last one of this mode to reset the counters.

(3) The package hyperref has to be loaded with the option hypertexnames=false to avoid the jumping to wrong places. https://tex.stackexchange.com/a/3197/161015

I run several tests:

(1) Copy and pasted several boxes in the middle in both modes to test the automatisms.

(2) Started a new chapter to verify the first number and correct initialization.

(3) Checked all links.

To unclutter up the code, I put the EXAMPLE definitions and the DEMOS definitions in separate files, and also for the examples of use of EXAMPLE and PROCEDURE.

a

c

x1

x3

This the main code (updated)

% !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}

This the file 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 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

This is the file file PROCEDURE_def.tex (updated on request)

    %%%%%% 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 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

This the file 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 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
3
  • 1. In my preamble, I replaced my definition of EXAMPLE by your definition of EXAMPLE, EXAMPLEcont and EXAMPLEend in ref2 and it compiles. But there is something wrong with the references. 2. To trace, I changed colback=white to cyan in your EXAMPLE, to yellow in your EXAMPLEcont, and to green in your EXAMPLEend. (This showed that you forgot to use EXAMPLEend for the last EXAMPLE 1.2) The problem is that Cref{XPL:1-3} refers to the first EXAMPLE (Continued).
    – schremmer
    May 9 at 18:52
  • @schremmer Please see my updated answer. May 9 at 23:02
  • Will look it up tomorrow. Thanks
    – schremmer
    May 9 at 23:44
0

Except for the references to DEMOs, you can adjust manually adjust counters and titles

 \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}

enter image description here

1
  • Your answer for EXAMPLE (Continued) works perfectly. With DEMO, as you warned, there is trouble with references. 1. I cannot refer with Cref to DEMO 1.2a. 1.2b and 1.2c. 2. While DEMO 1.2a, 1.2b, 1.2c are all listedcorrectly in the Appendix they too all refer to Demo 2a. Because of the kind of reader I am writing for, I really cannot do that. (By the way, even though Demos do have titles, a, b, c can be included in the title with only a bit of tinkering.)
    – schremmer
    May 9 at 18:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.