2

I'm using tcolorbox to draw boxes around my theorems. This package also has the option of puting the theorem numbers in the margin as you can see in my MWE below; see page 342 of the manual for more details.

The problem is that, even with a pretty vanilla setup as in my example, the numbering of the theorem overlaps with the box. I could not find an option for adjusting this, but I'm sure there must be something.

Does anybody know how to place the theorem number farther from the theorem box?

Please note that I would like to use tcolorbox, so please don't suggest a solution for a similar effect using a different package.

EDIT: In case I was not very clear, I need the numbering to be inside the margin, outside the box, and left from the box. I do not ask to put the number back in the box, this could simply be done by removing the margin apart style.

\documentclass{article}
\usepackage[theorems]{tcolorbox}
\usepackage{xcolor}

\newtcbtheorem[number within=subsection]%
{theorem} % \begin..
{Theorem} % Title
{theorem style = margin apart, % Style
 colback=white,
 colframe=lightgray,
 coltitle=black}
{theo} % label prefix; cite as ``theo:yourlabel''

\usepackage{lipsum}

\begin{document}

\section{My section}
\subsection{My subsection}
\begin{theorem}{The title}{mylabel}
This is a theorem.
\end{theorem}

\end{document}

enter image description here

  • I tried adding something like "left=-2mm", but this moves all the text, including the contents and the titles, so it's not good. I'd like the titles and contents of the theorem to remain where they are, while the number shifts to the left. – geo909 Jun 23 '16 at 14:09
  • Using the numbers outside in the margin does not really look nice, regardless whether this is done with tcolorbox or anything else – user31729 Jun 23 '16 at 15:08
  • I know, but I need to do it anyway – geo909 Jun 23 '16 at 15:10
  • I'll be writing a huge thesis with a gazillion of numbered stuff, that my supervisor will be reading in print, not as a pdf. That will make his life much easier, when I am to print the final draft, I'll probably switch back to normal numbering.. – geo909 Jun 23 '16 at 15:16
  • sigh, supervisors .... – user31729 Jun 23 '16 at 15:29
3

It's possible with a theorem name style and shifting a overlay out of the box with overlay={\node[...]}

\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{xcolor}

\newtcbtheorem[number within=subsection]%
{theorem} % \begin..
{Theorem} % Title
{%theorem style = margin apart, % Style
  enhanced,
  colback=white,
  colframe=lightgray,
  theorem name,
  coltitle=black,%
  overlay={\node[xshift=-20pt] (A) at (title.west) {\bfseries \thetcbcounter};},
  left=2mm,
  }
{theo} % label prefix; cite as ``theo:yourlabel''

\usepackage{lipsum}

\begin{document}

\section{My section}
\subsection{My subsection}
\begin{theorem}{The title}{mylabel}
This is a theorem.
\end{theorem}

\end{document}

enter image description here

  • Thanks, but this is entirely different from what I'm looking for. I would like the numbers to be inside the margin, that is, outside the box and left from the box, while the title remains where it is. – geo909 Jun 23 '16 at 14:55
  • @geo909: Well, use some lefttitle= with negative value then, but actually, this does not really look nice – user31729 Jun 23 '16 at 15:01
  • As I was saying, this will cause the whole title to shift, so the numbers and the "Theorem (The title)". I only want the numbers to be in the margin and the title to remain where it is. – geo909 Jun 23 '16 at 15:04
4

Based on Christian's solution, I've introduced a magic number as left skip and the result looks like:

enter image description here

\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{xcolor}

\newtcbtheorem[number within=subsection]%
{theorem} % \begin..
{Theorem} % Title
{%theorem style = margin apart, % Style
  enhanced,
  colback=white,
  colframe=lightgray,
  theorem name,
  coltitle=black,%
  overlay={\node[xshift=-20pt] (A) at (title.west) {\bfseries \thetcbcounter};},
  left=2mm,
%  show bounding box,
%  width=\linewidth,
  left skip=32pt
  }
{theo} % label prefix; cite as ``theo:yourlabel''

\usepackage{lipsum}

\begin{document}

\section{My section}
\subsection{My subsection}

\lipsum[1]

\begin{theorem}{The title}{mylabel}
This is a theorem.
\end{theorem}

\end{document}
  • Oh, that's nice too (+1) -- The value of 32pt is the width of 1.1.1, I assume? – user31729 Jun 24 '16 at 16:13
  • It's supposed to be, but I fond it by trial and error. – Ignasi Jun 24 '16 at 17:36

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.