Beamer 幻灯片内的可破坏 tcolorbox

Beamer 幻灯片内的可破坏 tcolorbox

我想要一个 tcolorbox例子选择易碎可以在几张幻灯片中显示。这是我的 MWE:

\documentclass{beamer}
\usetheme{default}
%
\usepackage[most]{tcolorbox}
\usepackage{lipsum}
%
\newcounter{myexpl}[section]
\def\themyexpl{\thesection.\arabic{myexpl}}

\tcbmaketheorem{texample}{Example}{
fonttitle={\bfseries\upshape\hypersetup{linkcolor=blue!10!white}},
  fontupper=\slshape, arc=0mm, colback=red!50!yellow!5!white, 
colframe=red!50!yellow!50!black, separator sign dash,breakable} 
  {myexpl}{exp}
%
\title{Beamer Template}
\author{Test}
\begin{document}
\begin{frame}[plain]
    \maketitle
\end{frame}
\begin{frame}[fragile,allowframebreaks]{Example Breakable Test}
\begin{texample}{test}{tt}
\lipsum[1-3]
\end{texample}

\end{frame}
\end{document}

答案1

这还不是一个真正优雅的解决方案(目前为止?),但表明这在原则上是可以实现的。关键因素是Martin Scharrer 对一个密切相关问题的解决方案。策略是将保存tcolorbox在 a 中\savebox,然后将其分解为合适的位。讽刺的是,为此我们不是需要。我还手动添加了一些称为breakable的模拟,因为我不知道相应的长度到底是多少。\textheight\Textheight

\documentclass{beamer}
\usetheme{default}
%
\usepackage[most]{tcolorbox}
\usepackage{lipsum}
%
\newcounter{myexpl}[section]
\def\themyexpl{\thesection.\arabic{myexpl}}
\usepackage{adjustbox}
\newsavebox{\mysavebox}
\newlength{\myrest}
\newlength{\Textheight}
\Textheight=7.9cm
\newif\iffirstframe
\firstframetrue
\tcbmaketheorem{texample}{Example}{
fonttitle={\bfseries\upshape\hypersetup{linkcolor=blue!10!white}},
  fontupper=\slshape, arc=0mm, colback=red!50!yellow!5!white, 
colframe=red!50!yellow!50!black, separator sign dash} 
  {myexpl}{exp}
%
\title{Beamer Template}
\author{Test}
\begin{document}

\begin{frame}[plain]
    \maketitle
\end{frame}


\begin{lrbox}{\mysavebox}%
\begin{texample}{test}{tt}
\lipsum[1-3]
\end{texample}
\end{lrbox}%
\begin{frame}[fragile,t,allowframebreaks]{Example Breakable Test}
\ifdim\ht\mysavebox>\Textheight
    \setlength{\myrest}{\ht\mysavebox}%
    \loop\ifdim\myrest>\Textheight
        \iffirstframe
         \firstframefalse
        \else 
         \newpage\par\noindent
        \fi 
        \clipbox{0 {\myrest-\Textheight} 0 {\ht\mysavebox-\myrest}}{\usebox{\mysavebox}}%
        \addtolength{\myrest}{-\Textheight}%
    \repeat
     \newpage\par\noindent 
    \clipbox{0 0 0 {\ht\mysavebox-\myrest}}{\usebox{\mysavebox}}%
\else
    \usebox{\mysavebox}%
\fi
\end{frame}
\end{document}

在此处输入图片描述

我相信这也适用于 mdframed,参见这个问题

相关内容