我正在尝试在 Latex 中重新创建我的 Google 表单,如下所示:
您可以看到背景中有颜色(我可以使用 minipage 来实现这一点吗?或者另一个 tcolorbox?),然后每个问题都有白色背景框。我遇到的第一个问题是第一个框。边框是灰色的,但顶部(覆盖灰色边框)是紫色的。
以下是右侧部分的放大图:
我怎样才能以一种简单的方式完成这一切?
这是我的代码:
\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
像这样吗?
\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}
当然,有很多方法可以概括这一点,例如
\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}
比如说,可以通过里面的某些小页面来获得更接近你截图的效果\fcolorbox
。
\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}
此版本是“智能”的,因为如果顶部栏太小,它会将其放下。也就是说,您也可以将此框用于没有顶部栏的框。(请不要查看 itemize 中圆圈的实现,而是参考enumitem
。不过,在这里讨论这个问题是题外话。)