8

I'm trying to recreate my Google forms in Latex like this one:

enter image description here

You can seee that there is a color in the backgroud (can I use a minipage for this? Or another tcolorbox?) and then white background boxes for each question. The first problem I face is with that first box. The border is gray but the top (that overlays the gray border) is purple.

Here is a zoom of the right part:

enter image description here

How can I do all this in a simple way?

Here is my code:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tcolorbox}
\usepackage{xcolor}
\definecolor{googleform-header}{HTML}{673AB7}
\definecolor{googleform-bg}{HTML}{EDE7f6}

\begin{document}

\tcbset{colback=white,colframe=googleform-header}
\begin{tcolorbox}[toprule=3mm]
This is a \textbf{tcolorbox}.
\end{tcolorbox}

\end{document}

1 Answer 1

8

Something like this?

\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}
\newtcolorbox{googlebox}[1][]{%
  colback=white,colbacktitle=googleform-header,colframe=googleform-frame,
  enhanced,
  overlay={ \fill[googleform-header] 
    ([yshift=-1ex]frame.north west) -- 
    ([yshift=-1mm]frame.north west) arc[start angle=180,end angle=90,radius=1mm]
    --
    ([xshift=-1mm]frame.north east) arc[start angle=90,end angle=0,radius=1mm]
    --
    ([yshift=-1ex]frame.north east)  -- cycle;},
  boxrule=1pt,top=1ex+2mm,
    #1}

\begin{document}

\begin{googlebox}
This is a \textbf{\textsf{tcolorbox}} inspired by \textsf{Google}.
\end{googlebox}

\end{document}

enter image description here

enter image description here

There are of course ways to generalize this, such as

\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}
\pgfkeys{/tcb/googlebox/.cd,top bar/.initial=1ex,frame arc/.initial=1mm}
\newtcolorbox{googlebox}[1][]{%
  colback=white,colbacktitle=googleform-header,colframe=googleform-frame,
  enhanced,#1,
  overlay={ \fill[googleform-header] 
    ([yshift=-\pgfkeysvalueof{/tcb/googlebox/top bar}]frame.north west) -- 
    ([yshift=-\pgfkeysvalueof{/tcb/googlebox/frame arc}]frame.north west) arc[start angle=180,end angle=90,radius=1mm]
    --
    ([xshift=-\pgfkeysvalueof{/tcb/googlebox/frame arc}]frame.north east) arc[start angle=90,end angle=0,radius=1mm]
    --
    ([yshift=-\pgfkeysvalueof{/tcb/googlebox/top bar}]frame.north east)  -- cycle;},
  boxrule=0.6pt,top=\pgfkeysvalueof{/tcb/googlebox/top bar}+2mm,arc=\pgfkeysvalueof{/tcb/googlebox/frame arc}
 }

\begin{document}

\begin{googlebox}
This is a \textbf{\textsf{tcolorbox}} inspired by \textsf{Google}.
\end{googlebox}

\begin{googlebox}[googlebox/top bar=2ex]
This is a \textbf{\textsf{tcolorbox}} inspired by \textsf{Google}.
\end{googlebox}

\end{document}

enter image description here

enter image description here

Something that comes closer to your screenshot can be obtained with some minipage inside a \fcolorbox, say.

\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}
This is a \textbf{tcolorbox} inspired by Google.
\end{googlebox}

\begin{googlebox}[googlebox/top bar=0ex]
Question 1
\begin{itemize}% <- there are certainly better options to do this with enumitem
 \item[\Large$\circ$] Option 1
 \item[\Large$\circ$] Option 2
 \item[\Large$\circ$] Option $\pi$
\end{itemize}
\end{googlebox}

\begin{googlebox}[googlebox/top bar=0ex,
title={Some title?}]
Some content.
\end{googlebox}
\end{minipage}}

\end{document}

enter image description here

This version is "intelligent" in the sense that it drops the bar at the top if it is too small. That is, you can use this box also for boxes without top bar. (Please do not look at the implementation of the circles in itemize but consult enumitem instead. Discussing this here is however off-topic.)

6
  • Fantastic! Thank you very much @schrödingers-cat. So, if I want to replicate my first image, all I have to do is create another box with gray frame and put both boxes inside a minipage (or another tcolorbox without rounded corners)?
    – Pedro
    Commented May 18, 2020 at 18:36
  • 1
    @Pedro You could just use \pagecolor to color the background of the page. But yes, I think what you suggest works.
    – user194703
    Commented May 18, 2020 at 18:41
  • \pagecolor is for the entire page, right? I just want to replicate the first image and then put a caption below it. That's why I think minipage would work better. But I'm struggling with it.
    – Pedro
    Commented May 18, 2020 at 19:07
  • 1
    @Pedro I added a proposal for that.
    – user194703
    Commented May 18, 2020 at 19:14
  • Brilliant!!! Thank you very much again!! One last question, I'm trying to write another line of text below the first one. Tried using \` or \par` but it's not working. Any clues on how to set vertical spaces?
    – Pedro
    Commented May 18, 2020 at 19:28

You must log in to answer this question.

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