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.

Looking at the wikibooks article on theorems has me wondering... I'd like to do something, if possible, similar to the default "proof" theorem style, whereby I can add a custom name to each theorem as I go along..

Eample: In the wikibooks here, it says that if I use the following code, I get the opportunity to name the proof:

\begin{proof}[Proof of important theorem]
    Here is my important proof
\end{proof}

If I were to leave out the [proof of important theorem], it would just say "Proof:" instead.

I'd like to make it possible to define a definition theorem that always says "Definition #", but I can optionally add a name to it so it may say something like "Definition 3.1 - The answer of the universe and everything", followed by the definition in question.

Right now, this is all I have. I don't know much about TeX yet as I'm just learning it now.

\newtheoremstyle{definitionstyle} % name of the style to be used
  {10mm}        % measure of space to leave above the theorem. E.g.: 3pt
  {10mm}        % measure of space to leave below the theorem. E.g.: 3pt
  {}            % name of font to use in the body of the theorem
  {}            % measure of space to indent
  {\bfseries}   % name of head font
  {\newline}    % punctuation between head and body
  {10mm}        % space after theorem head
  {}            % Manually specify head
\theoremstyle{definitionstyle}
\newtheorem{mydef}{Definition}[section]
share|improve this question

1 Answer 1

up vote 9 down vote accepted

All theorem environments support an optional argument for a theorem's name or a note. In the following example, I use the thmtools package to format the note. (The amsthm package still provides some underlying functionality, but I prefer thmtools' key-value-syntax.)

\documentclass{article}

\usepackage{amsthm}
\usepackage{thmtools}

\declaretheoremstyle[%
  within=section,%
  spaceabove=10mm,%
  spacebelow=10mm%,
  headfont=\bfseries,%
  headpunct={},%
  postheadspace=\newline,%
  notefont=\normalfont\itshape,%
  notebraces={--~}{},% punctuation before and after the note
]{definitionstyle}
\declaretheorem[style=definitionstyle,name=Definition]{mydef}

\usepackage{lipsum}

\begin{document}

\section{foo}

\begin{mydef}[The answer of the universe and everything]
\lipsum[1]
\end{mydef}

\end{document}

enter image description here

share|improve this answer
    
Interesting. What's the difference between \newtheorem and \declaretheorem? –  agent154 Nov 20 '12 at 21:48
    
@agent154 \declaretheorem is the main thmtools command; it uses a syntax different from that of \newtheorem. –  lockstep Nov 21 '12 at 23:19

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.