6

Consider the following MWE

\documentclass{article}
\usepackage{amsthm}
\usepackage{hyperref}

\theoremstyle{plain}
\newtheorem{theorem}{Theorem}[section]
\theoremstyle{definition}
\newtheorem{examplex}[theorem]{Example}
\newtheorem*{continuedex}{Example \continuedexref\space Continued}
\newtheorem*{example*}{Example}

\newenvironment{examcont}[1]
  {\newcommand{\continuedexref}{\ref*{#1}}\continuedex}
  {\endcontinuedex}

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

\begin{document}
\section{Foo}
\begin{example}
\label{exa:foo}
  A numbered example.
\end{example}
\begin{examcont}{exa:foo}
  An example continued.
\end{examcont}
\begin{example*}
  An unnumbered example.
\end{example*}
\end{document}

This uses i) this answer to add an end mark to the example environment and ii) this answer to allow for for continued examples.

Currently I only have the end triangle mark for the standard example environment. I want to have the end mark for both the continued example and the star (unnumbered) example. How can I achieve this?

enter image description here

petobens
  • 3,306

1 Answers1

4

The symbol must be inserted at the end of the environment, 'flushed' right, so use \hfill\myqedsymbol where \myqedsymbol is a macro wrapper for the particular symbol (\triangle in this case)

\documentclass{article}

\usepackage{amsthm}
\usepackage{hyperref}

\theoremstyle{plain}
\newtheorem{theorem}{Theorem}[section]
\theoremstyle{definition}
\newtheorem{examplex}[theorem]{Example}
\newtheorem*{continuedex}{Example \continuedexref\space Continued}
\newtheorem*{example*}{Example}

\newcommand{\myqedsymbol}{\ensuremath{\triangle}}%

\newenvironment{examcont}[1]
  {\newcommand{\continuedexref}{\ref*{#1}}\continuedex}
  {\hfill\myqedsymbol\endcontinuedex}

\newenvironment{example}
  {\pushQED{\qed}\renewcommand{\qedsymbol}{\myqedsymbol}\examplex}
  {\popQED\endexamplex}

\begin{document}
\section{Foo}
\begin{example}
\label{exa:foo}
  A numbered example.
\end{example}
\begin{examcont}{exa:foo}
  An example continued.
\end{examcont}
\begin{example*}
  An unnumbered example.
\end{example*}
\end{document}

enter image description here

Version with qed mark for unnumbered example

The problem arises from the starred environment, so it's best to rename example* and define the example* as a wrapper environment:

\documentclass{article}
\usepackage{amsthm}
\usepackage{hyperref}

\theoremstyle{plain}
\newtheorem{theorem}{Theorem}[section]
\theoremstyle{definition}
\newtheorem{examplex}[theorem]{Example}
\newtheorem*{continuedex}{Example \continuedexref\space Continued}
\newtheorem*{examplestarred}{Example}

\newcommand{\myqedsymbol}{\ensuremath{\triangle}}%

\newenvironment{examcont}[1]{%
  \pushQED{\qed}%
  \renewcommand{\qedsymbol}{\myqedsymbol}%
  \newcommand{\continuedexref}{\ref*{#1}}%
  \continuedex%
}{%
  \popQED%
  \endcontinuedex%
}%


\newenvironment{example}{%
  \pushQED{\qed}%
  \renewcommand{\qedsymbol}{\myqedsymbol}%
  \examplex%
}{%
  \popQED%
  \endexamplex%
}%


\newenvironment{example*}{%
  \pushQED{\qed}%
  \renewcommand{\qedsymbol}{\myqedsymbol}%
  \examplestarred%
}{%
  \popQED%
  \endexamplestarred%
}%

\begin{document}
\section{Foo}
\begin{example}
\label{exa:foo}
  A numbered example.
\end{example}
\begin{examcont}{exa:foo}
  An example continued.
\end{examcont}
\begin{example*}
  An unnumbered example.
\end{example*}
\end{document}

enter image description here

  • Thanks. Do I need to load the extra ragged2e package? – petobens Oct 08 '14 at 20:40
  • @petobens: No, sorry, that was my first guess-- I will remove it –  Oct 08 '14 at 20:44
  • The unnumbered example doesn't have an end mark. – Bernard Oct 08 '14 at 20:56
  • @Bernard: Correct, I forgot the look after that issue –  Oct 08 '14 at 20:58
  • @Bernard: Corrected the code –  Oct 08 '14 at 22:08
  • Why does the numbered example and the unnumbered example end the environment definition with \popQED\endexample.. while the continued example ends with \hfill\myqedsymbol? And why isn't \pushQED.. used in the continued example definition? – petobens Oct 09 '14 at 02:47
  • @petobens: Well, basically the whole pushQED stuff is not needed in my point of view, since the redefinition of the \qedsymbol occurs inside of a group, so it's safe outside. However, since the theorem environment is responsible for the typesetting, it is better to call the \pushQED...\popQED commands. –  Oct 09 '14 at 04:02
  • @petobens: I updated the code -- all three environments use the \pushQED...\popQED macros now –  Oct 09 '14 at 04:16
  • @ChristianHupfer -- what the \pushQED ... code does is enable the environment to work with amsmath to use \qedhere to move the qed symbol up to the end of a display math line; otherwise the symbol would invariably end up on a separate line, and possibly break to a new page. – barbara beeton Oct 09 '14 at 18:07
  • @barbarabeeton: Thanks, I have not digged too deep into amsmath package, but after your explanation, I am glad, that I kept those macros ;-) –  Oct 09 '14 at 18:16
  • @petobens: You're welcome ;-) –  Oct 09 '14 at 19:00