42

What is the etiquette to denote the end of an example or remark? For proofs, it's the QED symbol (white box). I know it's not necessary for everyone, but I would like to use it to break up the text a little. What should I use? A circle or filled box or what?

lockstep
  • 250,273
P.A
  • 791

5 Answers5

43

Try the following indirect method (requires amsthm):

\newtheorem{example}{Example}
\AtBeginEnvironment{example}{%
  \pushQED{\qed}\renewcommand{\qedsymbol}{$\triangle$}%
}
\AtEndEnvironment{example}{\popQED\endexample}

Full example

\documentclass{article}
\usepackage{amsmath,amsthm}

% some setup % % maybe change here the default symbol % \renewcommand{\qedsymbol}{...} % \NewCommandCopy{\proofqedsymbol}{\qedsymbol}% save the default \newcommand{\exampleqedsymbol}{$\triangle$}% for end of examples

% ensure that proof has the standard symbol \AtBeginEnvironment{proof}{\renewcommand{\qedsymbol}{\proofqedsymbol}}

% define an environment for examples \theoremstyle{definition}

\newtheorem{example}{Example} \AtBeginEnvironment{example}{% \pushQED{\qed}\renewcommand{\qedsymbol}{$\triangle$}% } \AtEndEnvironment{example}{\popQED\endexample}

\begin{document}

\begin{example} This has only text. \end{example}

\begin{example} This has text but also a proof inside it. \begin{proof} This is the proof of the above claim. \end{proof} And now the example is over. \end{example}

\begin{example} This has also a display at the end: \begin{align} f(x) &= \bigl( g(x) \bigr) \ h(x) &= \bigl( r(x) \bigr).\qedhere \end{align} \end{example}

\end{document}

enter image description here

LaTeX has now incorporated \AtBeginEnvironment and \AtEndEnvironment that used to be only available with etoolbox.

Original answer

Try the following indirect method (requires amsthm):

\newtheorem{examplex}{Example}
\newenvironment{example}
  {\pushQED{\qed}\renewcommand{\qedsymbol}{$\triangle$}\examplex}
  {\popQED\endexamplex}

In this way also \qedhere works exactly like in proof.

Full example.

\documentclass{article}
\usepackage{amsmath,amsthm}

\theoremstyle{definition} \newtheorem{examplex}{Example} \newenvironment{example} {\pushQED{\qed}\renewcommand{\qedsymbol}{$\triangle$}\examplex} {\popQED\endexamplex}

\begin{document}

\begin{example} This has only text. \end{example}

\begin{example} This has also a display at the end: \begin{align} f(x) &= \bigl( g(x) \bigr) \ h(x) &= \bigl( r(x) \bigr).\qedhere \end{align} \end{example}

\end{document}

egreg
  • 1,121,712
  • Seems there's a couple of syntax problems here. (Feel free to remove this comment when fixed.) – badroit Jul 17 '12 at 16:35
  • Nice. With etoolbox you can define a command to patch a previously declared theorem type: \newcommand{\addQEDstyle}[2]{\AtBeginEnvironment{#1{\pushQED{\qed}\renewcommand{\qedsymbol}{#2}}\AtEndEnvironment{#1}{\popQED}}. Call as \addQEDstyle{example}{$\triangle$} – Andrew Swann Nov 21 '17 at 14:12
  • @AndrewSwann That could be an alternative way. – egreg Nov 21 '17 at 14:19
  • @AndrewSwann That is an awesome solution, but there is a small typo: \AtBeginEnvironment{#1 should be \AtBeginEnvironment{#1} -> the final brace is missing ;-) – wmnorth Nov 29 '18 at 21:59
  • @wmnorth Yes thanks - unfortunately I can no longer edit my comment. – Andrew Swann Nov 30 '18 at 07:38
  • @egreg Is it possible to force example labelling to follow a certain section, subsection or even subsubsection? For example, if I write an example in subsection 3.1.2, I would get Example 3.1.2 (or, for multiple examples in the same section, Example 3.2.1.1, Example 3.2.1.2, and so on). I would be happy if it only follows the leading section (so we would get Example 3.1 and Example 3.2). Any ideas? – sam wolfe Jul 07 '22 at 11:28
  • @samwolfe That's a completely different topic – egreg Jul 07 '22 at 11:49
  • @egreg See here for continued discussion: https://tex.stackexchange.com/questions/650131/labelling-examples-remarks-based-on-section – sam wolfe Jul 07 '22 at 12:26
  • @egreg Is it possible to do the same tweak when using examples in multiple languages? (If it should be its own question tell me and I'll ask) – cgss Aug 27 '22 at 17:38
  • If I do this (or Andrew Swann's solution) it works as claimed. However, if I put a proof inside the example, it also changes the qedsymbol for the proof ... How can this be avoided? – Dan Fox Jul 21 '23 at 08:09
  • @DanFox I modified the code to do what you want. – egreg Jul 21 '23 at 08:29
19

I think this is totally a matter of personal style. If you are using \qed already you could use a similar symbol like \triangle.

Whatever you do, don't just use \hfil$\triangle$ because this does not work when your example fills the last line completely. Here is a definition of \demo that uses the flexible \xqed:

\documentclass{minimal}
\usepackage[utf8]{inputenc}

\newcommand\xqed[1]{%
  \leavevmode\unskip\penalty9999 \hbox{}\nobreak\hfill
  \quad\hbox{#1}}
\newcommand\demo{\xqed{$\triangle$}}

\begin{document}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.
\demo    
\end{document}

The manfnt font also provides a filled triangle pointing to the right. After declaring \font\manual=manfnt you can use \manual\char'170.

Two different triangles

  • Thanks, I'll try it out and get back. Maybe I'll use a different shape than a triangle though. – P.A Apr 24 '11 at 09:17
  • The triangle pointing the right looks as though it is a link to somewhere else. What specifically is it supposed to denote? – brannerchinese Apr 24 '11 at 09:34
  • 1
    @brannerchinese I had no specific meaning in mind, it is just one of the lesser known symbols in the standard fonts. I agree that it suggests a continuation and as such is not appropriate for denoting the end of a section. – Christian Lindig Apr 24 '11 at 09:49
  • 1
    If I have an equation as the last line in my example, unfortunately the character appears a few lines before my last line. Is there a way to change that? I tried putting the \demo before the end of equation, but that makes the symbol not align properly. – P.A Apr 24 '11 at 11:01
  • @P.A It works for me so you need to provide an example that does not work. – Christian Lindig Apr 24 '11 at 12:13
  • Actually my problem is with the second triangle in your example. Ideally I'd like the triangle to appear on the last line (so on the same line as the series) -- like what they say should happen with proofs and the QED symbol (there, if you finish with a displayed equation, you need to use \qedhere). Edit: and sorry, I meant "after my last line" in my above comment. – P.A Apr 24 '11 at 16:17
  • Please post a working example as part of your original question or a new question. – Christian Lindig Apr 24 '11 at 17:13
  • @ChristianLindig: The following question of mine is considered a duplicate of this one: http://tex.stackexchange.com/questions/317369/well-behaved-qedsymbol-like-for-example-environment?noredirect=1#comment774658_317369 . Still, in my question I give a MWO of the problem that I think the OP mentioned in the comments above. Any feedback is more than welcome. – Kolmin Jun 30 '16 at 15:55
10

The very useful thmtools package has a key for defining the qed-symbol. For example, I use the following in my documents:

\usepackage{amsthm,thmtools}
\theoremstyle{remark}
\declaretheorem[name=Example,qed={\lower-0.3ex\hbox{$◃$}}]{Ex}

...

\begin{Ex}
  The numbers 2, 3 and 5 are all prime.
\end{Ex}

(I use unicode-math to be able to use the ◃ symbol directly. Just replace it by whatever symbol you like, e.g. \triangleleft.)

Everything is set up correctly so that you can use \qedhere like in a standard amsthm proof environment.

Caramdir
  • 89,023
  • 26
  • 255
  • 291
3

Maybe you’ll like to use the {leftbar}-environment?

\documentclass{minimal}
\usepackage{framed}
\begin{document}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.
\begin{leftbar}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.
\end{leftbar}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.
\end{document}

If you like it I can show an extended example with a colored bar, no indention of first line an support for floating objects in the environment.

Tobi
  • 56,353
0

Use \qed right before \end{example} :

\newtheorem{example}[definition]{Example}
.
.
.
\begin{example}
5+6=11
\qed
\end{example}
Behdad
  • 19
  • 2