1

I'm not sure if this has already been asked, but I have been curious if amsthm also contains support for "examples".

For example, I would like to have something like

\begin{example} 
 ...
 \end{example}

that gets auto numbered in the same way as theorems, lemmas, remarks, etc.

Is there any LaTeX package that supports this?

  • 4
    \newtheorem{example}{Example}, out of the box with LaTeX or with amsthm then. It will define a counter example, is numbered and can be referred to – user31729 Jan 1 '17 at 9:52
  • 1
    If you prefer some eye-candy, look for mdframed and tcolorbox, both provide theorem environments with colour etc. There are certainly more packages that define theorem - like environments. – user31729 Jan 1 '17 at 10:03
2

Three short example definitions from amsthm, tcolorbox and mdframed. See the different options and the similarities.

\documentclass{article}

\usepackage{amsthm}
\usepackage[most]{tcolorbox}

\usepackage{mdframed}

\newtheorem{amsexample}{Example from amsthm package}[section] % Defines a counter named amsexample which resets with section

\newtcbtheorem[auto counter,number within=section]{tcbexample}{Example from tcolorbox}{%
  colback=white!90!yellow,
  colbacktitle={yellow}, 
  coltitle={black}
}{exa}

\newmdtheoremenv[backgroundcolor=cyan]{mdfexample}{Example from mdframed package}[section]



\begin{document}

\section{A section}

\begin{amsexample}
  Some example.
\end{amsexample}

\begin{tcbexample}{This is my example title}{first}
  Some example.
\end{tcbexample}

\begin{mdfexample}[MDF example title]
  Some example.
\end{mdfexample}

See \ref{exa:first} for more eye-candy. 


\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.