7

My proofs often look like this:

\documentclass{article}
\usepackage{mathtools}
\begin{document}
    \begin{align}
        &\text{First Statement}\\
        &\implies \text{Second Statement}\\
        &\stackrel{\text{Explanation}}{\implies}\text{Third Statement}\\
        &\stackrel{\mathclap{\text{Explanation}}}{\implies} \text{Fourth Statement}
    \end{align}
\end{document}

Compiled

And the issue is that the alignment takes into account the entire stackrel, while I want it to algin with the implication arrow. I tried \stackrel{Explanation}{&\implies} but that throws an error. \mathclap works, if the explanation is not too long and doesn't touch the statement after the implication arrow.

Do you have any suggestions how to solve this problem?

Felix B.
  • 387
  • Can you add a full compilable code, please? For example I have not understood your question. – Sebastiano Dec 29 '18 at 13:22
  • @Sebastiano like this? – Felix B. Dec 29 '18 at 13:27
  • 1
    i see no reason that using a \phantom won't work. for the first statement, use the \phantom with the whole content of the \stackrel with the longest text. for the second, use the \phantom for just the top element of the \stackrel. some adjustment will be necessary if two "printed" explanations" have different widths. i can't test this now since i don't have tex installed on my laptop. – barbara beeton Dec 30 '18 at 00:25
  • https://tex.stackexchange.com/a/414223/148164 aligned-overset is the best answer – Felix B. Mar 16 '23 at 13:31

3 Answers3

6

The \stackrel command is defined as

#1#2 → \mathrel{\mathop{#2}\limits^{#1}}

so you could use \smashoperator from the mathtools package to get rid of the space introduced by the left half of the superscript. I'm defining \smashstackrel below, a version of \stackrel that incorporates \smashoperator. I think \smashstackrel[l] does precisely what you want. I also defined \feliximplies{<text>} to make life simpler.

\documentclass{article}

\usepackage{mathtools}

\newcommand*\smashstackrel[3][lr]{%
  \mathrel{\smashoperator[#1]{\mathop{#3}^{#2}}}
}

\newcommand*\feliximplies[1]{\smashstackrel[l]{\textnormal{#1}}{\implies}}

\begin{document}

\begin{align}
    &\text{First Statement}\\
    &\implies \text{Second Statement}\\
    &\smashstackrel[l]{\text{Explanation}}{\implies}\text{Third Statement}\\
    &\feliximplies{Explanation} \text{Fourth Statement}
\end{align}

\end{document}

output


Notes:

  • The optional argument of \smashstackrel can be either [l], [r] or [lr] depending on whether you want to ignore the left side or the right side or both sides of the superscript for spacing purposes.

  • \implies is defined as \DOTSB\;\Longrightarrow\; and \; produces a space that can be stretched (but not shrunk, by default). This space will no longer be stretchable if \stackrel (or \smashstackrel) is used, so doing so feels slightly dubious. I think something like

    \;\mkern-\thickmuskip\stackrel{<text>}{\implies}\;\mkern-\thickmuskip
    

    might be more appropriate than just \stackrel{<text>}{implies}. This reinserts precisely the amount of stretchability that was lost. (The same remark applies to \smashstackrel and \noLstackrel, which is defined below.)

    In this case it doesn't matter though, since here the space won't be stretched anyway. It would matter if this command were used inline rather than in a display environment.

    Brief explanation: \; is defined as \mskip\thickmuskip and inserts a horizontal space of length \thickmuskip, which by default is 5mu but can be stretched to 10mu if necessary. \mkern is similar to \mskip, but it doesn't allow for stretching. So \mkern-\thickmuskip removes a horizontal space of 5mu in this case so that we end up with a horizontal space of 0mu that can be stretched to up to 5mu. See this answer for more information on spacing commands.

  • A possible disadvantage of\smashstackrel compared to \stackrel is that it always typesets things in \displaystyle. I've included a version of \smashstackrel[l] that doesn't do this below because I had already written it before I suddenly remembered the existence of \smashoperator.

    \makeatletter %% <- make @ usable in command names
    \newcommand*\noLstackrel[2]{\mathpalette\noLstackrel@{{#1}{#2}}}
    \newcommand*\noLstackrel@[2]{\noLstackrel@@{#1}#2}
    \newcommand*\noLstackrel@@[3]{% #1 = \displaystyle etc., #2 = top, #3 = bottom
      \begingroup                           %% <- limit scope of boxes
        \sbox0{$\m@th#1\stackrel{#2}{#3}$}% %% <- put stackrel construction in box 0
        \sbox2{$\m@th#1#3$}%                %% <- put base symbol in box 2
        \hskip.5\wd2 \hskip-.5\wd0          %% <- remove excess width on the left
        \mathrel{\usebox0}%                 %% <- print box 0
      \endgroup
    }
    \makeatother  %% <- revert @
    

    Usage: \noLstackrel{<stuff on top>}{\implies}.

Circumscribe
  • 10,856
  • Excellent your work and the same of @caverac. – Sebastiano Dec 30 '18 at 10:16
  • The second note is a bit hard to read because you only define the command you refer to, in the third note. Probably because you have rewritten the answer? Otherwise excellent answer. Do you think it would be a good idea to redefine \implies in a way that it allows \implies^{Explanation}? – Felix B. Dec 30 '18 at 11:23
  • 1
    @FelixB. Oops, that is indeed what happened. What you suggest sounds like a neat idea, but it seems like it'd be a bit finicky to implement if you want \implies to still be treated as a relation (rather than an operator) for spacing purposes and even more so if you want the left side to be "smashed" as above. Because \mathop{\Longrightarrow} does neither of these things, you would have to use something like \@ifnextchar to look ahead for an explicit ^ . – Circumscribe Dec 30 '18 at 11:55
  • If you say it might be finicky I probably better leave my hands off of it. Still trying to wrap my head around what all the commands in the second note do. And I haven't really understood the third comment (I think I know that the problem is that it treats sums limits different in \(\) than \[\] but I don't understand the solution) Wouldn't using \limits like in the original \stackrel solve this problem? – Felix B. Dec 30 '18 at 11:58
  • 1
    I've added a brief explanation to second remark. It only really matters for inline ($…$) equations though, since I don't think spaces in display environments are really ever stretched. – Circumscribe Dec 30 '18 at 12:18
  • The "problem" with \smashoperator is that it doesn't decrease the size of the operator if it is used in e.g. a superscript. You can test this out by typesetting e.g. $A^{\smashoperator{\sum^a}}$. This likely won't be an issue for you, so you probably shouldn't use this version. (I generally dislike including code written by others in my documents if I don't understand it and don't need it.) – Circumscribe Dec 30 '18 at 12:27
  • ("this version" refers to the one defined in the third comment.) – Circumscribe Dec 30 '18 at 12:39
2

Reading the documentation on mathtools after learning about \smashoperators from Circumscribes answer, I found another possible solution: \xRightarrow

\documentclass{article}
\usepackage{mathtools}
\begin{document}
    \begin{align}
        &\text{Statement}\\
        &\implies \text{implies arrow}\\
        &\xRightarrow{\text{Explanation}}\text{xRightarrow}\\
        &\xRightarrow{(*)} \text{xRightarrow}\\
        &\;\xRightarrow{(*)}\; \text{xRightarrow with ;}\\
        &\implies \text{implies arrow}\\
        &\;\xRightarrow{}\; \text{xRightarrow with ;}\\
        &\;\Rightarrow\; \text{Rightarrow with ;}
    \end{align}
\end{document}

Resulting in:

Result

The advantage of this solution is, that it utilizes a command from a known package, which probably has less errors than a home cooked solution. And it allows for underscript too. The disadvantage is probably clear from the picture. \implies inserts a space before the arrow, which xRightarrow does not do. (EDIT: this can be fixed with \; at the sides as Circumscribes points out but it is still noticeable that xRightarrow is based on Rightarrow, as you can see from the default length when there is no input)

So instead of \implies you would probably have to use \Rightarrow instead. Secondly I am not sure if I visually prefer different length arrows over explanations which overflow the width of the usual \implies arrow.

Felix B.
  • 387
  • Seems like a good solution. To make the spacing match that of \implies you should use \;\xRightarrow{…}\;, since \implies is effectively the same thing as \;\Longrightarrow\;. – Circumscribe Dec 30 '18 at 14:15
1

You could try eqnarray

\begin{eqnarray}
    && \text{First Statement}\\
    &\implies& \text{Second Statement}\\
    &\stackrel{\text{Explanation}}{\implies}&\text{Third Statement}\\
    &\stackrel{\mathclap{\text{Explanation}}}{\implies}& \text{Fourth Statement}
\end{eqnarray}

enter image description here

caverac
  • 7,931
  • 2
  • 15
  • 31
  • 2
    https://tex.stackexchange.com/questions/196/eqnarray-vs-align judging from the most popular answer that might not be the best idea? – Felix B. Dec 29 '18 at 13:46
  • @FelixB. You are absolutely right! I will leave it here until someone else gives you a better solution – caverac Dec 29 '18 at 14:03