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.

Possible Duplicate:
Good environment for writing math examples
How to create a new counter for an a new environment that is in sync with subsections

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

share|improve this question
3  
2  
I thing you should read l2tabu. \bf is obsolete. –  Marco Daniel Nov 10 '11 at 9:57
1  
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
add comment

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.

1 Answer

up vote 5 down vote accepted

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

share|improve this answer
1  
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
add comment

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