我想将框的标题垂直置于框顶部规则的中心。
不幸的是我似乎找不到办法根据标题文本和边距计算标题框的高度。
有什么好办法吗?
任何建议都非常感谢 :)
我到目前为止尝试过的:
在里面快速参考,列出了所有起作用的长度,并查看代码,我还得到了值
/tcp/titlerule
:\kvtcb@title@rule
/tcb/toptitle
:\kvtcb@toptitle
/tcb/bottomtitle
:\kvtcb@bottomtitle
/tcb/boxsep
:\kvtcb@boxsep
标题文本似乎也存储在中\tcbtitletext
。
然而,\kvtcb@…
似乎没有起到长度的作用,即0.5\kvtcb…
给出一个错误,我只能访问\tcbtitletext
里面盒子环境。
梅威瑟:
\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{many}
\tcbset{
enhanced,
breakable,
attach boxed title to top left={
xshift=0.5cm,
yshift= -3.5mm, % What do I put here? I'd like to have something like:
% yshift= -0.5\titleboxheight
},
top=4mm,
coltitle=black,
beforeafter skip=\baselineskip,
}
\newenvironment{mybox}[1]{%
\begin{tcolorbox}[title={A Box~--~#1}]%
}{
\end{tcolorbox}
}
\begin{document}
\begin{mybox}{This title box aligned correct}
Some text.
\end{mybox}
\begin{mybox}{This title box is too low}
Some text.
\end{mybox}
\begin{mybox}{\huge This title box is too high}
Some text.
\end{mybox}
\end{document}
生成:
答案1
看看是否yshift=-\tcboxedtitleheight/2
能解决你的问题(它的使用在10.2.2 盒装标题放置选项,tcolorbox
文档,第 159 页中有描述):
\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{many}
\tcbset{
enhanced,
breakable,
attach boxed title to top left={
xshift=0.5cm,
yshift=-\tcboxedtitleheight/2}, % <---
top=4mm,
coltitle=black,
beforeafter skip=\baselineskip,
}
\newenvironment{mybox}[1]{%
\begin{tcolorbox}[title={A Box~--~#1}]%
}{
\end{tcolorbox}
}
\begin{document}
\begin{mybox}{This title box aligned correct}
Some text.
\end{mybox}
\begin{mybox}{This title box is too low}
Some text.
\end{mybox}
\begin{mybox}{\huge This title box is too high}
Some text.
\end{mybox}
\end{document}