3

When my ntheorem Box spans multiple pages, I want it to have a hint on each page, that it is a continuation. How can this be done?

Below is some sample code, spanning a box over two pages, which is yet missing a hint on the second page, that it is a continuation.

\documentclass[]{article}

\usepackage{blindtext}

\usepackage{framed} 
\usepackage{pstricks} 
\usepackage[framed]{ntheorem}

\begin{document}
\newshadedtheorem{test}{Example}

\begin{test}
\textbf{Some sample text}
\blindtext[5]
\end{test}

At the beginning of the box at page 2 it shall have\\
\textbf{Example 1 (Continued)}.\\
(Included at the top of the box, not before the box).

\end{document}

Preview:

enter image description here

me.at.coding
  • 1,653

1 Answers1

7

This can be easily achieved using either the mdframed or tcolorbox packages.

An option using mdframed:

\documentclass[]{article}
\usepackage[a6paper]{geometry}% just for the example
\usepackage{blindtext}
\usepackage[framemethod=tikz]{mdframed} 
\usepackage{ntheorem}

\newmdtheoremenv[
  ntheorem=true,
  hidealllines=true,
  backgroundcolor=gray!50,
  splittopskip=2\baselineskip,
  middleextra={\node[anchor=north west,font=\bfseries,inner xsep=0pt,xshift=10pt] at (P-|O) {Example~\thetest\ (Continued)};},
  secondextra={\node[anchor=north west,font=\bfseries,inner xsep=0pt,xshift=10pt] at (P-|O) {Example~\thetest\ (Continued)};}
]{test}{Example}

\begin{document}

\begin{test}[An example]
\blindtext[3]
\end{test}

\end{document}

enter image description here

And here's now an option using tcolorbox:

\documentclass[]{article}
\usepackage[a6paper]{geometry}% just for the example
\usepackage{blindtext}
\usepackage[most]{tcolorbox} 

\newcounter{test}

\newtcolorbox{test}[2][%
breakable,
arc=0pt,
outer arc=0pt,
coltitle=black,
fonttitle=\bfseries,
boxrule=0pt,
colframe=gray!30,
colback=gray!30,
title after break={Example~\thetest\ (Continued)}
]{%
before upper={
  \stepcounter{test}\textbf{Example~\thetest.\ }%
},
label={#2},
#1}

\begin{document}

\begin{test}{testa}
\blindtext[3]
\end{test}

\end{document}

enter image description here

Gonzalo Medina
  • 505,128
  • Thank you! Until now I used \definecolor{myColor}{rgb}{0.9,0.9,0.9} followed by \shadecolor{myColor} (both before newshadedtheorem) Can you please tell me, how to migrate this to your solution? – me.at.coding Sep 11 '13 at 17:58
  • @stefan.at.wpf keep the definition of your color and change the line backgroundcolor=gray!50, to backgroundcolor=myColor,. – Gonzalo Medina Sep 11 '13 at 18:00
  • my fault, thanks for the hint. your example works great, but I get some problems in my real document ): will get back to this problem tomorrow. basically correct answer. – me.at.coding Sep 11 '13 at 18:21
  • @stefan.at.wpf OK. In the meantime I updated my answer with another option, using this time the tcolorbox package. – Gonzalo Medina Sep 11 '13 at 20:03
  • I yet didn't have the chance to check if your new version works for me, but I selected your answer as correct one as it does exactly what I wanted anyways. Thank you very much! – me.at.coding Sep 14 '13 at 16:06
  • @stefan.at.wpf Glad I could help. You're welcome! – Gonzalo Medina Sep 14 '13 at 16:07