3

Is it possible to use the align environment (or something similar) to typeset something like the following (nonesense) example with correct spacing?

  |a - c|
< |a - b| + |b - c|

What I want: The first line should be aligned to everything in the second (and consecutive lines) right from the <. I tried things like

\begin{align*}
    &  |a - c|\\
    & < |a - b| + |b - c| 
\end{align*}

or

\begin{align*}
    &  |a - c|\\
    < & |a - b| + |b - c| 
\end{align*}

but in the first example, the first line isn't aligned, and in the second example, the < is too close to the first | in the second line.

Using something like \phantom{<} in the first line, i.e.

\begin{align*}
    & \phantom{<} |a - c|\\
    & < |a - b| + |b - c| 
\end{align*}

didn't align the first line correctly, either. I'm probably overlooking a really obvious solution here, but I can't think of one myself and don't really know what to search for.

EDIT:

MWE:

\documentclass{minimal}
\usepackage{amsmath}

\begin{document}
\begin{align*}
  & |a-c| \\
  & < |a-b| + |b-c|
\end{align*}

\begin{align*}
  & |a-c| \\
  < & |a-b| + |b-c|
\end{align*}

\begin{align*}
    & \phantom{<} |a - c|\\
    & < |a - b| + |b - c| 
\end{align*}

What I want: 

\begin{align*}
    & \phantom{ {}<{}} |a - c|\\
    & < |a - b| + |b - c| 
\end{align*}
\end{document}

The indicated align* is what I want (i.e. the last one), which is cmhughes' solution. Is there a way to do this without the \phantom (meaning a more flexible solution), or do you have to do it like this?

3
  • Try to put the \phantom{<} in the first column in both lines. If you provide a MWE to immediately test, you trigger peoples »Want To See This« button, and you get an answer much faster.
    – Johannes_B
    Sep 8, 2014 at 16:57
  • 2
    < is a binary operator - try \phantom{ {}<{}} in your second experiment; it might get you closer :)
    – cmhughes
    Sep 8, 2014 at 16:59
  • Thanks cmhughes, that's the behaviour I want, but I'd like a less "manual" solution (so no manual control of the spaces, if possible) which works for other operators than <, as well.
    – Lustique
    Sep 8, 2014 at 17:20

3 Answers 3

4

if the space you want after the < is the same as you'd get if everything were on one line, then simply putting {} between the < and the & is sufficient:

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\begin{align*}
      &  |a - c| \\
  <{} &  |a - b| + |b - c| 
\end{align*}

\[ |a - c| <  |a - b| + |b - c| \]

\end{document}

output of example code

4
  • Could you briefly explain why a simple {} solved my problem? Isn't < the same as <{}? In a normal math environment the behaviour seems to be the same, at least considering spacing.
    – Lustique
    Sep 8, 2014 at 17:29
  • 1
    in order to get the "correct" spacing, the operator needs to be followed directly by another printable (or parseable) element. when it's separated from that element by '&', the necessary connection can no longer be made. the {} restores the condition. that's why amsmath documentation insists that the & must precede the operator. (of course, if you know what you're doing, you can ignore the instructions, because you know how to compensate.) Sep 8, 2014 at 17:34
  • So a use of align like in my example just isn't intended? I thought something like what I wanted to do would be quite useful, or is this considered to be bad mathematical typesetting? (I, of course, wanted to use the above construction for longer and more complicated estimations, so I actually need more than one line)
    – Lustique
    Sep 8, 2014 at 17:53
  • well, it's certainly not how align is usually applied (or originally conceived), but if there is a good mathematical reason for the "anomalous" usage, then i can't see any reason why you shouldn't apply it. Sep 8, 2014 at 18:04
1

You can write code as shown below

\documentclass{article}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{booktabs}
\begin{document}
\begin{align*}
      &  |a - c|\\
  < \quad  &  |a - b| + |b - c| 
\end{align*}

\end{document}

alignment

1

Here's two ways using an alternative approach... TABstacks.

\documentclass{article}
\usepackage{tabstackengine}
\stackMath
\begin{document}
\[
\setstackgap{S}{5pt}
\tabbedShortstack[l]{
   &  |a - c|\\
    < & |a - b| + |b - c| 
}
\]
or
\[
\renewcommand\stackalignment{l}
\tabbedstackunder[5pt]{&  |a - c|}{< & |a - b| + |b - c| }
\]
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .