有没有办法让标题垂直居中?增加标题栏的高度时,内容文本上方会出现更多空间(部分内容……)。是否也可以修复这个问题?
代码:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[skins]{tcolorbox}
\definecolor{googleform-header}{HTML}{673AB7}
\definecolor{googleform-bg}{HTML}{EDE7f6}
\definecolor{googleform-frame}{RGB}{218,219,223}
\definecolor{googleform-pagebg}{RGB}{238,234,247}
\pgfkeys{/tcb/googlebox/.cd,top bar/.initial=1ex,frame arc/.initial=1mm}
\newtcolorbox{googlebox}[1][]{%
colback=white,colbacktitle=googleform-header,colframe=googleform-frame,
enhanced,width=0.9\linewidth,%halign title=flush center,
#1,
overlay={\pgfmathsetmacro\mytop{\pgfkeysvalueof{/tcb/googlebox/top bar}}
\pgfmathsetmacro\myarc{\pgfkeysvalueof{/tcb/googlebox/frame arc}}
\ifdim\mytop pt>\myarc pt
\fill[googleform-header]
([yshift=-\mytop pt]frame.north west) --
([yshift=-\myarc pt]frame.north west) arc[start angle=180,end angle=90,radius=\myarc pt]
--
([xshift=-\myarc pt]frame.north east) arc[start angle=90,end angle=0,radius=\myarc pt]
--
([yshift=-\mytop pt]frame.north east) -- cycle;
\fi},
boxrule=0.6pt,top=\pgfkeysvalueof{/tcb/googlebox/top bar}+2mm,
arc=\pgfkeysvalueof{/tcb/googlebox/frame arc},
fontupper=\sffamily,fonttitle=\sffamily
}
\begin{document}
\fcolorbox{googleform-pagebg}{googleform-pagebg}{\begin{minipage}{0.9\textwidth}
\centering
\begin{googlebox}[googlebox/top bar=7ex,
title={How to vertically center this title?}]
Some content with too much space above.
\end{googlebox}
\end{minipage}}
\end{document}
答案1
boxed title
具有相等top
和参数的Abottom
将使标题垂直居中。此外,此框允许使用与框框不同的颜色轻松绘制标题框,从而避免使用“覆盖”。
由于我不理解原文arc
和space
定义,我宁愿声明一个newgooglebox
。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[skins]{tcolorbox}
\definecolor{googleform-header}{HTML}{673AB7}
\definecolor{googleform-bg}{HTML}{EDE7f6}
\definecolor{googleform-frame}{RGB}{218,219,223}
\definecolor{googleform-pagebg}{RGB}{238,234,247}
\newtcolorbox{newgooglebox}[2][]{%
enhanced, boxrule=.6pt, fontupper=\sffamily, fonttitle=\sffamily,
colframe=googleform-frame, colback=white,
colbacktitle=googleform-header, arc=1mm,
attach boxed title to top,
boxed title style={colframe=googleform-header, top=3mm, bottom=3mm},
center,
title={#2},
#1
}
\newtcolorbox{backbox}[1][]{%
enhanced, size=tight, boxrule=0pt, frame hidden, colback=googleform-pagebg,
sharp corners, left=8mm, right=8mm, top=2mm, bottom=2mm, halign=center,
}
\begin{document}
\begin{backbox}
\begin{newgooglebox}{How to vertically center this title?}
Some content with too much space above.
\end{newgooglebox}
\end{backbox}
\begin{backbox}
\begin{newgooglebox}[width=.7\linewidth]{How to vertically center this title?}
Some content with too much space above.
\end{newgooglebox}
\end{backbox}
\end{document}
答案2
使用
title={\vphantom{\scriptsize1}\\How to vertically center this title?}]