My initial question:
I'm writing my lecture notes in LaTeX and used some customized theorem environments with amsthm so far. Now I wanted to redesign those theorems with help of tikzpicture.
That's what I want to do:
- I want the theorem header (Theorem name, Numbering, title) to be within a tikzpicture node. Concretely I want to use tikzpicture's chamfered rectangle option.
- I want the theorem content/body also to be within a tikzpicture node. Currently there only should be a gray background color. But there will be theorems where I want to customize this area as well (e.g. another chamfered rectangle option).
- There shall not be a white spacing between header and body (currently there's some unwanted spacing between them) but I'd like to get an option for a definable (customizable) line to separate the header from the content.
Here's a working code example which describes my problems. Do you have any ideas?
% DOCUMENT
\documentclass[twoside]{scrbook}
\parindent0pt
\parskip6pt
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{scrhack}
\renewcommand*\familydefault{\sfdefault}
% GRAPHICS
\usepackage{xcolor, tikz}
\usetikzlibrary{shapes}
\definecolor{lightgray}{RGB}{215,215,215}
\definecolor{blue}{RGB}{17,94,140}
% MATH
\usepackage{amsmath, amsfonts, amssymb, amsthm}
% THEOREMS
\usepackage{environ}
\newtheoremstyle{defstyle}
{2em}
{1em}
{}
{}
{\sffamily\bfseries\large\color{white}}
{\newline}{2ex}
{\tikz\node[fill=blue, inner sep=0, chamfered rectangle, chamfered rectangle corners=north east, text width=\textwidth] {
\thmname{#1}\thmnumber{ #2}\thmnote{\quad(#3)}
};}
\NewEnviron{definition}[1][]{
\begin{deftmp}[#1]
\tikz\node[fill=lightgray, rectangle, text width=\textwidth] {
\BODY
};
\end{deftmp}
}
\NewEnviron{lemma}[1][]{
\begin{lemmatmp}[#1]
\tikz\node[fill=lightgray, inner sep=0, chamfered rectangle, chamfered rectangle corners=south east, text width=\textwidth] {
\BODY
};
\end{lemmatmp}
}
\theoremstyle{defstyle}
\newtheorem{deftmp}{Definition}[chapter]
\newtheorem{lemmatmp}[deftmp]{Lemma}
% BEGIN
\begin{document}
Here's a working definition, but with some unwanted spacing between header and body:
\begin{definition}[One definition]
Text without enumerations and with simple things like formulas:
\begin{align*}
S_n = \frac{1}{n} \sum_{i=1}^n X_i
\end{align*}
\end{definition}
Here's the problem I have with enumerate within the body:
\begin{definition}[Problem definition]
Text with a enumeration:
\begin{enumerate}
\item One
\item Two
\item $\ldots$
\end{enumerate}
\end{definition}
There could also be a theorem like:
\begin{lemma}[Another theorem]
With some text.
\end{lemma}
Additionally there is a small offset on the right margin of both tikzpictures: The upper header tikzpicture is longer than the body tikzpicture though both are set to textwidth.
\end{document}
Update 1: A modification of Gonzalo Medina's Code:
Thanks to Gonzalo Medina I was able to rework my theorems the way I wanted them to look like. But the following MWE shows a problem with page breaking theorems. Is there a way to avoid those display misbehaviors? I'd like my theorems to stay breakable but they should break correctly.
\documentclass{scrbook}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[svgnames]{xcolor}
\usepackage{chngcntr}
\usepackage{amssymb}
\usepackage{aliascnt}
\usepackage{tikz}
\usepackage{lipsum}
\usetikzlibrary{shapes.misc,calc}
\usepackage{tcolorbox}
\tcbuselibrary{skins,theorems,breakable}
\renewcommand*\familydefault{\sfdefault}
\definecolor{hellgrau}{RGB}{215,215,215}
\definecolor{blau}{RGB}{17,94,140}
\definecolor{orange}{RGB}{229,94,30}
\makeatletter
\tcbset{
mytheorem/.code args={#1#2#3#4}{
\refstepcounter{#2}\label{#4}
\pgfkeysalso{title={\setbox\z@=\hbox{#1~\csname the#2\endcsname\ }\hangindent\wd\z@\hangafter=1 \mbox{#1~\csname the#2\endcsname\ }(#3)}}},
}
\newcommand{\mtcbmaketheorem}[5]{
\newtcolorbox{#1}[3][]{#3,mytheorem={#2}{#4}{##2}{#5:##3},##1}
}
\makeatother
\newcounter{defi}
\newaliascnt{lemm}{defi}
\counterwithin{defi}{chapter}
\counterwithin{lemm}{chapter}
\tcbset{
defstyle/.style={
breakable,
freelance,
boxrule=1pt,
width=\linewidth,
frame code={%
\path[fill=blau]
([yshift=-7.5pt]frame.north west) -- ([xshift=7.5pt]frame.north west) --
(frame.north east) -- (frame.north east|-interior.north east) --
(frame.north west|-interior.north west) -- cycle;
},
interior titled code={
\path[fill=hellgrau]
(frame.west|-interior.north west) -- (frame.east|-interior.north east) --
(frame.east|-interior.south east) -- (frame.west|-interior.south west) -- cycle;
\path[draw=white, line width=1pt] ([xshift=-1pt]frame.west|-interior.north west) -- ([xshift=1pt]frame.east|-interior.north east);
},
fonttitle=\bfseries\sffamily
},
satzstyle/.style={
breakable,
freelance,
boxrule=1pt,
width=\linewidth,
frame code={%
\path[fill=orange]
([yshift=-7.5pt]frame.north west) -- ([xshift=7.5pt]frame.north west) --
(frame.north east) -- (frame.north east|-interior.north east) --
(frame.north west|-interior.north west) -- cycle;
},
interior titled code={
\path[fill=hellgrau]
(frame.west|-interior.north west) -- (frame.east|-interior.north east) --
(frame.east|-interior.south east) -- (frame.west|-interior.south west) -- cycle;
\path[draw=white, line width=1pt] ([xshift=-1pt]frame.west|-interior.north west) -- ([xshift=1pt]frame.east|-interior.north east);
},
fonttitle=\bfseries\sffamily
}
}
\mtcbmaketheorem{defi}{Definition}{defstyle}{defi}{df}
\mtcbmaketheorem{lemm}{Lemma}{satzstyle}{lemm}{lm}
\begin{document}
\chapter{A test chapter}
\begin{defi}{Partially ordered set}{poset}
A partial order is a binary relation $\preccurlyeq$ over a set $P$ which is antisymmetric, transitive, and reflexive. A set with a partial order is called a partially ordered set (also called a poset).
\end{defi}
\begin{lemm}{Zorn's Lemma}{zorn}
Suppose a non-empty partially ordered set $P$ has the property that every non-empty chain has an upper bound in $P$. Then the set $P$ contains at least one maximal element.
\end{lemm}
\lipsum[1-2]
\begin{lemm}{Poissonpunktprozess}{PoissPunktProzess}
Wir nehmen an, unser System zuf"alliger Punkte erf"ullt folgende Bedingungen:
\begin{enumerate}
\item $N_{a,b}$ und $N_{c,d}$ sind stochastisch unabh"angig und $[a,b] \cap [c,d] = \emptyset$. \label{item1:satz:PoissPunktProzess}
\item $N_{a+s,b+s}$ und $N_{a,b}$ haben f"ur alle $s \in [0,\infty)$ die gleiche Verteilung. \label{item2:satz:PoissPunktProzess}
\item Es existiert ein $\lambda > 0$, so dass $\lim_{\Delta t \downarrow 0} \frac{P_1(\Delta t)}{\Delta t} = \lambda$. \label{item3:satz:PoissPunktProzess}
\item Es ist $\lim_{\Delta t \downarrow 0} \frac{P(N_{\Delta t} \geq 2)}{\Delta t} = 0$. \label{item4:satz:PoissPunktProzess}
\end{enumerate}
Dann gilt f"ur $t \geq 0$ bzw. $a,b \in [0,\infty)$, $b > a \geq 0$:
\begin{itemize}
\item $N_t$ ist Poissonverteilt zum Parameter $\lambda t$,
\item $N_{a,b}$ ist Poissonverteilt zum Parameter $\lambda(b-a)$.
\end{itemize}
\end{lemm}
\end{document}