1

I have document with 30 math examples. How do I number these examples automatically? Without using the list

 \begin{enumerate} ... \end{enumerate}

like

Example 1
blah blah

Example 2
blah blah

and so on?

Zarko
  • 296,517

1 Answers1

10
  • define new counter
  • define new environment with title and number
  • increment counter before its use

Something like this:

\newcounter{xmpl}
\newenvironment{example}
    {\noindent
     \refstepcouter{xmpl}
     \textbf{Example \thexmpl }
    }{\par\noindent%
      \ignorespacesafterend}

and then use as:

\begin{example} 
< content of the example>
\end{example}

Addendum: More simpler and straightforward solution is consider Christian Hupfer comment below: use of newtheorem.

  • load package amsthm
  • declare example environments as \newtheorem{example}{Example}
  • use it as shown above

More details and concise description about theorems like environments you can find in Wikibook LaTeX/Theorems. Sorry, because I didn't recall for this usual approach before.

Addedndum 2: You can also use enumerate environment. Package enumitem offer simple redefinition of labels:

\documentclass{article}
\usepackage{enumitem}
\usepackage{lipsum}

\begin{document}
    \begin{enumerate}[label=Exercise \arabic*]
\item \lipsum*[11]
\[
c = \sqrt{a^2 + b^2}
\]
\item blah blah
\[
a = \sqrt{c^2 - b^2}
\]
\item blah blah
    \end{enumerate}
\end{document}

For other possibilities for formatting of enumerate environment see package documentation.

Of course this recent solution has sense if examples are organised as list, i.e. examples follow one after another.

enter image description here

Zarko
  • 296,517
  • 4
    You could also mention the usual \newtheorem approach, \newtheorem{example}{Example}, for example (pun intented ;-)) –  May 06 '17 at 06:49
  • 1
    @ChristianHupfer, thank you very much for comment. I consider it in my answer. – Zarko May 06 '17 at 08:07