3

I am typesetting some mathematical equations using \begin{align*} environment. Hopefully to make the steps clear I am adding text above =, \leq, \geq but I am having troubles with aligning them e.g.:

\begin{align*}
x_1 + x_2
\overset{\text{some text}}=& 2y^3 \leq\\
\overset{\text{some longer text}}\leq& 3z
\end{align*}

The result is, that the \leq is not centered with = sign above. Is there a neat way to solve this? In some different cases I am using this approach:

\begin{align*}
x_1 + x_2
\overset{\text{some text}}=& 2y^3 \leq\\
\overset{\phantom{\text{some text}}}\leq& 3z
\end{align*}

But I don't think that adding some phantom characters to the first example would be a good way how to do it.

5
  • 2
    Long justifications are better placed on the side.
    – egreg
    Commented Apr 23, 2014 at 8:40
  • 2
    I agree with @egreg writing on top of relations etc is considered bad style in writing, and should be reformulated instead. Some of this may be fine on a blackboard, but not in print. Also remember \intertext{...} and its cousin \shortintertext{...} from mathtools
    – daleif
    Commented Apr 23, 2014 at 8:48
  • Thanks, I'll try to figure it out differently, maybe discuss it with professor for whom I write it. But sometimes it is something like from def 3.11(ii) in my language "only" z def 3.11(ii), so I might stick to it form time to time. But I guess "long justification" can stand for two and more characters sometimes.
    – quapka
    Commented Apr 23, 2014 at 9:06
  • Possible duplicates: Center a column in align and overset text over equal sign in in an Align environment Commented Apr 23, 2014 at 9:29
  • @quapka: I've just added 2 solutions to the answers in tex.stackexchange.com/questions/70365/center-a-column-in-align They allow for the use of the alignenvironment.
    – Bernard
    Commented Apr 23, 2014 at 16:32

2 Answers 2

5

This solution proposes use of makebox where adjustment of width is possible for one's need.

enter image description here

Code

\documentclass[12pt]{article}
\usepackage[margin=1cm,paper size={10cm,10cm}]{geometry}
\usepackage{amsmath,amssymb}
\thispagestyle{empty}
\begin{document}

{\bf OP:}

\begin{align*}
x_1 + x_2
\overset{\text{some text}}=& 2y^3 \leq\\
\overset{\text{some longer text}}\leq& 3z
\end{align*}


{\bf Use of makebox:}

\begin{align*}
x_1 + x_2
\makebox[3cm][c]{$\overset{\text{some text}} = $}              &2y^3 \leq\\
\makebox[3cm][c]{$\overset{\text{some longe text}} \leq$}  &   3z
\end{align*}

\end{document}
4
  • I had started with makebox but I was getting lots of errors so I gave up :-( I now see it was simple: I was missing the $ inside the makebox. I like this solution myself. I am going to upvote it!
    – FionaSmith
    Commented Apr 23, 2014 at 10:06
  • @FionaSmith -- I was thinking of array, but your OP mentioned that and that forced me to think what else ...
    – Jesse
    Commented Apr 23, 2014 at 10:36
  • How to create a box with the same width of an other box? Instead of hardcoding the 3cm I'd like to do something like: \makebox[\getWidthOf{\overset{\text{some long text}}\leq}][x]{$\overset{\text{some text}}\leq$} to have the symbol with the shorter text take exactly the same space as the symbol with the longer text (and nothing more).
    – Bakuriu
    Commented May 4, 2014 at 15:35
  • @Bakuriu -- Please check here tex.stackexchange.com/q/18576/34618. If this does not help, then you need to ask a new question since this is closed, not available of posting any.
    – Jesse
    Commented May 4, 2014 at 16:30
2

I am not sure this is quite what you want, but you could use a tabular environment:

\begin{tabular}{r c l}
$x_1 + x_2$ & $ \overset{\text{some text}}=           $ & $2y^3 \leq$ \\
            & $ \overset{\text{some longer text}}\leq $ & $3z$
\end{tabular}

You then get them centred one above the other, but there is extra space around the = in the first line.

Or, as egreg suggests, array

$
\begin{array}{@{}r@{}>{{}}c<{{}}@{}l@{}}
x_1 + x_2 & \overset{\text{some text}}=            & 2y^3 \leq \\
            &  \overset{\text{some longer text}}\leq  & 3z
\end{array}
$
5
  • Well although this would done the job It does not seem like a good solution for almost "two times a page" use. Still thanks, but I'll probably go with @egreg advice. But I might use it in some cases.
    – quapka
    Commented Apr 23, 2014 at 9:02
  • Since this is math, an array would be better, with \begin{array}{@{}r@{}>{{}}c<{{}}@{}l@{}} (requires also the array package).
    – egreg
    Commented Apr 23, 2014 at 9:04
  • maybe what you want is something like dcases - see en.wikibooks.org/wiki/LaTeX/Advanced_Mathematics ?
    – FionaSmith
    Commented Apr 23, 2014 at 9:06
  • @egreg I have added an example. I've not used array before and in the example I was looking at I was very confused by the whole string of @{}r@{} etc and didn't want to spend time looking it up! Since you provided the correct code, I've updated my example above.
    – FionaSmith
    Commented Apr 23, 2014 at 9:11
  • With @{} we remove the intercolumn space; the >{{}}c<{{}} construction adds empty atoms around the relation symbols in the c column so the spacing will be correct.
    – egreg
    Commented Apr 23, 2014 at 9:13

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