Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

This question already has an answer here:

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.

share|improve this question

marked as duplicate by Heiko Oberdiek, percusse, Svend Tveskæg, Guido, Peter Jansson Apr 23 at 11:14

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2  
Long justifications are better placed on the side. –  egreg Apr 23 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 Apr 23 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 Apr 23 at 9:06
    
    
@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 Apr 23 at 16:32

2 Answers 2

up vote 3 down vote accepted

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}
share|improve this answer
    
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 Apr 23 at 10:06
    
@FionaSmith -- I was thinking of array, but your OP mentioned that and that forced me to think what else ... –  Jesse Apr 23 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 May 4 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 May 4 at 16:30

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}
$
share|improve this answer
    
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 Apr 23 at 9:02
    
Since this is math, an array would be better, with \begin{array}{@{}r@{}>{{}}c<{{}}@{}l@{}} (requires also the array package). –  egreg Apr 23 at 9:04
    
maybe what you want is something like dcases - see en.wikibooks.org/wiki/LaTeX/Advanced_Mathematics ? –  FionaSmith Apr 23 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 Apr 23 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 Apr 23 at 9:13

Not the answer you're looking for? Browse other questions tagged or ask your own question.