Text FormattingLeft-align theorem numbers

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
bstex
Posts: 69
Joined: Mon Oct 23, 2017 10:22 am

Left-align theorem numbers

Post by bstex »

Hi.
I'm using the ntheorem package but I can't force the theorem numbers to be left-aligned.
As you can see in my MWE, the theorem numbers are right-aligned by default, but I need them to be left-aligned. It is a very small detail, but it doesn't look very nice when theorems have bigger numbers, for example 0.150 etc.

My MWE:

Code: Select all

\documentclass[a4paper]{book}
\usepackage{showframe}
\usepackage[top=2.5cm,bottom=2.5cm,inner=3cm,outer=2cm,headsep=10pt]{geometry}
\usepackage{lipsum}

\usepackage[standard]{ntheorem}
\theoremstyle{margin}
\theoremindent3em
\theorembodyfont{\normalfont}
\newtheorem{MyTheorem}{\hspace*{-0.5em}}[chapter]

\begin{document}

\begin{MyTheorem}
\lipsum[2-2]
\end{MyTheorem}

\begin{MyTheorem}
\lipsum[2-2]
\end{MyTheorem}

\begin{MyTheorem}
\lipsum[2-2]
\end{MyTheorem}

\begin{MyTheorem}
\lipsum[2-2]
\end{MyTheorem}

\begin{MyTheorem}
\lipsum[2-2]
\end{MyTheorem}

\begin{MyTheorem}
\lipsum[2-2]
\end{MyTheorem}

\begin{MyTheorem}
\lipsum[2-2]
\end{MyTheorem}

\begin{MyTheorem}
\lipsum[2-2]
\end{MyTheorem}

\begin{MyTheorem}
\lipsum[2-2]
\end{MyTheorem}

\begin{MyTheorem}
\lipsum[2-2]
\end{MyTheorem}

\begin{MyTheorem}
\lipsum[2-2]
\end{MyTheorem}

\begin{MyTheorem}
\lipsum[2-2]
\end{MyTheorem}

\begin{MyTheorem}
\lipsum[2-2]
\end{MyTheorem}

\begin{MyTheorem}
\lipsum[2-2]
\end{MyTheorem}

\begin{MyTheorem}
\lipsum[2-2]
\end{MyTheorem}

\end{document}
Any help, please? I have tried so many things with this package.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Left-align theorem numbers

Post by Johannes_B »

That should give a first clue.
https://tex.stackexchange.com/a/218302/37907
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
bstex
Posts: 69
Joined: Mon Oct 23, 2017 10:22 am

Left-align theorem numbers

Post by bstex »

I have read this post, but I closed the tab because I couldn't do it with the ntheorem package.
Little did I know that I had to change all my theorems preamble code and not use the ntheorem.
Thank you very much!
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Left-align theorem numbers

Post by Stefan Kottwitz »

Hi,

you postest a very good minimal example!

So fur sure we can achieve that. Here is a suggestion using \makebox for left alignment:

Code: Select all

\makeatletter
\newtheoremstyle{leftalign}%
  {\item[\theorem@headerfont \llap{\makebox[1.6em][l]{##2}}%
    \hskip\labelsep ##1\theorem@separator]}%
  {\item[\theorem@headerfont \llap{\makebox[1.6em][l]{##2}}%
    \hskip\labelsep ##1\ (##3)\theorem@separator]}
\makeatother
\theoremstyle{leftalign}
Stefan
LaTeX.org admin
bstex
Posts: 69
Joined: Mon Oct 23, 2017 10:22 am

Left-align theorem numbers

Post by bstex »

I'll try your solution too.
Thank you very much, Stefan. ;)
bstex
Posts: 69
Joined: Mon Oct 23, 2017 10:22 am

Left-align theorem numbers

Post by bstex »

Your solution is excellent with the ntheorem package.
Thank you so much!
Post Reply