I am trying to create a customized "proof" environment attached to a theorem. It looks like this: What it should look like.

So there is first the theorem, and then a gray bar starts on the inner margin. It ends, when the proof of the theorem is finished. It should also be possible to give a theorem without proof of cause.

The document you see above was created from the following code:


%% Language %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{lmodern} % Type1-font for non-english texts and characters

%% Math Symbols %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Other Packages %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{color}                          % colors
\usepackage{framed}                         % frames
\usepackage{mdframed}                       % better frames

\usepackage{fancyhdr}                   % Fancy headings

%% Style Definitions %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% My Theorem Style ============================================================

\newtheoremstyle{myThmStyle}% name of the theorem
{6pt}% habovespacei
{6pt}% hbelowspacei
{\itshape}% font
{}% hindenti
{}% hheadfonti
{}% hheadpuncti
{ }% hheadspacei
{\thmname{\normalfont\large\textsc{#1}\normalsize} \thmnote{#3:} \thmnumber{ \hfill \normalfont(#2)}\\[1pt]}

% Frame Styles ================================================================


    innertopmargin=4pt, %\baselineskip
    innerbottommargin=4pt, %\baselineskip,

% Thorems =====================================================================


% Proof environment ===========================================================
% (attached to theorem)

    {\color{thmLnColor}\vrule width 8pt}%
    \hspace{0pt}%must no space.

% Theorem environment =========================================================




\section{Section A}

\begin{theorem}[about something important] \label{thm:important}
This is some important theorem with equations
    1 + 1 = 0 \;,
and text.

Some text with reference to theorem \eqref{thm:important}.

\begin{theorem}[about something important] \label{thm:veryImportant}
This is some important theorem with equations
    1 + 1 = 0 \;,
and text.
Proof of something important... The proof may exceed several pages. The proof may exceed several pages. The proof may exceed several pages. 

The proof may exceed several pages. The proof may exceed several pages. The proof may exceed several pages.


There are two things that do not work yet:

  1. When the text within the proof exceeds one page, then there appears a small gap between theorem and proof.
  2. The gray bar of the proof is currently always on the left side. But I want it to be on the inner margin (left for right pages and right for left pages).

The first problem is certainly due to my dirty bugfix


within \newenvironment{myTheoremEnvEx}[1][\hsize].

Can you help me with this? I'd also be happy to see better solutions.

  • You can do this very simple by defining a single command which ends up the first framed environment and start the next one. Jun 27, 2013 at 16:59
  • Maybe the thmbox package could provide a good starting point?
    – Clément
    May 12, 2015 at 23:10

1 Answer 1


This is somewhat of an old question but I was interested in how to put a line down the margin, where the side changes depending on the parity of the page number.

Rather than using the mdfamed package I have used tcolorbox as I am more used to using it. For answer this question, tcolorbox has one particularly useful switch, toggle left and right, that can be used to swap the role of left and right in various instances. This is what is used to address point #2 in the OPs question.

Apart from this it is fairly straightforward except for the creation of a new theorem "style" for use by \newtcbtheorem to cater for the particular style required by the question. This is done by the line

\tcbset{theorem style/theorem wide name and number/.code={

with the associated macro \tcb@theo@widetitle doing the actual work. This the output

Sample output

from the following code (updated for tcolorbox version 1.14, with breakable added to the theorem style to allow it also to break over pages)



%% Other Packages %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{changepage}% for use of \ifoddpage below

% Theorems ==============

% define a new theorem style
\def\tcb@theo@widetitle#1#2#3{\hbox to \textwidth{\textsc{\large#1}\normalsize\space#3\hfil(#2)}}
  theorem style/theorem wide name and number/.code={ \let\tcb@theo@title=\tcb@theo@widetitle},
    check odd page, toggle left and right, colframe=thmLnColor,
    leftrule=8pt, rightrule=0mm, boxsep=0mm,arc=0mm, outer arc=0mm,
    left=3mm,right=0mm,top=0mm,bottom=0mm, toptitle=0mm,

\newtcbtheorem[use counter=equation, number within=section]{mytheorem}{Theorem}%
  {theorem style=theorem wide name and number,enhanced,breakable,
  arc=0mm,outer arc=0mm,parbox=false,
  title style={color=thmBgColor}, coltitle=black,
  attach title to upper={\par\noindent},
  before={\par\vfill\smallbreak\noindent}, after={\par},



%% Style Definitions

\quad\clearpage % to make it easier to get a screenshot with two pages

\section{Section A}

\begin{theorem}[about something important]{important}
This is some important theorem with equations
    1 + 1 = 0 \;,
and text.

  \lipsum*[1-8] Theorem \eqref{thm:important}.

\begin{theorem}[about something important]{veryImportant}
This is some important theorem with equations
    1 + 1 = 0 \;,
and text.

It continues for some more lines, so that a page break occurs during
its statement.

\begin{proof}[Proof of something important]

  • I love this, not to revive an old thread though, but @Andrew is it possible to have the same thing for longer lemmas or theorems, sometimes I have my theorem starting at the end of a page, and it skips to next page since it won't let it span on two pages, is it possible to have it span over multiple pages?
    – Sephya
    Nov 25, 2018 at 2:47
  • 2
    @Sephya Essentially just add breakable to the theorem style. I have updated my answer. Nov 25, 2018 at 11:38
  • @AndrewSwann It looks like you have updated my answer:) Thanks!
    – user30471
    Nov 25, 2018 at 23:53
  • @Andrew Oh, now I see yes - I seemed to get pinged by tags to you. Nov 26, 2018 at 7:38

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.