如果没有提供标题,如何跳过 newtcblisting 的编号

如果没有提供标题,如何跳过 newtcblisting 的编号

我定义了一个自定义的 newtcblisting,带有可选标题。我想\lstlistoflistings只保留带有标题的列表(这也会影响编号)。另外,我tcolorbox在索引中也有不需要的列表。

在 MWE 中,第二个列表的预期数字为 1,因为第一个列表没有标题:

平均能量损失

\documentclass[12pt]{book}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\usepackage{amssymb,amsmath,amsthm,amsfonts}
\usepackage[spanish]{babel}
\usepackage[nolist]{acronym}
\usepackage[table]{xcolor}
\usepackage[breakable,listings,skins,hooks]{tcolorbox}

\renewcommand{\lstlistingname}{Código} % Cambio 'Listing 4.1:' por 'Código 4.1:'
\renewcommand*{\lstlistlistingname}{Lista de cuadros de código}

\begin{document}

\lstdefinelanguage{isabelle}{
    keywords=[1]{abbreviation,by,contractLoop}
}
\lstdefinestyle{Isabelle}{
  language=isabelle,
  escapeinside={&}{&},
  columns=fixed,
  extendedchars,
  captionpos=b,                    
  breaklines=true,
  basewidth={0.5em,0.45em},
  basicstyle=\ttfamily,
  mathescape,
}

\newtcblisting[blend into=listings]{code}[2][]{%
 breakable,
 boxrule=0.75pt,
 listing options={ style={#2} },
 listing only,
 enhanced,
 listing remove caption=false,
 attach boxed title to bottom center={yshift=-8pt},
 before skip=15pt plus 2pt,after skip=15pt plus 2pt,
 boxed title style={enhanced jigsaw, colback=white, sharp corners, boxrule=0pt},
 coltitle=black,
 overlay first app={%
   \draw[dashed,line width=0.75pt,xshift=0.75pt] (frame.south east) -- (frame.south west); % chktex 8
  },
 overlay middle app={%
   \draw[dashed,line width=0.75pt,xshift=-0.75pt] (frame.north east) -- (frame.north west); % chktex 8
   \draw[dashed,line width=0.75pt,xshift=0.75pt] (frame.south east) -- (frame.south west); % chktex 8
  },
 overlay last app={%
   \draw[dashed,line width=0.75pt,xshift=-0.75pt] (frame.north east) -- (frame.north west); % chktex 8
  },
  #1
}



\begin{code}{Isabelle}
newtype Value = Value
    {getValue :: Map CurrencySymbol (Map TokenName Integer)}
\end{code}

\begin{code}[title=Definicion del tipo \texttt{Value}]{Isabelle}
newtype Value = Value
    {getValue :: Map CurrencySymbol (Map TokenName Integer)}
\end{code}


\end{document}

答案1

您可以定义一个新环境,例如code*,它混合到中listings,但没有编号并且不添加任何列表条目。

\newtcblisting[blend into=listings]{code}[2][]{my code env={#1}{#2}}
\newtcblisting[blend into=listings, no counter, list inside=]{code*}[2][]{my code env={#1}{#2}}

完整示例

\documentclass[12pt]{book}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\usepackage{amssymb,amsmath,amsthm,amsfonts}
\usepackage[spanish]{babel}
\usepackage[nolist]{acronym}
\usepackage[table]{xcolor}
\usepackage[breakable,listings,skins,hooks]{tcolorbox}

\renewcommand{\lstlistingname}{Código} % Cambio 'Listing 4.1:' por 'Código 4.1:'
\renewcommand*{\lstlistlistingname}{Lista de cuadros de código}

\begin{document}

\lstdefinelanguage{isabelle}{
    keywords=[1]{abbreviation,by,contractLoop}
}
\lstdefinestyle{Isabelle}{
  language=isabelle,
  escapeinside={&}{&},
  columns=fixed,
  extendedchars,
  captionpos=b,                    
  breaklines=true,
  basewidth={0.5em,0.45em},
  basicstyle=\ttfamily,
  mathescape,
}

\tcbset{
  my code env/.style 2 args={
    breakable,
    boxrule=0.75pt,
    listing options={ style={#2} },
    listing only,
    enhanced,
    listing remove caption=false,
    attach boxed title to bottom center={yshift=-8pt},
    before skip=15pt plus 2pt,after skip=15pt plus 2pt,
    boxed title style={enhanced jigsaw, colback=white, sharp corners, boxrule=0pt},
    coltitle=black,
    overlay first app={%
      \draw[dashed,line width=0.75pt,xshift=0.75pt] (frame.south east) -- (frame.south west); % chktex 8
    },
    overlay middle app={%
      \draw[dashed,line width=0.75pt,xshift=-0.75pt] (frame.north east) -- (frame.north west); % chktex 8
      \draw[dashed,line width=0.75pt,xshift=0.75pt] (frame.south east) -- (frame.south west); % chktex 8
    },
    overlay last app={%
      \draw[dashed,line width=0.75pt,xshift=-0.75pt] (frame.north east) -- (frame.north west); % chktex 8
    },
    #1
  }
}

\newtcblisting[blend into=listings]{code}[2][]{my code env={#1}{#2}}
\newtcblisting[blend into=listings, no counter, list inside=]{code*}[2][]{my code env={#1}{#2}}

\lstlistoflistings

\begin{code*}{Isabelle}
newtype Value = Value
    {getValue :: Map CurrencySymbol (Map TokenName Integer)}
\end{code*}

\begin{code}[title=Definicion del tipo \texttt{Value}]{Isabelle}
newtype Value = Value
    {getValue :: Map CurrencySymbol (Map TokenName Integer)}
\end{code}

\end{document}

在此处输入图片描述

相关内容