5

I am trying to construct a theorem environment which roughly looks like this:

1.1   Theorem   Statement of the theorem. Here is some extra text so you can see how the
      theorem body text should be indented (aligned with theorem head). 

The theorem head should be bold, with no punctuation after. The spacing between thmnumber and thmname should be adjustable. Body text normal.

I want to be able to use the environment for definitions as well (which won't be numbered), so it should be possible to remove the number without affecting the alignment of the theorem head. Example:

      Definition   Statement of the definition. It should be aligned the same way as a 
      theorem. 

Here is some body text in the document. Note that the theorem numbers are not in the
margin. 

1.1   Theorem   Statement of the theorem. Here is some extra text so you can see how the
      theorem body text should be indented (aligned with theorem head). 
5
  • @Sigur: I know how to interchange thmnumber and thmname, its the alignments that I don't know how to do. Commented Dec 16, 2014 at 18:03
  • it would be helpful to say what document class you intend to use. Commented Dec 16, 2014 at 19:20
  • @barbarabeeton: article Commented Dec 16, 2014 at 19:22
  • possible duplicate of Numbering theorems in the left margin
    – Werner
    Commented Dec 16, 2014 at 20:01
  • Similar, but not a duplicate. I want the numbers aligned with the body text, not in the margin. Commented Dec 16, 2014 at 20:12

3 Answers 3

4

Here's a way to do it; this will also comply with lists such as enumerate in the statement, which solutions with \hangindent won't.

\documentclass{article}
\usepackage{showframe} % just for the example
\usepackage{amsthm}
\usepackage{enumitem}
\usepackage{xparse}

\usepackage{lipsum}

\newtheoremstyle{fctaylor}% name
  {\topsep}%      Space above
  {\topsep}%      Space below
  {\normalfont}%         Body font
  {}%         Indent amount (empty = no indent, \parindent = para indent)
  {\bfseries}% Thm head font
  {}%        Punctuation after thm head
  {0pt}%     Space after thm head: " " = normal interword space;
  {\makethmhead{#1}{#2}{#3}}

\newlength\fctaylortheoremindent
\AtBeginDocument{\setlength\fctaylortheoremindent{3em}} % <- customize here
\newlength\fctaylorlabelsep
\AtBeginDocument{\setlength\fctaylorlabelsep{1em}} % <- customize here

\makeatletter
\newcommand{\makethmhead}[3]{%
  \gdef\thisthmhead{%
    \makebox[\fctaylortheoremindent][l]{\bfseries#2}%
    {\bfseries#1}%
    \@ifnotempty{#3}{ (#3)}%
    \hspace{\fctaylorlabelsep}%
  }%
}
\makeatother

\newenvironment{fctayloritemize}
 {\list{}{%
    \leftmargin=\fctaylortheoremindent
    \labelwidth=\dimexpr\fctaylortheoremindent-\labelsep\relax
    \itemindent=0pt
  }}
 {\endlist}

\NewDocumentCommand{\newfctaylortheorem}{smomo}{%
  \IfBooleanTF{#1}
   {\newtheorem*{fctaylor@#2}{#4}}
   {\IfNoValueTF{#3}
     {\IfNoValueTF{#5}
       {\newtheorem{fctaylor@#2}{#4}}
       {\newtheorem{fctaylor@#2}{#4}[#5]}}
     {\newtheorem{fctaylor@#2}[fctaylor@#3]{#4}}}%
  \NewDocumentEnvironment{#2}{o}
   {\IfNoValueTF{##1}{\begin{fctaylor@#2}}{\begin{fctaylor@#2}[##1]}%
    \begin{fctayloritemize}\item[\thisthmhead\hfill]}
   {\end{fctayloritemize}\end{fctaylor@#2}}%
}

\theoremstyle{fctaylor}
\newfctaylortheorem{thm}{Theorem}[section]
\newfctaylortheorem*{defn}{Definition}

\begin{document}
\section{One}

\begin{defn}
\lipsum*[2]
\end{defn}

\begin{thm}\label{A}
\lipsum*[2]
\end{thm}

\begin{thm}[Somebody]\label{B}
Something that should show how the text is split across line boundaries
and is correctly indented. And some equivalent conditions:
\begin{enumerate}[label=\upshape(\alph*),ref=(\alph*)]
\item a condition
\item another
\item and another
\end{enumerate}
which show the point made.
\end{thm}

\ref{A} and \ref{B}

\end{document}

enter image description here

4
  • I'm glad you noticed the problem with enumerate; I need that to work. Commented Dec 16, 2014 at 22:11
  • I have two more questions about customizing this code (by the way, it is easy to use and works perfectly). (1) How can I make a theorem with no heading (so it would be just the number and the body text of the theorem)? [I tried just leaving the theorem name blank: \newfctaylortheorem{claim}{} but that didn't work.] (2) How can I make it so that theorems (and claims, see above) are numbered by subsection instead of by section? (I know this is not recommended, but I want to do it anyway)? [I tried \renewcommand{\thethm}{\arabic{subsection}.\arabic{thm}} but it didn't work.] Thanks again. Commented Dec 17, 2014 at 6:36
  • Note that, with the numbering, theorems, claims, etc. should be consecutively numbered. I tried to do this as usual with the thm counter but got an error. Commented Dec 17, 2014 at 6:43
  • @fctaylor25 There were a couple of typos, I fixed them
    – egreg
    Commented Dec 17, 2014 at 7:27
5

Here's a possibility using thmtools as a front-end for amsthm:

enter image description here

The code (adjust the settings according to your needs; in particular, change \thmindent to get the desired hanging indentation for the theorem-like structures):

\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{lipsum}

\newlength\thmindent
\setlength\thmindent{2.5em}

\declaretheoremstyle[
  spaceabove=6pt, 
  spacebelow=6pt,
  headfont=\normalfont\bfseries,
  notefont=\normalfont\bfseries, 
  notebraces={(}{)},
  bodyfont=\normalfont,
  postheadspace=0.5em,
  numberwithin=section,
  headformat={\makebox[\thmindent]{\NUMBER\hfill}\NAME\NOTE},
  postheadhook=\hangindent=\thmindent
]{nuswapindented}
\declaretheoremstyle[
  spaceabove=6pt, 
  spacebelow=6pt,
  headfont=\normalfont\bfseries,
  notefont=\normalfont\bfseries, 
  notebraces={(}{)},
  bodyfont=\normalfont,
  postheadspace=0.5em,
  numbered=no,
  headformat={\makebox[\thmindent]{\mbox{}\hfill}\NAME\NOTE},
  postheadhook=\hangindent=\thmindent
]{unnuswapindented}
\declaretheorem[style=nuswapindented,name=Theorem]{theo}
\declaretheorem[style=unnuswapindented,name=Definition]{defi}

\begin{document}

\section{Test section}

\lipsum[4]
\begin{defi}
\lipsum[4]
\end{defi}
\lipsum[4]
\begin{theo}
\lipsum[4]
\end{theo}

\end{document}
3
  • Will it work when enumerate is used inside thm?
    – egreg
    Commented Dec 16, 2014 at 20:52
  • I tried: after an enumerate inside theo the margin is lost (and the enumerate is misplaced).
    – egreg
    Commented Dec 16, 2014 at 21:55
  • @egreg Yes, I should've thought about it. Commented Dec 17, 2014 at 15:01
2

It can be done with the ntheorem package and its change theoremstyle. The spacing between theorem name and theoremnumber can be adjusted patching the change theorem style: I introduce a new dimension, thlabelsep which defaults to 0.5em and can changed in the preamble:

\documentclass{article}
\usepackage[utf8]{inputenc}

 \usepackage{amsmath}
\usepackage[thmmarks, amsmath, thref]{ntheorem}
\usepackage{cleveref}

\newdimen\thlabelsep
\global\thlabelsep0.5em
\makeatletter
\renewtheoremstyle{change}%
{\item[\hskip\labelsep \theorem@headerfont ##2\hskip\thlabelsep##1\theorem@separator]}%
{\item[\hskip\labelsep \theorem@headerfont ##2\hskip\thlabelsep##1\ (##3)\theorem@separator]}
\makeatother
\theoremstyle{change}
\thlabelsep1.5em
\theoremheaderfont{\bfseries\upshape}
\theoremseparator{}
\theorembodyfont{\upshape}
\newtheorem{thm}{Theorem}[section]

\theoremstyle{nonumberplain}
\newtheorem{defn}{Definition}
\begin{document}

\section{Two Conjectures}

\begin{defn}
  A Sophie Germain prime is a prime number $ p $ such that $ 2p + 1$ is also prime.
\end{defn}

\begin{thm}
There is an infinity of twin primes. Related: There is an infinity of Sophie Germain primes. 
\end{thm}

\end{document} 

enter image description here

10
  • please add more text so that the indentation of lines after the first can be observed. also, it would be better to use more standard fonts; heuristica is one that not everyone is likely to have. Commented Dec 16, 2014 at 19:18
  • I'll do that in a moment. Would sticking to just fourier be OK?
    – Bernard
    Commented Dec 16, 2014 at 19:20
  • more people are likely to have fourier than heuristica, but really, unless a particular font is requested in a question, it's best to stick with the least common denominator, usually cm or lm. Commented Dec 16, 2014 at 19:22
  • @Bernard: I prefer CM roman. Commented Dec 16, 2014 at 19:23
  • @fctaylor25: changed font and body of theorem so as to have a two-line statement.
    – Bernard
    Commented Dec 16, 2014 at 19:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .