使用覆盖将 tcolorbox 垂直对齐到中心

使用覆盖将 tcolorbox 垂直对齐到中心

在第一张幻灯片中,tcolorbox 垂直居中对齐。但在第二张幻灯片中,无法正确对齐 tcolorbox。

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

答案1

像这样?

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

在此处输入图片描述

更新:

如果希望tcolorboxenv垂直居中在当前页面的文本区域,可以使用tcolorbox选项box align=center。OP的设置使得文本区域的中心和整个页面的中心重合,差不多就是一个重合。

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

在此处输入图片描述

相关内容