I am new to LaTeX, so I apologise if this question seems too simple to you. I am currently trying to write a paper and I would like to add an overhang to Theorems and Definitions (like the picture below for sub-sections, but for theorems) but I have no idea how to do it. I have tried defining some length \Overhang then defining the environment theorem while adding the overhang length into the definition, but it did not work.

Just to be clear, I want the word "Theorem" and the numbering to be on different lines, aligned to the right. Thank you in advance!

Example of Subsection Overhang

Edit: here is a picture of what I would like the newly defined theorem environment to look like. enter image description here

  • 3
    Welcome to TeX.SE! Currently, your question is not entirely clear, and therefore difficult to answer. Could you please add the code for a small example document, just one page (using the article documentclass or similar standard classes), with a theorem in it (and nothing else), and add an image that shows how this example document looks now and how you want it to look? Doing so will make it easier to understand what you mean and to try out possible solutions. You can edit using the edit button below the question.
    – Marijn
    Jul 5, 2018 at 10:55

2 Answers 2


The following code puts both the section number and the labels of theorem environments in the margin by putting them in right-aligned boxes of zero width (and zero depth).


\newlength{\marginlabelsep}\setlength{\marginlabelsep}{1em} %% <- change to a nice value

\usepackage{titlesec} %% <- To put the section # in the margin

\newtheoremstyle{mythmstyle} %% Name
  {} %% <- Space above (empty = default = \topsep = 8.0pt plus 2.0pt minus 4.0pt)
  {} %% <- Space below (empty = default = \topsep = 8.0pt plus 2.0pt minus 4.0pt)
  {\itshape} %% <- Body font
  {} %% <- Indent amount (empty = no indent, \parindent = just that)
  {\bfseries} %% <- Thm head font
  {} %% <- Punctuation after thm head
  {0pt} %% <- Space after thm head (or " " or \newline) (default: 5pt plus 1pt minus 1pt)
  {\vtop to 0pt{\llap{\thmname{#1}\hskip\marginlabelsep}
  } %% <- Thm head spec (empty = default ~= \thmname{#1}\thmnumber{ #2}\thmnote{ (#3)})

\newtheorem{theorem}{Theorem}[section] %% <- Numbering subordinate to sections
\newtheorem{lemma}[theorem]{Lemma}     %% <- Uses same counter as theorem

\usepackage{lipsum} %% <- for \lipsum


\section{My section}



\begin{theorem}[A beautiful theorem]



enter image description here


I am using the amsthm package to create a custom theorem style. The \newtheoremstyle command is a little monstrous because it takes so many arguments arguments, so I keep these comments around to remind me what each of them does. The most important argument for us is the last one, which describes the formatting of the theorem head. If this is left empty, it is effectively defined as

\thmname{#1}\thmnumber{ #2}\thmnote{ (#3)})

The arguments #1, #2 and #3 will be the theorem name, its number and the title/note, and \thmname, \thmnumber and \thmnote either print their contents, or nothing if there is no name, number or title/note.

To move the theorem head into the margin we should replace this by some code that takes up no space and prints the theorem name+number in the margin on two separate lines, followed by the theorem note and a newline (if there is a note).

The TeX primitives \vbox, \vcenter and \vtop can be used to print multiple boxes on top of each other, like this:

Word \vbox{\hbox{A}\hbox{B}} word \vtop{\hbox{C}\hbox{D}} word.\\
Next line \vtop to 0pt{\hbox{E}\hbox{F}},\\       %% Note: <-, ^ avoid using \\
last line.

enter image description here

The argument of \vtop has to be a sequence of boxes, so I've put the letters A, B, ... inside \hboxes (simple horizontal boxes) here. I've used \vtop to 0pt{...} instead of just \top{...} to create a box with zero depth because the next line would otherwise be pushed downwards (like the second line above). For more information on boxes, see e.g. this answer.

To put the theorem label in the margin, I've used \llap{<contents>}. This LaTeX command prints a box that contains <contents>, takes up no space and sticks out to the left (\rlap does the same, but sticks out on the right). Because it produces a box, it can be used directly inside \vtop. Here is an illustration:


enter image description here

I've added a horizontal space after \thmname{#1} and \thmnumber{#1} to make sure that the label is separated from the main text by\marginlabelsep.

Remark: Before this (hopefully) last edit, the final argument of \newtheoremstyle was

{\vtop to 0pt{\hbox to -\marginlabelsep{\hss\thmname{#1}}
              \hbox to -\marginlabelsep{\hss\thmnumber{#2}}}\thmnote{#3\\}%
} %% <- Thm head spec (empty = default ~= \thmname{#1}\thmnumber{ #2}\thmnote{ (#3)})

which was completely fine. I've changed this because \llap is a little easier to understand (and to explain!) than the effect of putting boxes with negative widths inside a \vbox and what \hss does.

  • I think there is a slight problem. There is a small indent in front of the theorem text if the theorem does not have a label. Is there a way to improve on this problem? (in this picture ibb.co/m33t9y, the word "If" starts slightly to the right of "it".)
    – Teyyf
    Jul 6, 2018 at 1:49
  • Sorry, refer to postimg.cc/image/binas4a2f instead
    – Teyyf
    Jul 6, 2018 at 1:57
  • @Teyyf: Did you by any chance copy the code right after I had edited it? I had accidentally introduced this space by forgetting a % at the end of a line (cf. this question) and fixed it shortly afterwards. Jul 6, 2018 at 8:04

The amsthm package provides the \newtheoremstyle command that can be used to set the style of theorems. In the body font argument (which is the 4th argument, see the amsthm manual for details) the \hangindent command can be used to specify a hanging indent. In the example below this is set manually to 6em, which is approximately the width of the text Theorem 1. Also a \newline is added to start the theorem text on a new line.




\begin{theorem}[Theorem title]
Let $f$ be a function whose derivative exists in every point, then $f$ is a continuous function.


enter image description here

  • Unfortunately, this just pushes the text to the right of the main text body. I want the "Theorem 1" outside the main text body to the left.
    – Teyyf
    Jul 5, 2018 at 16:34

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.