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). 

3 Answers3

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}
Gonzalo Medina
  • 505,128
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

egreg
  • 1,121,712
  • I'm glad you noticed the problem with enumerate; I need that to work. – Randy Randerson Dec 16 '14 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. – Randy Randerson Dec 17 '14 at 06: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. – Randy Randerson Dec 17 '14 at 06:43
  • @fctaylor25 There were a couple of typos, I fixed them – egreg Dec 17 '14 at 07:27
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

Bernard
  • 271,350
  • 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. – barbara beeton Dec 16 '14 at 19:18
  • I'll do that in a moment. Would sticking to just fourier be OK? – Bernard Dec 16 '14 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. – barbara beeton Dec 16 '14 at 19:22
  • @Bernard: I prefer CM roman. – Randy Randerson Dec 16 '14 at 19:23
  • @fctaylor25: changed font and body of theorem so as to have a two-line statement. – Bernard Dec 16 '14 at 19:35
  • @Bernard: A couple of things: (1) the theorem body text should be aligned with the theorem head, (2) I'm not sure how to get rid of the number for definitions (I'm used to amsthm). I'd appreciate it if you would include that in the answer. Seems solid otherwise, thanks for the response! – Randy Randerson Dec 16 '14 at 19:37
  • But theorem body text is aligned with theorem head. You can check on the .odf. I guess it's an optical effect on the screen. For definition, I'll update in a moment (not sure what definition formatting is in amsthm). – Bernard Dec 16 '14 at 19:42
  • Maybe I'm using the term incorrectly. What I mean is the body text should be aligned with the word "Theorem" rather than the theorem number. – Randy Randerson Dec 16 '14 at 19:46
  • I see. That's more complicated, as the length of the numbering may vary. I've updated my answer to add an example of an unnumbered definition. – Bernard Dec 16 '14 at 19:57
  • It's easy to realize the alignment if you want the theorem number in the margin, and the word ‘Theorem’ to begin at the text left margin. – Bernard Dec 16 '14 at 20:09