Text FormattingQED on the last line of the center environment containing a TikZ drawing

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
user49915
Posts: 81
Joined: Wed Apr 17, 2019 12:51 pm

QED on the last line of the center environment containing a TikZ drawing

Post by user49915 »

Running pdflatex on the input

Code: Select all

\documentclass{svmono}% v5.6 from https://www.springer.com/gp/authors-editors/book-authors-editors/resources-guidelines/rights-permissions-licensing/manuscript-preparation/5636, dated 23 April 2019. If you use "book" instead, define the environment "example" yourself.
\usepackage{newtxtext}
\usepackage[slantedGreek]{newtxmath}%% Should be loaded after the text font according to its manual. The default uppercase Greek letter
\usepackage{lipsum}
\usepackage{tikz}\usetikzlibrary{calc,shapes,positioning}
\usepackage{mathtools}\mathtoolsset{mathic=true} %%% See http://tex.stackexchange.com/a/3496/
\newcommand*{\mathQEDendingNonProofSymbol}{\Box}%%% Alternatives: \square, \boxempty
\newcommand*{\textQEDendingNonProofSymbol}{\(\mathQEDendingNonProofSymbol\)}%%% Alternatives: \square, \boxempty
\makeatletter
\newcommand*{\textQEDendingNonProof}{{\unskip\nobreak\hfil\penalty50\hskip1em\null\nobreak\hfil\textQEDendingNonProofSymbol\parfillskip=\z@\finalhyphendemerits=0\endgraf}}
\makeatother
\newcommand*{\qedEndingNonProofAfterTikzCenter}{\nopagebreak\par\nopagebreak\vspace{-1.57\baselineskip}\nopagebreak\textQEDendingNonProof}%%% -1.57\baselineskip is a wild guess; it is subject to change depending on the font used
\begin{document}
\begin{example}
  \lipsum[1][1-2]
\begin{center}
  \begin{tikzpicture}[atomicNode/.style={ellipse,draw,inner sep=.3ex,minimum width=3em},startNode/.style={circle,inner sep=.2ex,fill},startText/.style={inner sep=.15ex}]
    \node (MThreeText) {\(M_3\):};
    \node[startText,below=1ex of MThreeText] (MThreeStartText) {\(x\coloneqq 2\)};
    \node[startNode,anchor=north] (MThreeStart) at (MThreeStartText.south) {};
    \node[atomicNode] (MThreeSOne) at ($(MThreeStart.south east)+(3em,-4ex)$) {\(S_1\)};
    \node[atomicNode,right=5em of MThreeSOne] (MThreeSTwo) {\(S_2\)};
    \draw[-latex] (MThreeStart) -- (MThreeSOne);
    \draw[-latex] (MThreeSOne) to[bend left]node[above,pos=.55]{\(\{\mathit{odd}(x)\}\,x\coloneqq 2\)} (MThreeSTwo);
  \end{tikzpicture}
\end{center}%
\qedEndingNonProofAfterTikzCenter%
\end{example}
\end{document}
produces the output
output
output
screenshot.png (43.54 KiB) Viewed 6932 times
In this example, the qed symbol (square) should be placed on the base line of the TikZ drawing (which can be arbitrarily complicated) and flushed to the right.
My current solution involves finishing the `center` environment, introducing a wildly guessed negative vertical space, putting the box, and continuing from there on. This is fragile: wild guesses break when the general parameters such as the font or the baselineskip change. Instead, we should undo the vertical skip(s) introduced by `\endcenter` in a font-independent way (which boils down to undoing the vertical skip(s) introduced by `\endtrivlist`), put the QED symbol, and redo the vertical skip(s). However, the definition of `\endtrivlist` is a bit too complicated for me to understand. I imagine that `trivlist` is a very standard thing, so, someone has probably already done the job. Any help?

An aside is worth being made. Marginnote-based solutions to place the qed symbol are of second choice, since the package is abandoned and does lead to problems with a large book. Marginpar/marginline sometimes requires manual vertical adjustments, i.e., a no-go for automation. Using `amsthm` or `ntheorem` is also a no-go: `amsthm` clashes with `svmono` in various ways, and `ntheorem` has bugs (e.g., doesn't jive with UTF-8 engines and has other problems, see https://tex.stackexchange.com/questions/tagged/ntheorem) and is both antique and abandoned. The inclusion of `ntheorem` with some options into `svmono.cls` is, in fact, so far from a clever design that I had to turn off `ntheorem` manually. (If you have problems with getting `svmono.cls` for the purpose of trying this very example out, go with the `book` class instead and define `example` via `\newtheorem`).
Last edited by user49915 on Fri Jun 07, 2019 11:30 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

thomasb
Posts: 134
Joined: Thu Aug 03, 2017 10:54 am

QED on the last line of the center environment containing a TikZ drawing

Post by thomasb »

You are going to say that you don't like it :

Code: Select all

\begin{proof} 
(...) 
\end{proof}
?
user49915
Posts: 81
Joined: Wed Apr 17, 2019 12:51 pm

QED on the last line of the center environment containing a TikZ drawing

Post by user49915 »

thomasb wrote:You are going to say that you don't like it
No. I'm going to say that what you typed is unrelated to my question.
thomasb
Posts: 134
Joined: Thu Aug 03, 2017 10:54 am

QED on the last line of the center environment containing a TikZ drawing

Post by thomasb »

user49915 wrote:No. I'm going to say that what you typed is unrelated to my question.
Well, I'm not sure I understood the question then ! You need the QED not to go another line ?
user49915
Posts: 81
Joined: Wed Apr 17, 2019 12:51 pm

QED on the last line of the center environment containing a TikZ drawing

Post by user49915 »

thomasb wrote:You need the QED not to go another line ?
Yes. But replacing "example" with "proof" leads to "Proof" instead of "Example" in the output.
thomasb
Posts: 134
Joined: Thu Aug 03, 2017 10:54 am

QED on the last line of the center environment containing a TikZ drawing

Post by thomasb »

user49915 wrote:Yes. But replacing "example" with "proof" leads to "Proof" instead of "Example" in the output.
It seems you can define your own environments : http://distrib-coffee.ipsl.jussieu.fr/p ... heorem.pdf
user49915
Posts: 81
Joined: Wed Apr 17, 2019 12:51 pm

QED on the last line of the center environment containing a TikZ drawing

Post by user49915 »

thomasb wrote:It seems you can define your own environments : http://distrib-coffee.ipsl.jussieu.fr/p ... heorem.pdf
`ntheorem` has bugs and is unmaintained. I think I wrote a note about it in the question.
thomasb
Posts: 134
Joined: Thu Aug 03, 2017 10:54 am

QED on the last line of the center environment containing a TikZ drawing

Post by thomasb »

user49915 wrote: `ntheorem` has bugs and is unmaintained. I think I wrote a note about it in the question.
Indeed...
rais
Posts: 419
Joined: Sun Nov 16, 2014 8:51 pm

QED on the last line of the center environment containing a TikZ drawing

Post by rais »

I didn't understand the benefit of putting a `proof' symbol into an example environment; all that even for a Springer class, which I find highly unusual to be tinkered with.
Anyway, my idea would be to put everything but the qed symbol into a {minipage}, align it to the bottom, and put the qed symbol next to it, e.g.,

Code: Select all

\documentclass{svmono}% v5.6 from <!-- m --><a class="postlink" href="https://www.springer.com/gp/authors-editors/book-authors-editors/resources-guidelines/rights-permissions-licensing/manuscript-preparation/5636">https://www.springer.com/gp/authors-edi ... ation/5636</a><!-- m -->, dated 23 April 2019. If you use "book" instead, define the environment "example" yourself.
\usepackage{newtxtext}
\usepackage[slantedGreek]{newtxmath}%% Should be loaded after the text font according to its manual. The default uppercase Greek letter
\usepackage{lipsum}
\usepackage{showframe}%<-- only for orientation
\usepackage{tikz}\usetikzlibrary{calc,shapes,positioning}
\usepackage{mathtools}\mathtoolsset{mathic=true} %%% See <!-- m --><a class="postlink" href="http://tex.stackexchange.com/a/3496/">http://tex.stackexchange.com/a/3496/</a><!-- m -->
\newcommand*{\mathQEDendingNonProofSymbol}{\Box}%%% Alternatives: \square, \boxempty
\newcommand*{\QEDendingNonProofSymbol}{%
  \ensuremath{\mathQEDendingNonProofSymbol}%
}% actually, this way it could be called \textormathQEDendingNonProofSymbol
\newlength\QEDSymbolSpace
\begin{document}
\begin{example}
  \lipsum[1][1-2]
\begin{center}
  \settowidth\QEDSymbolSpace{\QEDendingNonProofSymbol}%
  \hspace{\QEDSymbolSpace}%
  \begin{minipage}[b]{\dimexpr\linewidth-2\QEDSymbolSpace}
    \centering
    \begin{tikzpicture}[atomicNode/.style={ellipse,draw,inner sep=.3ex,minimum width=3em},startNode/.style={circle,inner sep=.2ex,fill},startText/.style={inner sep=.15ex}]
      \node (MThreeText) {\(M_3\):};
      \node[startText,below=1ex of MThreeText] (MThreeStartText) {\(x\coloneqq 2\)};
      \node[startNode,anchor=north] (MThreeStart) at (MThreeStartText.south) {};
      \node[atomicNode] (MThreeSOne) at ($(MThreeStart.south east)+(3em,-4ex)$) {\(S_1\)};
      \node[atomicNode,right=5em of MThreeSOne] (MThreeSTwo) {\(S_2\)};
      \draw[-latex] (MThreeStart) -- (MThreeSOne);
      \draw[-latex] (MThreeSOne) to[bend left]node[above,pos=.55]{\(\{\mathit{odd}(x)\}\,x\coloneqq 2\)} (MThreeSTwo);
    \end{tikzpicture}
  \end{minipage}\QEDendingNonProofSymbol
\end{center}%
\end{example}
\end{document}
is that less troublesome for you?

KR
Rainer
thomasb
Posts: 134
Joined: Thu Aug 03, 2017 10:54 am

QED on the last line of the center environment containing a TikZ drawing

Post by thomasb »

Wow ! What about \hfill\QEDendingNonProofSymbol at the end ?
Post Reply