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.

I am trying to have an example (using the theorem environent in amsmath) split in two parts:

Example 1 ...

Some more discussion

Example 1 (continued) ...

What is the best way to do this ?

The code I have so far is

\documentclass{article}

\usepackage{amsmath}
\newtheorem{example}{Example}

\begin{document}

Consider the following example:

\begin{example}
  $a = b + c$
\end{example}

Now, consider what happens if we add $d$ to $a$:

\begin{example}[continued] % I'd like to have this to output Example 1 (continued)
  $a + d$
\end{example}

\end{document}
share|improve this question
1  
Please post the code you have so far and we can help. This should include \documentclass and the packages that you are using. Otherwise it is not clear what the problem is. –  Peter Grill Sep 14 '11 at 22:21
    
My apologies, I forgot that examples, theorems, etc are not built in. –  Anton Belov Sep 14 '11 at 22:57
    
Anton: I've added a second MWE, in response to a suggestion by cmhughes, to show how one could automate the insertion of the command \addtocounter{example}{-1}. –  Mico Sep 15 '11 at 1:04

6 Answers 6

up vote 3 down vote accepted

I think you can keep most of your previous code. All you need to do is add a few instructions in the preamble -- specifically, load the ntheorem package and modify the default definition of theoremstyle (the latter is needed only if you want to see , continued rather than (continued)) -- and remember to issue the command \addtocounter{example}{-1} before typing \begin{example}[continued].

See the following MWE:

\documentclass{article}
\usepackage{amsmath}
\usepackage[amsmath]{ntheorem}
\makeatletter
\renewtheoremstyle{plain}%
  {\item[\hskip\labelsep \theorem@headerfont ##1\ ##2\theorem@separator]}%
  {\item[\hskip\labelsep \theorem@headerfont ##1\ ##2, ##3\theorem@separator]}
\makeatother
\newtheorem{example}{Example}

\begin{document}

\section{Some thoughts}
Consider the following example:
\begin{example}
$a = b + c$
\end{example}
Now consider what happens if we add $d$ to $a$:
\addtocounter{example}{-1}
\begin{example}[continued]
$a + d$
\end{example}
\end{document}

Edit: Following up on the suggestion of cmhughes, here's a version of the preceding MWE that's very similar but relieves the author of having to remember to type \addtocounter{example}{-1} before starting the example. This is achieved by creating a new environment I've named contexample; its style is identical to that of the example environment except that it appends ", continued" to the environment's header. Note that with this device, any example can be "continued" as often as one wishes.

\documentclass{article}
\usepackage{amsmath}
\usepackage[amsmath]{ntheorem}
\makeatletter
\renewtheoremstyle{plain}%
  {\item[\hskip\labelsep \theorem@headerfont ##1\ ##2\theorem@separator]}%
  {\item[\hskip\labelsep \theorem@headerfont ##1\ ##2, ##3\theorem@separator]}
\makeatother
\newtheorem{example}{Example}
\newenvironment{contexample}{
   \addtocounter{example}{-1} \begin{example}[continued]}{
   \end{example}}

\begin{document} 
\section{Some thoughts}
Consider the following example:
\begin{example}
$a = b + c$.
\end{example}
Now consider what happens if we add $d$ to $a$:
\begin{contexample}
$a + d$.
\end{contexample}
And if we wish to continue along these lines, we also find
\begin{contexample}
$x = y$.
\end{contexample}
\end{document}
share|improve this answer
    
Thank you, this is the simplest way to do what I needed. –  Anton Belov Sep 15 '11 at 0:08
    
You could put the \addtocounter{example}{-1} in the definition- it could go before the \hskip in the second \item; then you wouldn't have to change the counter manually every time. –  cmhughes Sep 15 '11 at 0:16
    
@cmhughes: Great suggestion! I've added a second MWE to illustrate how this would work. –  Mico Sep 15 '11 at 0:50
    
@Mico. It's not quite what I intended; I was thinking of {\item[\addtocounter{example}{-1}\hskip\labelsep \theorem@headerfont ##1\ ##2, ##3\theorem@separator]} which then allows the use \begin{example} or \begin{example}[continued] –  cmhughes Sep 15 '11 at 2:30
    
Thanks, really nifty idea. I guess I wasn't going to go as far as assume that whenever the example environment starts with any option given in square brackets, doing so would imply that it's a continuation of the preceding example. Such a working assumption, I'm afraid, will create havoc whenever the body of the example happens to start off with a left square bracket, won't it though? –  Mico Sep 15 '11 at 4:50

Using the thmtools package as a front-end for amsmath (or ntheorem) you can easily achive what you need using the label=<key> and continues=<key> keys. A little example:

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

\declaretheorem[style=definition]{example}

\begin{document}

\renewcommand\thmcontinues[1]{Continued}

\begin{example}[label=exa:cont]
This is an example.
\end{example}
\begin{example}[continues=exa:cont]
And here's the continuation of the example.
\end{example}

\end{document}

enter image description here

The text displayed is controlled by the \thmcontinues command which you can redefine according to your needs, as I did in my example code; by default it will display something like (continuing from p. <the_page>), where <the_page> is the page number of the first occurrence of the example.

share|improve this answer
    
very nice, thank you –  Anton Belov Sep 15 '11 at 0:02

Adapting cmhughes idea, but keeping the use of the \newtheorem command, you can simply make a new theorem type for continuations, and set the counter for that theorem to match the main example counter:

\documentclass{article}

\usepackage{amsmath}
\newtheorem{example}{Example}
\newtheorem{excont}{Example}
\renewcommand{\theexcont}{\theexample}

\begin{document}

Consider the following example:

\begin{example}
  $a = b + c$
\end{example}

Now, consider what happens if we add $d$ to $a$:

\begin{excont}[Continued]% I'd like to have this to output Example 1 (continued)
  $a + d$
\end{excont}

\end{document}
share|improve this answer
    
perfect solution for my problem –  Anton Belov Sep 15 '11 at 0:00

If the continuation always follows the main environment, this works

\documentclass{article}

\usepackage{amsthm}
\newtheorem{exampleinn}{Example}
\newtheorem*{example*}{Example \DO}
\newenvironment{example}
  {\xdef\DO{\number\numexpr\value{exampleinn}+1\relax\ (continued)}%
   \exampleinn}
  {\endexampleinn}

\begin{document}

Consider the following example:

\begin{example}
  $a = b + c$
\end{example}

Now, consider what happens if we add $d$ to $a$:

\begin{example*} % I'd like to have this to output Example 1 (continued)
  $a + d$
\end{example*}

\end{document}

The example* environment can be used any number of times and it will always refer to the main example. If the numbering of the example environment is more complex (say section.number), some more work is needed.

share|improve this answer

The following code defines two environments: example and examplecont. Note that only the example environment increments the counter.

\documentclass{article}

\usepackage{lipsum}% only needed for sample text

\newcounter{example}
\newenvironment{example}{%
\refstepcounter{example}%
{\bfseries Example \theexample}}{}

\newenvironment{examplecont}{%
{\bfseries Example \theexample} (cont\ldots)}{}

\begin{document}

\begin{example}
\lipsum[1]
\end{example}

\lipsum[2]

\begin{examplecont}
\lipsum[3]
\end{examplecont}
\end{document}

EDIT If you want a solution that uses an optional argument, here's one:

\documentclass{article}

\usepackage{lipsum}% only needed for sample text
\usepackage{ifthen}

\newcounter{example}
\newenvironment{example}[1][]{%
\ifthenelse{\equal{#1}{continued}}%
{%
{\bfseries Example \theexample (continued\ldots)\quad}%
}%
{%
\refstepcounter{example}%
{\bfseries Example \theexample \quad}%
}%
}{}

\begin{document}

\begin{example}
\lipsum[1]
\end{example}

\lipsum[2]

\begin{example}[continued]
\lipsum[3]
\end{example}
\end{document}
share|improve this answer
    
I posted this before your edit about using a theorem environment –  cmhughes Sep 14 '11 at 23:08

Starting from here, with just a few visual modifications:

enter image description here

\documentclass{article}
\usepackage{amsthm}
\begin{document}
\section{Original}

\newtheorem{exampleorig}{Example}

Consider the following example:

\begin{exampleorig}
  $a = b + c$
\end{exampleorig}

Now, consider what happens if we add $d$ to $a$:

\begin{exampleorig}[continued] % I'd like to have this to output Example 1 (continued)
  $a + d$
\end{exampleorig}

\section{Modified}

\newcounter{definition}
\newtheoremstyle{example}
{\topsep} {\topsep}%
{\upshape}% Body font
{}% Indent amount (empty = no indent, \parindent = para indent)
{\bfseries\scshape}% Thm head font
{.}% Punctuation after thm head
{1em}% Space after thm head (\newline = linebreak)
{}% Thm head spec

\theoremstyle{example}
\newtheorem{example}[definition]{Example}

\newtheoremstyle{example_contd}
{\topsep} {\topsep}%
{\upshape}% Body font
{}% Indent amount (empty = no indent, \parindent = para indent)
{\bfseries\scshape}% Thm head font
{.}% Punctuation after thm head
{1em}% Space after thm head (\newline = linebreak)
{\thmname{#1} \thmnumber{ #2}\thmnote{#3} (continued)}% Thm head spec

\theoremstyle{example_contd}
\newtheorem*{example_contd}{Example}

Consider the following example:

\begin{example} \label{ex:example1}
  $a = b + c$
\end{example}

Now, consider what happens if we add $d$ to $a$:

\begin{example_contd}[\ref{ex:example1}] % I'd like to have this to output Example 1 (continued)
  $a + d$
\end{example_contd}

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