# New command or environment for numbered examples [duplicate]

So I looked at the \newcommand command and I'm not quite sure how I can use that to my advantage. So I'm asking for your help :)

I am making a paper which has problems and examples in it. And I would like to have a command which will automatically make a mini text, let's say: Example 1, or Example 1.1 (according to the sections and subsections), that is bolded and in a specific color.

Currently I have the following syntax:

{\bf \color{Green}Example 3.}\bigskip

Show this and that...

{\bf \color{Emerald}Solution:}\bigskip


And this looks fine in PDF, but it get's kinda tedious. I have to watch what is the example number, and have I accidentally repeated it and so on.

The same would be for exercises.

How can I do something like that, so that I only have to write (in code) \example

or just \begin{example}.

-

## marked as duplicate by Marco Daniel, Mico, egreg, Seamus, Stefan Kottwitz♦Nov 10 '11 at 15:47

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

– Stefan Kottwitz Nov 10 '11 at 9:56
I thing you should read l2tabu. \bf is obsolete. – Marco Daniel Nov 10 '11 at 9:57
e.g. \newcommand{\example}[1]{\textcolor{Green}{\textbf{#1}}\bigskip}, but defining a proper headline would be better. – Martin Scharrer Nov 10 '11 at 10:10

## 1 Answer

You could use the amsthm package to make your own example environments.

\documentclass{scrartcl}

\usepackage{amsthm}
\usepackage{xcolor}

\newtheoremstyle{own}%
{3pt}% Space above
{3pt}% Space below
{}% Body font
{}% Indent amount
{\color{blue}\bfseries}% Theorem head font
{:}% Punctuation after theorem head
{\newline}% Space after theorem head
{}% Theorem head spec

\theoremstyle{own}
\newtheorem{example}{Example}[section]

\begin{document}
\section{Some Headline Text}
\begin{example}
Some Text.
\end{example}
\end{document}


Please note that {\bf Text} is old TeX syntax. With LaTeX you should use at least {\bfseries Text} or even better \textbf{Text}.

-
Good advice! However, sometimes it's better to point to already existing solutions on the site, if you might know one. Closing as a duplicate, thus giving a clearly visible link, is better than collecting duplicates on the site, though it doesn't give reputation. – Stefan Kottwitz Nov 10 '11 at 10:00
@StefanKottwitz: Sorry, I didn’t think of that … – Tobi Nov 10 '11 at 10:06
No problem, just a general remark. Your specific solution here is helpful, especially since it shows the way of customization regarding font and color. – Stefan Kottwitz Nov 10 '11 at 10:09
This looks and works perfectly!! Thank you ^^ – dingo_d Nov 10 '11 at 14:29