New command or environment for numbered examples

3,739

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:
3,739

Related videos on Youtube

dingo_d
Author by

dingo_d

Updated on November 11, 2020

Comments

  • dingo_d
    dingo_d about 3 years

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

  • Stefan Kottwitz
    Stefan Kottwitz about 12 years
    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.
  • Tobi
    Tobi about 12 years
    @StefanKottwitz: Sorry, I didn’t think of that …
  • Stefan Kottwitz
    Stefan Kottwitz about 12 years
    No problem, just a general remark. Your specific solution here is helpful, especially since it shows the way of customization regarding font and color.
  • dingo_d
    dingo_d about 12 years
    This looks and works perfectly!! Thank you ^^