我试图将tcolorbox
页面垂直居中,但下面的代码使框并不正好位于页面的中间。
到目前为止我已经尝试过这个:
\documentclass[12pt]{article}
\usepackage{geometry}
\geometry{paper=letterpaper,margin=2cm}
\usepackage[autostyle]{csquotes}
\usepackage[dvipsnames]{xcolor}
\definecolor{marronMedio}{HTML}{AB8000}
\definecolor{amariClaro}{HTML}{FFFFCA}
\definecolor{grisMedio}{HTML}{999999}
\usepackage[many]{tcolorbox}
\newtcolorbox{phrasebox}{
%fuzzy shadow={0.25cm}{-0.25cm}{0cm}{0.25mm}{fill=grisMedio},
sharp corners=downhill,
arc=7mm,
width=12cm,
height=5cm,
enhanced jigsaw,
before upper=\Large,
halign=flush center,
valign=center,
colframe=marronMedio,
boxrule=0.7mm,
colback=amariClaro
}
\begin{document}
\pagenumbering{gobble}
\centering
\vspace*{\fill}
\begin{phrasebox}
\enquote{Everything you can imagine is real.}\\[0.5cm]
\textit{--- Pablo Picasso}
\end{phrasebox}
\vspace*{\fill}
\end{document}
结果如下:
如您所见,页面顶部的空间比底部的空间略大。
我怎样才能摆脱这个问题?
任何帮助将不胜感激。
答案1
只需在页面末尾添加一个空白框:
\documentclass[12pt]{article}
\usepackage{geometry}
\geometry{paper=letterpaper,margin=2cm, showframe}
\usepackage[autostyle]{csquotes}
\usepackage[dvipsnames]{xcolor}
\definecolor{marronMedio}{HTML}{AB8000}
\definecolor{amariClaro}{HTML}{FFFFCA}
\definecolor{grisMedio}{HTML}{999999}
\usepackage[many]{tcolorbox}
\newtcolorbox{phrasebox}{
%fuzzy shadow={0.25cm}{-0.25cm}{0cm}{0.25mm}{fill=grisMedio},
sharp corners=downhill, arc=7mm, width=12cm, height=5cm, enhanced jigsaw, before upper=\Large, halign=flush center, valign=center, colframe=marronMedio, boxrule=0.7mm, colback=amariClaro
}
\begin{document}
\pagenumbering{gobble}
\centering
\vspace*{\fill}
\begin{phrasebox}
\enquote{Everything you can imagine is real.}\\[0.5cm]
\textit{--- Pablo Picasso}
\end{phrasebox}
\vspace*{\fill}\mbox{}
\end{document}
答案2
为了使页面上的 tcolorbox 垂直居中,您可以将 tcolorbox 放入另一个与页面一样大的 tcolorbox 中。
然后使用valign=center, halign=center
\documentclass[12pt]{article}
\usepackage[showframe=true, % <--- setto false
paper=letterpaper, margin=2cm,
]{geometry}
\usepackage[autostyle]{csquotes}
\usepackage[many]{tcolorbox}
\newtcolorbox{phrasebox}{
sharp corners=downhill,
arc=7mm,
width=12cm,
height=5cm,
enhanced jigsaw,
before upper=\Large,
halign=flush center,
valign=center,
colframe=brown,
boxrule=0.7mm,
colback=yellow!40
}
\tcbset{
NoGaps/.style={boxsep=0mm, left=0pt, right=0pt, top=0pt, bottom=0pt, before skip=0pt, after skip=0pt,},
HideBox/.style={sharp corners,
colback=white,
boxrule=0mm, % 0.5mm = default
colframe=white, frame hidden,
},
ShowPageFrame/.is choice,
ShowPageFrame/.style={colframe=red, boxrule=1mm},
}
\begin{document}
\pagenumbering{gobble}
\begin{tcolorbox}[HideBox, NoGaps,
ShowPageFrame=true, % setto false
valign=center, halign=center, % Box content to page center
height=\textheight,
]
\begin{phrasebox}
\enquote{Everything you can imagine is real.}\\[0.5cm]
\textit{--- Pablo Picasso}
\end{phrasebox}
\end{tcolorbox}
\end{document}