Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

This one should be easy for the gurus…

Suppose I want to define a theorem environment which has a custom numbering scheme. That is, instead of being numbered according to some counter, it is numbered according to a passed parameter. So writing something like

\begin{customtheorem}{8}
   Text.
\end{custom theorem}

would produce

Theorem 8. Text.

I realize I could define a new environment on my own, but then the header will be bold, or small caps, or whatever I defined it to be, and so may differ from the rest of the document if I switch documentclass. So I would like something that also matches the regular theorem headers.

Thanks in advance for any ideas.

share|improve this question

2 Answers 2

up vote 14 down vote accepted

An easy way is

\documentclass{article}
%\usepackage{amsthm} %% uncomment to see the difference
\newtheorem{innercustomthm}{Theorem}
\newenvironment{customthm}[1]
  {\renewcommand\theinnercustomthm{#1}\innercustomthm}
  {\endinnercustomthm}

\begin{document}

\begin{customthm}{8}\label{eight}
Every theorem must be numbered by hand.
\end{customthm}

Here is a reference to theorem~\ref{eight}.
\end{document}

You can also use the optional argument for attribution:

\begin{customthm}{99}[Somebody]\label{ninetynine}
Statement.
\end{customthm}
share|improve this answer
    
I guess that's simpler than mine (and allows non numeric values too) –  David Carlisle May 1 '12 at 16:48
    
@DavidCarlisle Yes, it uses the fact that innercustomthm is stepped, so the reference is established, but \theinnercustomthm is used, which can contain anything (well, almost). –  egreg May 1 '12 at 16:50
    
This is splendid. Thanks so much. @DavidCarlisle: I went with egreg's, because it's simpler, but thanks also! –  Skeptic May 1 '12 at 17:06
    
I am interested in an extension of this behavior. Let's say I want to create a theorem with the same label as a previous theorem. I would like to display this as \begin{customthm}{\ref{oldtheorem}}\end{customthm}, but this gives me errors. How would I modify this code to achieve the desired result? –  Jonathan Gleason Aug 10 '12 at 15:20
    
The optional argument form did not work for me (I'm using amsthm). I fixed this with \newenvironment{customthm}[2][]{\renewcommand\theinnercustomthm{#2}\innercustom‌​thm[#1]}{\endinnercustomthm}. –  equaeghe Mar 7 at 15:42

You can just temporarily reset your theorem counter:

\documentclass{article}
\usepackage{amsthm}


\newtheorem{Theorem}{Theorem}



\makeatletter

\newenvironment{customTheorem}[1]
  {\count@\c@Theorem
   \global\c@Theorem#1 %
    \global\advance\c@Theorem\m@ne
   \Theorem}
  {\endTheorem
   \global\c@Theorem\count@}

\makeatother


\begin{document}


\begin{Theorem}
Dummy text
\end{Theorem}

\begin{customTheorem}{99}
Dummy text
\end{customTheorem}

\begin{Theorem}
Dummy text
\end{Theorem}


\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.