TransWikia.com

Numbering theorem-like environments

TeX - LaTeX Asked on March 14, 2021

I would like all my theorem-like environments (theorem, example, etc.) to be numbered but such that the number appears before the environment’s name, more or less like this:

1. Theorem

2. Example

How can I do this?

3 Answers

amsthm provides swapnumbers which reverses the display of Theorem <num>. to <num> Theorem. Here's a minimal example:

enter image description here

documentclass{article}
usepackage{amsthm}% http://ctan.org/pkg/amsthm
swapnumbers % Switch number/label style
theoremstyle{plain}
newtheorem{theorem}{Theorem}
newtheorem{example}[theorem]{Example}
begin{document}
begin{theorem}
This is a theorem.
end{theorem}
begin{example}
This is an example.
end{example}
end{document}​

In the above example, the example environment shares the theorem counter. Moreover, both are defined with the plain style. There are others available, as shown in the amsthm package documentation.

Correct answer by Werner on March 14, 2021

There are few ways to create theorem like environments. Here's an option using ntheorem

screenshot

The trick is to make a new theoremstyle using the arguments

  • ##1 which is the name of the theorem
  • ##2 which is the number of the theorem
  • ##3 which is the optional title of the theorem

Using the examples in the ntheorem documentation as a guide, you can tweak this to suit your needs.

documentclass{article}

usepackage{lipsum}
usepackage{ntheorem}

makeatletter
newtheoremstyle{numberfirst}%
{item[theorem@headerfont{##2theorem@separatorhskiplabelsep ##1}]}%
{item[theorem@headerfont{##2theorem@separatorhskiplabelsep ##1} (##3)]}%
makeatother

theoremstyle{numberfirst}
theoremseparator{.}
newtheorem{mytheorem}{Theorem}

begin{document}

begin{mytheorem}
lipsum[1]
end{mytheorem}

begin{mytheorem}[Optional title]
lipsum[1]
end{mytheorem}

end{document}

Answered by cmhughes on March 14, 2021

amsthm has a command swapnumbers that, when specified before the theoremstyle or newtheorem elenments for which numbers are to come first, will do what you want.

for details, see the amsthm user's guide, section 4.2 on "number swapping".

Answered by barbara beeton on March 14, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP