为 tcbset beamer 添加计数器

为 tcbset beamer 添加计数器

我定义tcbset如下:

\tcbset{%
  left=6mm, right=6mm, top=6mm, bottom=6mm, middle=4mm,
}

\tcbset{%
  outerlayer/.style={%
    enhanced,
    sharpish corners=all,
    colbacktitle=dcol, 
    coltitle=white, coltext=dcol,
    left=1mm, 
    right=1mm, 
    top=1mm,
    bottom=1mm, 
    middle=4mm, 
    toptitle=1mm, 
    bottomtitle=1mm,
    fuzzy shadow={0mm}{0.9mm}{0.6mm}{0.2mm}{black!20!Grey}, % top
    fuzzy shadow={0mm}{-0.6mm}{-0.1mm}{0.2mm}{black!40!Grey}, % bottomSmall
    fuzzy shadow={0mm}{-0.2mm}{-0.2mm}{0.2mm}{black!20!Grey}, % bottomBig
    title filled, boxrule=0mm, %
    segmentation code={\path[draw=BGrey](segmentation.west) -- (segmentation.east);}
  },
  innerlayer/.style={outerlayer,
    noparskip, 
    breakable, 
    colback=dcol,%
    coltitle=black,
    coltext=white, 
    fonttitle={\bfseries \scshape}, 
  bottomtitle=1mm}
}

\newtcolorbox{card}[1][]{%
  outerlayer,
  title=#1,
}

\newtcolorbox{hlcard}[1][]{%
  innerlayer,box align=base,
   #1
}

现在,我想要在标题左侧添加一个可选的计数器。我的意思是:

\newtcolorbox{card}[1][<counter here>][]{%
      outerlayer,
      title=#2,
    }

并且当给出第一个可选框时,计数器应该出现(欢迎任何更好的方法)。

我怎样才能做到这一点?

答案1

由于你没有提供完整且可编译的最小工作示例(MWE),我尝试去建造它。

因此,我不知道您的颜色定义,因此我使用了red而不是dcolgray而不是Grey和 而blue不是BGrey

tcolorbox有一个auto counter选项允许计算特定类型的盒子(在您的示例中card,而不是hlcard)。

您可以使用\thetcbcounter在标题后自动添加数字。

\documentclass{beamer}

\usepackage{mwe}% <-- for testing purpose only, delete it
\usepackage[most]{tcolorbox}
\tcbset{%
    left=6mm, right=6mm, top=6mm, bottom=6mm, middle=4mm,
}

\tcbset{%
    outerlayer/.style={%
        enhanced,
        sharpish corners=all,
        colbacktitle=red, 
        coltitle=white, coltext=red,
        left=1mm, 
        right=1mm, 
        top=1mm,
        bottom=1mm, 
        middle=4mm, 
        toptitle=1mm, 
        bottomtitle=1mm,
        fuzzy shadow={0mm}{0.9mm}{0.6mm}{0.2mm}{black!20!gray}, % top
        fuzzy shadow={0mm}{-0.6mm}{-0.1mm}{0.2mm}{black!40!gray}, % bottomSmall
        fuzzy shadow={0mm}{-0.2mm}{-0.2mm}{0.2mm}{black!20!gray}, % bottomBig
        title filled, boxrule=0mm, %
        segmentation code={\path[draw=blue](segmentation.west) -- (segmentation.east);}
    },
    innerlayer/.style={outerlayer,
        noparskip, 
        breakable, 
        colback=red,%
        coltitle=black,
        coltext=white, 
        fonttitle={\bfseries \scshape}, 
        bottomtitle=1mm}
}

\newtcolorbox[auto counter]{card}[1][]{%
    outerlayer,
    title={#1~\thetcbcounter},
}

\newtcolorbox{hlcard}[1][]{%
    innerlayer,box align=base,
    #1
}

\begin{document}
    \begin{frame}
    \begin{card}[Title of the card box]
        Text of card box upper part
        \tcblower
        lower part
    \end{card}
    \begin{hlcard}
        hlcard box with no counter
    \end{hlcard}
    \begin{card}[Title of another card box]
        Text of anothe card box upper part
        \tcblower
        lower part
    \end{card}
    \end{frame}
\end{document}

在此处输入图片描述

相关内容