我正在准备一份使用基本单元格的文档tcolorbox
,如下所示:
\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{skins, breakable}
\newtcolorbox[auto counter, number within=section]{mybox}[1]{title=\thetcbcounter: #1}
\begin{document}
\section{Monday}
\begin{mybox}{A long long story}
Explanation
\end{mybox}
\section{Tuesday}
\begin{mybox}{Another long long story}
Explanation
\end{mybox}
\end{document}
每个部分都有多个单元格。标题和内容都比较长。就我而言,将计数器放在标题中会让人觉得视觉上很烦人,所以我希望将其作为单独的标签移到外面,如下所示:
主细胞仍然水平对齐在页面中,以及标签单元指主细胞的计数器。有没有方便或合适的方法来做到这一点?
答案1
您可以使用overlay unbroken and first
键添加带有计数器的节点(根据需要调整设置):
\documentclass{article}
\usepackage[many]{tcolorbox}
\newtcolorbox[auto counter, number within=section]{mybox}[1]{
enhanced,
title=#1,
overlay unbroken and first ={
\node[anchor=north east,rounded corners,draw=black!80,fill=gray!30,line width=0.5mm,text width=2.5em,align=center,minimum height=4ex] at ([xshift=-\marginparsep]frame.north west) {\thetcbcounter};
}
}
\begin{document}
\section{Monday}
\begin{mybox}{A long long story}
Explanation
\end{mybox}
\section{Tuesday}
\begin{mybox}{Another long long story}
Explanation
\end{mybox}
\end{document}
相同的想法,但是在\tcbox
里面\node
放置计数器:
\documentclass{article}
\usepackage[many]{tcolorbox}
\newtcolorbox[auto counter, number within=section]{mybox}[1]{
enhanced,
title=#1,
overlay unbroken and first ={
\node[anchor=north east,inner sep=0pt,outer sep=0pt] at ([xshift=-\marginparsep]frame.north west) {\tcbox[boxsep=0pt]{\thetcbcounter}};
}
}
\begin{document}
\section{Monday}
\begin{mybox}{A long long story}
Explanation
\end{mybox}
\section{Tuesday}
\begin{mybox}{Another long long story}
Explanation
\end{mybox}
\end{document}