标题不显示在 tcbox 中,只显示在 tcblist 中

标题不显示在 tcbox 中,只显示在 tcblist 中

“shorttitle”,即代码中最后一个 { } 内的文本,同时出现在和tcboxtcblist

但是“简称”通常太短而难以真正理解,因此在“简称”之下、之前,我还设置了\tcblower一个“长标题”。

但“简称”在tcbox

所以,我想要的是“简称”不是在 中显示tcbox并显示 仅有的在里面tcblist

以下是 MWE:

% !TEX TS-program = pdflatexmk
\documentclass[11pt]{book}
%+++++Begin PREAMBLE%+++++Begin PREAMBLE%+++++Begin PREAMBLE%+++++Begin PREAMBLE
%+++++Begin PREAMBLE%+++++Begin PREAMBLE%+++++Begin PREAMBLE%+++++Begin PREAMBLE
\usepackage{relsize}        %Set the font size relative to the current font size    
\usepackage{titlesec} 
\usepackage{etoolbox} %what does it do, why is it here?
\usepackage[dotinlabels]{titletoc}
\usepackage{tcolorbox}% 
\usepackage[hypertexnames=false, hyperfootnotes=false]{hyperref}%[pdfborder={0 0 0}] %added hypertextnames=false as per Simon Dispa See https://tex.stackexchange.com/questions/3188/what-does-the-hyperref-option-hypertexnames-do
%=======Begin tcolorbox ---The PACKAGE must be here. The tcolorboxes must be defined after cleveref.
    \tcbuselibrary{%Begin load libraries for tcolorbox  
        skins,%
        raster,%
        breakable,%
            }%End load libraries for tcolorbox      
\usepackage{xpatch}
%%% added according to SimonDipsa<<<<<<<<<<<<Modified according to NoteFromSimon
\xpretocmd{\chapter}{% reset counters & add some space in list
  \setcounter{PRCstore}{0}%
  \setcounter{DMOstore}{0}%
  \setcounter{DMOm}{0}%
  \setcounter{subDMOm}{0}%
  \setcounter{PRCm}{0}%
  \setcounter{subPRCm}{0}%
  \addtocontents{PRC}{\protect\addvspace{10pt}}%
  \addtocontents{DMO}{\protect\addvspace{10pt}}}%
{}{}%% <<<<<<<<<<<<<<<<<<<<<<<<<<<  
\usepackage{cleveref}% should be the last package
\newcounter{PRC}%[chapter] %   \renewcommand{\thePRC}{\number\numexpr\value{PRC}+1\relax}% Display PRC+1
\newcounter{PRCm}%
\newcounter{PRCstore}%
\newcounter{subPRCm}% a b c .
\newcounter{subPRCpass}%% on off
\newcounter{DMO}%[chapter] %  }% Display DMO+1
\newcounter{DMOm}%
\newcounter{DMOstore}%
\newcounter{subDMOm}% a b c 
\newcounter{subDMOpass}%% on off
%============== Begin definition of PROCEDURE
\newtcolorbox[%
auto counter, 
number freestyle={\noexpand\thechapter.\noexpand\arabic{PRC}},
number within=chapter,%
list inside= PRC,%creates the list under tcblistof.
crefname={\textsc{procedure}}{\textsc{procedures}},%
Crefname={\textsc{Procedure}}{\textsc{Procedures}}%  
]%endForReferences
{%begin name environment
PROCEDURE%
}%end name Environment
[2][]{%Whatever that is
    code=%  
    \setcounter{PRC}{\value{PRCstore}}%   
    \setcounter{subPRCpass}{0}%     
    \addtocounter{PRC}{1}   ,
    after title=%   
    \setcounter{PRCstore}{\value{PRC}}, 
    enhanced,
    breakable,
    detach title,
    attach title to upper=~,%
    lower separated=true,
    bicolor,%
    %   boxrule=1mm,%
    colframe=black,%controls both the background color for the top and the frame of the bottom
    colback=cyan,%This is the background color below the title.
    colbacklower=yellow,%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= PRC,
auto counter, 
number within=chapter, 
number freestyle={\noexpand\thechapter.\noexpand\arabic{PRCm}\noexpand\alph{subPRCm}},%
list inside= PRC,%creates the list under tcblistof.
crefname={\textsc{procedure}}{\textsc{procedures}},%
Crefname={\textsc{Procedure}}{\textsc{Procedures}},%    
]
{PROCEDUREsub}[2][]{%
    code=%
    \setcounter{PRCm}{\value{PRCstore}}%   
    \addtocounter{PRCm}{1}% 
    \addtocounter{subPRCm}{1},
    after title=%
    \addtocounter{\tcbcounter}{1} , 
    enhanced,
    breakable,
    detach title,
    attach title to upper=~,%
    lower separated=true,
    bicolor,%
%   boxrule=1mm,%
    colframe=black,%controls both the background color for the top and the frame of the bottom
    colback=cyan,%This is the background color below the title.
    colbacklower=yellow,%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 PROCEDUREsub
%=============== Begin definition of PROCEDUREend
\newtcolorbox[%
%%use counter= PRCm,
auto counter, 
number within=chapter, 
number freestyle={\noexpand\thechapter.\noexpand\arabic{PRCm}\noexpand\alph{subPRCm}},%
list inside= PRC,%creates the list under tcblistof.
crefname={\textsc{procedure}}{\textsc{procedures}},%
Crefname={\textsc{Procedure}}{\textsc{Procedures}},%    
]
{PROCEDUREend}[2][]{%
    code=%
    \setcounter{PRCm}{\value{PRCstore}}%   
    \addtocounter{PRCm}{1}% 
    \addtocounter{subPRCm}{1}% 
    \setcounter{subPRCpass}{1}  ,
    after title=%
    \setcounter{PRCstore}{\value{PRCm}}% 
        \setcounter{subPRCm}{0}, 
    enhanced,
    breakable,
    detach title,
    attach title to upper=~,%
    lower separated=true,
    bicolor,%
    %   boxrule=1mm,%
    colframe=black,%controls both the background color for the top and the frame of the bottom
    colback=cyan,%This is the background color below the title.
    colbacklower=yellow,%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
%+++++End PREAMBLE+++++End PREAMBLE+++++End PREAMBLE+++++End PREAMBLE
%+++++End PREAMBLE+++++End PREAMBLE+++++End PREAMBLE+++++End PREAMBLE

\begin{document}
%========================================== Begin PROCEDURE
\begin{PROCEDURE}[label={PRC:1-1}]{Short Title 1}

Long Title 1

\tcblower

Text of PROCEDURE 1.

\end{PROCEDURE}
%========================================== End PROCEDURE
%========================================== Begin PROCEDURErsub
\begin{PROCEDUREsub}[label={PRC:1-1}]{Short Title 2a}

Long Title 2a

\tcblower

Text of PROCEDURE 2a

\end{PROCEDUREsub}
%========================================== End PROCEDURErsub
%========================================== Begin PROCEDUREend
\begin{PROCEDUREend}[label={PRC:1-1}]{Short Title 2b}

Long Title 2b

\tcblower

Text of PROCEDURE 2b

\end{PROCEDUREend}
%========================================== End PROCEDUREend


    \tcblistof[\chapter]{PRC}{List of Procedures}%
\end{document}

这是一张图片

在此处输入图片描述

答案1

您可以从框中#2的定义中删除(第二个参数,即简称) 。您可以保留它,以便将简称保留在框列表中。因此,对于所有三个框,请更改titlelistentry

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

进入

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

完整的 MWE,稍微缩短了一点(使用手动计数器设置,而article不是book将框和列表放在一页上):

\documentclass[11pt]{article}
\usepackage{relsize}        %Set the font size relative to the current font size    
\usepackage{tcolorbox}% 
\usepackage{hyperref}
\tcbuselibrary{%Begin load libraries for tcolorbox  
   skins,%
   raster,%
   breakable,%
}%End load libraries for tcolorbox 
\newcounter{PRC}
\newcounter{PRCm}
\newcounter{subPRCm}
\newtcolorbox[%
auto counter, 
number freestyle={\noexpand\thesection.\noexpand\arabic{PRC}},
number within=section,%
list inside= PRC,%creates the list under tcblistof.
]%endForReferences
{%begin name environment
PROCEDURE%
}%end name Environment
[2][]{%Whatever that is
    enhanced,
    breakable,
    detach title,
    attach title to upper=~,%
    lower separated=true,
    bicolor,%
    colframe=black,%controls both the background color for the top and the frame of the bottom
    colback=cyan,%This is the background color below the title.
    colbacklower=yellow,%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}},%
    #1%
}%
%============== End definition of PROCEDURE
%============== Begin definition of PROCEDUREsub   
\newtcolorbox[%
auto counter, 
number within=section, 
number freestyle={\noexpand\thesection.\noexpand\arabic{PRCm}\noexpand\alph{subPRCm}},%
list inside= PRC,%creates the list under tcblistof.
]
{PROCEDUREsub}[2][]{%
    enhanced,
    breakable,
    detach title,
    attach title to upper=~,%
    lower separated=true,
    bicolor,%
%   boxrule=1mm,%
    colframe=black,%controls both the background color for the top and the frame of the bottom
    colback=cyan,%This is the background color below the title.
    colbacklower=yellow,%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}},%
    #1%
}%
%================ End definition of PROCEDUREsub
%=============== Begin definition of PROCEDUREend
\newtcolorbox[%
auto counter, 
number within=section, 
number freestyle={\noexpand\thesection.\noexpand\arabic{PRCm}\noexpand\alph{subPRCm}},%
list inside= PRC,%creates the list under tcblistof.
]
{PROCEDUREend}[2][]{%
    enhanced,
    breakable,
    detach title,
    attach title to upper=~,%
    lower separated=true,
    bicolor,%
    %   boxrule=1mm,%
    colframe=black,%controls both the background color for the top and the frame of the bottom
    colback=cyan,%This is the background color below the title.
    colbacklower=yellow,%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}},%
    #1%
}%
%=========== End definition of PROCEDUREend

\begin{document}
%========================================== Begin PROCEDURE
\setcounter{PRC}{1}
\setcounter{PRC}{1}
\begin{PROCEDURE}[label={PRC:1-1}]{Short Title 1}

Long Title 1

\tcblower

Text of PROCEDURE 1.

\end{PROCEDURE}
%========================================== End PROCEDURE
%========================================== Begin PROCEDURErsub
\setcounter{PRCm}{2}
\setcounter{subPRCm}{1}
\begin{PROCEDUREsub}[label={PRC:2-1}]{Short Title 2a}

Long Title 2a

\tcblower

Text of PROCEDURE 2a

\end{PROCEDUREsub}
%========================================== End PROCEDURErsub
%========================================== Begin PROCEDUREend
\setcounter{subPRCm}{2}
\begin{PROCEDUREend}[label={PRC:2-2}]{Short Title 2b}

Long Title 2b

\tcblower

Text of PROCEDURE 2b

\end{PROCEDUREend}
%========================================== End PROCEDUREend

\tcblistof[\section]{PRC}{List of Procedures}%
\end{document}

结果:

在此处输入图片描述

相关内容