我使用 tcolorbox 在方程式周围绘制方框。由于方框宽度等于方程式宽度,长标题通常会缩小,因此看起来很丑陋,如下所示:
有什么办法可以在方程式和标题周围绘制一个自动宽度的框吗?
最小工作示例如下:
\documentclass[11pt]{article}
\usepackage[many]{tcolorbox}
\begin{document}
\begin{equation}
\tcbhighmath[title=A long title hence does not fit]{\lambda=at^2}
\end{equation}
\begin{equation}
\tcbhighmath[title=short-title]{\lambda=at^2+bt^3}
\end{equation}
\end{document}
答案1
一种不同的方法是定义一个新键autowidth title
,使最小值text width
等于title
长度
\documentclass[11pt]{article}
\usepackage[many]{tcolorbox}
\pgfkeysdef{/tcb/autowidth title}{
\pgfmathwidth{"#1"}
\def\width{\pgfmathresult pt} % \width = title length
%
\tcbset{title=#1,
tcbox width=minimum center,
text width=\width % minimum text width = title length
}
}
\begin{document}
\begin{equation}
\tcbhighmath[autowidth title=A long title hence does not fit ]{\lambda=at^2}
\end{equation}
\begin{equation}
\tcbhighmath[autowidth title=short-title]{\lambda=at^2+bt^3}
\end{equation}
\end{document}
答案2
摘自 Thomas F. Sturm 的这幅优秀宏图:....适合宽度....,这是我的适应答案:
\documentclass[11pt]{article}
\usepackage[many]{tcolorbox}
\tcbset{longtitle/.style={%
title={#1},
before upper={\begin{tabular}{@{}l@{}l}\phantom{#1}\\[\the\dimexpr-\ht\strutbox-\dp\strutbox]},
after upper={\end{tabular}}}
}
\begin{document}
\begin{equation}
\tcbhighmath[longtitle=A long title hence does now fit]{$\lambda=at^2$}%<---- for a double dollar
\end{equation}
\begin{equation}
\tcbhighmath[title=short-title]{\lambda=at^2+bt^3}%<---- without a double dollar
\end{equation}
\end{document}
避免$
在主要论点中出现字符的修复方法:
\documentclass[11pt]{article}
\usepackage{array}
\usepackage[many]{tcolorbox}
\tcbset{longtitle/.style={%
title={#1},
before upper={%
$\begin{array}{@{}>{\displaystyle}l@{}}
\mbox{\phantom{#1}}\\[\the\dimexpr-\ht\strutbox-\dp\strutbox]%
},
after upper={\end{array}$}},
}
\begin{document}
\begin{equation}
\tcbhighmath[longtitle=A long title hence does now fit]{\lambda=at^2}
\end{equation}
\begin{equation}
\tcbhighmath[title=short-title]{\lambda=at^2+bt^3}
\end{equation}
\end{document}