Graphics, Figures & TablestikZ | Page Break in framed Theorem

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
voorneveld
Posts: 15
Joined: Mon Sep 07, 2009 11:18 am

tikZ | Page Break in framed Theorem

Post by voorneveld »

The theorem environment in the MWE below
(a) puts a header with optional argument on a colored background and
(b) frames the content.

Code: Select all

\listfiles
\documentclass{article}

\usepackage{amsmath}
\usepackage{tikz}
\usepackage{lipsum}

\makeatletter
\newtheorem{theo}{Theorem}[section]

\newsavebox{\header}
\newsavebox{\content}
\newenvironment{theorem}[1][]
{%
\refstepcounter{theo}
% Save the text for the theorem header, with optional argument, in box \header
\begin{lrbox}{\header}
\textbf{Theorem \thetheo} \@ifnotempty{#1}{\textbf{(#1)}}
\end{lrbox}
% Save the text for the theorem body in box \content
\begin{lrbox}{\content}
    \begin{minipage}[!h]{0.95\textwidth}
}%
{%
    \end{minipage}
\end{lrbox}
\begin{tikzpicture}
\node[draw = blue!20, text = black, very thick, rectangle, inner sep = 10pt, inner ysep = 20pt] (box) {\usebox{\content}};
\node[draw = none, text = black, fill = blue!20, right=0pt] at (box.north west) {\usebox{\header}};
\end{tikzpicture}
}%
\makeatother

\begin{document}
\section{First section}

\begin{theorem}[Nice theorem]
\lipsum[1]
\end{theorem}

\section{Second section}

\begin{theorem}
\lipsum
\end{theorem}
\end{document}
It does not break nicely across pages.

Can I make it do so without a bottom line on the page that contains the first part of the theorem and without a top line on the second?

The mdframed package seems to do this, but I don't see how to include this into my environment.

Mark Voorneveld

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

tikZ | Page Break in framed Theorem

Post by localghost »

Take a look at the ntheorem package. It supports framed theorems.


Thorsten
voorneveld
Posts: 15
Joined: Mon Sep 07, 2009 11:18 am

Re: tikZ | Page Break in framed Theorem

Post by voorneveld »

The ntheorem documentation states that it works with mdframed as well, but in that case, I know insufficient about LaTeX to use ntheorem to make the theorem's header appear as it does in the MWE on a colored background.
Post Reply