3

I'm trying to vertically center a tcolorbox on a page, but with the code below the box isn't exactly at the middle of the page.

So far I've tried this:

\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}

And the result is here:

Output of compiling the given code.

As you can see, there is slightly more space at the top of the page than at the bottom.

How can I get rid of this problem?

Any help will be appreciated.

4

Jsut add an empty boxes at the end of the page:

\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} 

enter image description here

| improve this answer | |
  • Wow. .-. This community is suprising me more and more. Thanks a lot! It worked! =) – user101590 May 29 '16 at 22:23
0

For vertically centering of a tcolorbox on a page you can put the tcolorbox into another tcolorbox, which is as big as the page.
Then use valign=center, halign=center

enter image description here

\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}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy