# improving theorem environment

The following is a theorem from Algebraic topology written by A. Hatcher.

I'm interested in to know how is possible do theorems like this:

I know that a new environment has the following form, how to put two vertical lines. Thanks

\newtheoremstyle{stylename}{spaceabove}{spacebelow}{bodyfont}{indent}{headfont}{headpunctuation}{headspace}{headspec}


• mdframed is the better one Jun 2, 2020 at 7:23
• Thesmall framed package defines a leftbar environment. You also can look at the thmtools package. Jun 2, 2020 at 7:39
• @MadyYuvi thanks. this package is awesome. Jun 2, 2020 at 9:06
• @Bernard thmtools package is great. Thanks Jun 2, 2020 at 9:07
• You can use the lettrine package for the big T in Theorem. Jun 2, 2020 at 14:03

Several people have suggested packages such as thmtools in the comments. If you want to roll your own, here is a wrapper around an existing environment. It supports an optional argument, but cannot break across pages. It’s therefore only appropriate for short theorems.

\documentclass{article}
\usepackage{amsmath, amsthm} % For \newtheorem*.
\usepackage{unicode-math}    % Or your math package of choice.
\usepackage{xparse}          % For \NewDocumentEnvironment.
\usepackage{settobox}        % For \settoboxtotalheight.
\usepackage{microtype}       % For font expansion.
\usepackage{lipsum}          % For \lipsum.

%% This is the font actually used within the example you gave:
%\setmainfont{Cambria}
%\setmathfont{Cambria Math}

\newtheorem*{thm*}{Theorem}

\newsavebox{\decothmbox}
\newlength{\decowidth}
\newlength{\decoheight}
\newlength{\decorulewidth}
\setlength{\decorulewidth}{1.5em}

\NewDocumentEnvironment{decothm}{mo}%
{%
\bigskip\par\noindent%
\setlength{\decowidth}{\hsize}%
\begin{lrbox}{\decothmbox}%
\begin{minipage}[b]{\decowidth}%
\begin{#1}[#2]}%
{%
\end{#1}%
\end{minipage}%
\end{lrbox}%
\settoboxtotalheight{\decoheight}{\decothmbox}%
\makebox[\decorulewidth]{%
\hspace{0.6em}%
\rule{0.1em}{\decoheight}%
\hspace{0.1em}%
\rule{0.05em}{\decoheight}%
\hspace{0.65em}}%
\usebox{\decothmbox}%
\bigskip\par}

\begin{document}
This is a theorem.

\begin{decothm}{thm*}[4L.9]\label{thm:example}
Suppose $$H^\ast (X ; \mathbb{Z}_p)$$ is the polynomial algebra
$$\mathbb{Z}_p[\alpha]$$ on a generator $$\alpha$$ of dimension $$n$$,
possibly truncated by the relation $$\alpha^m = 0$$ for $$m > p$$.  Then if
$$p = 2$$, $$n$$ must be a power of $$2$$, and if $$p$$ is an odd prime, $$n$$
must be of the form $$p^k \ell$$, where $$\ell$$ is an even divisor of
$$2(p-1)$$.
\end{decothm}

\lipsum[1]
\end{document}


Essentially, this typesets the theorem text inside a minipage that subtracts the width of the left rule. Instead of using it immediately, we save that in a box so we can measure its height. This lets us lay out the rules to the left first.

The code uses xparse to make it possible to use an argument in the code to close an environment, settobox as a convenient way to add the height and the depth of the theorem, and includes amsmath before amsthm because, otherwise, another package would have loaded it afterwards, which could have caused bugs in a more complex document.