2

I would like to have a tcolorbox Example with the option breakable that can be display in few beamer slide. This is my 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

1 Answer 1

1

This is not a really elegant solution (yet?) but shows that this can be done in principle. The key ingredient is Martin Scharrer's solution of a closely related problem. The strategy is to save the tcolorbox in a \savebox and then to decompose it into bits that fit. Ironically, for this we do not need breakable. I also added some analog of the \textheight, called \Textheight, by hand simply because I do not know what the corresponding length really is.

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

enter image description here

I believe that this will work for mdframed, too, cf. this question.

1
  • Thanks to @Schrödinger'sCat. The solution proposed works. I also found that texemple with breakable works outside a Frame. Sep 22, 2019 at 9:55

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.