0

This is a follow-up question from Google forms with tcolorbox

I am trying to get a higher top bar and a title and I get this: enter image description here

Is there a way to vertically center the title? When augmenting the height of the title bar, there appears more space above the content text (Some content...). Is it possible to fix that too?

The code:

\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}
11
  • halign title=flush center, has been commented out -- remove the % sign and try
    – js bibra
    May 19, 2020 at 9:46
  • As the "h" indicates, it aligns horizontally not vertically. And valign title=flush center gives an error: Package pgfkeys Error: I do not know the key '/tcb/valign title'
    – Pedro
    May 19, 2020 at 10:10
  • tex.stackexchange.com/a/196445/197451-- -- try ,center title
    – js bibra
    May 19, 2020 at 10:16
  • 1
    title={\vphantom{\scriptsize1}\\How to vertically center this title?}]
    – js bibra
    May 19, 2020 at 10:50
  • 1
    Thank you @jsbibra, although not the perfect solution, it is a "workaround" for the title.
    – Pedro
    May 20, 2020 at 13:01

2 Answers 2

1

A boxed title with equal top and bottom parameters will vertically center the title. Also this box allow to easily draw the title frame with a different color from box frame avoinding to use `overlay'.

As I didn't understand original arc and space definitions, I've preferred to declare a 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}

enter image description here

0

Use

title={\vphantom{\scriptsize1}\\How to vertically center this title?}]
1
  • this is a "workaround" option just for the title and the specified height, that will not work for a different height. Any clues to reduce the space above the content text?
    – Pedro
    May 20, 2020 at 18:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .