0

In first slide, tcolorbox is aligned vertically center. But in second slide, unable to align the tcolorbox properly.

\documentclass[fontsize=10pt,landscape,parskip=half]{scrartcl}
\usepackage{scrlayer-scrpage}
\usepackage[paperwidth=128mm,
            paperheight=96mm,
            margin=8mm,
            footskip=6mm]{geometry}
\usepackage{overlays}
\usepackage{tcolorbox}

\newcommand{\texthide}[1]{\underline{\hspace{3mm}\phantom{#1}\hspace{3mm}}} \newcommand{\textshow}[1]{\underline{\hspace{3mm}\textbf{#1}\hspace{3mm}}}

\setlength{\parindent}{0pt} \begin{document}

\clearpage ~ \vfill \begin{overlays}{2} \begin{tcolorbox} \only{1}{ The grass \texthide{is} green } \only{2}{ The grass \textshow{is} green } \end{tcolorbox} % \vfill ~ \end{overlays} \vfill ~ \clearpage

\end{document}

sandu
  • 7,950

1 Answers1

3

Like this?

\documentclass[fontsize=10pt,landscape,parskip=half]{scrartcl}
\usepackage{scrlayer-scrpage}
\usepackage[paperwidth=128mm,
            paperheight=96mm,
            margin=8mm,
            footskip=6mm]{geometry}
\usepackage{overlays}
\usepackage{tcolorbox}

\newcommand{\texthide}[1]{\underline{\hspace{3mm}\phantom{#1}\hspace{3mm}}} \newcommand{\textshow}[1]{\underline{\hspace{3mm}\textbf{#1}\hspace{3mm}}}

\setlength{\parindent}{0pt}

\begin{document}

\begin{overlays}{2} \begin{tcolorbox}[before=\leavevmode\vskip-\dimexpr\baselineskip+\topskip\relax\vfill\par, after=\par\vfill] \only{1}{ The grass \texthide{is} green } \only{2}{ The grass \textshow{is} green } \end{tcolorbox} \end{overlays}

\end{document}

enter image description here

Update:

If you want the tcolorbox env to be exactly vertically centered at the text area of current page, use tcolorbox option box align=center. OP's setting makes the center of text area and center of the whole page overlap, which is more or less a coisidence.

\documentclass[fontsize=10pt,landscape,parskip=half]{scrartcl}
\usepackage{scrlayer-scrpage}
\usepackage{tikz}
\usepackage{tikzpagenodes}
\usepackage{showframe}
\usepackage[paperwidth=128mm,
            paperheight=96mm,
            margin=8mm,
            footskip=6mm]{geometry}
\usepackage{overlays}
\usepackage{tcolorbox}
\tcbuselibrary{skins}

\newcommand{\texthide}[1]{\underline{\hspace{3mm}\phantom{#1}\hspace{3mm}}} \newcommand{\textshow}[1]{\underline{\hspace{3mm}\textbf{#1}\hspace{3mm}}} \setlength{\parindent}{0pt}

\lohead{% \tikz[remember picture,overlay] { \draw (current page.north east) -- (current page.south west) (current page.north west) -- (current page.south east); \draw[purple] (current page text area.north east) -- (current page text area.south west) (current page text area.north west) -- (current page text area.south east); }% }

\begin{document} \begin{overlays}{2}
\begin{tcolorbox}[ before=\leavevmode\vskip-\dimexpr\baselineskip+\topskip\relax\vfill\par, after=\par\vfill, box align=center, enhanced jigsaw, opacityback=0.5, overlay={ \draw[blue] (frame.north east) -- (frame.south west) (frame.north west) -- (frame.south east); } ] \only{1}{ The grass \texthide{is} green } \only{2}{ The grass \textshow{is} green } \end{tcolorbox}

\end{overlays} \end{document}

enter image description here

muzimuzhi Z
  • 26,474
  • Have a question: Is the \relax and two \par mandatory here? – Tom May 24 '22 at 06:49
  • @Tom Looks like neither of them is mandatory. \relax is for \dimexpr to stop, two \pars are for ensuring the tcolorbox env is on its own paragraph. – muzimuzhi Z May 24 '22 at 06:58
  • I just add a answer to illustrate something according to your answer. Correct me if there are something wrong in it. – Tom May 24 '22 at 07:38
  • 1
    @Tom See answer update. I added a revised example using box align=center, with crosses showing centers of the tcolorbox env, the text area, and the whole page. – muzimuzhi Z May 24 '22 at 08:18
  • This is great! There is empty line in the second code between tikz and tcolorbox, which shift down the tcolorbox env. Please delete it. – Tom May 24 '22 at 08:35
  • @Tom It doesn't matter. That empty line is converted to a \par so tex enters vertical mode. But vertical mode is just what we want before tcolorbox env. – muzimuzhi Z May 24 '22 at 08:51
  • Are you sure? When I copy and compile it. The tcolorbox was off center. – Tom May 24 '22 at 08:54
  • @Tom Sorry, you're right. I moved the overlaid cross-drawing \tikz into header. Now it should be more robust. – muzimuzhi Z May 24 '22 at 09:08