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.

I have the following type of code in my document:

\begin{align*}
       (-m)+m & \stackrel{\mathrm{Ax 1.1 (i)}}{=}  m+(-m)\\
  &\stackrel{\mathrm{Ax 1.4}}{=}  0 \\

I want to align on the = but that is complicated by the fact that there is something hovering over it.

It would seem to be easier to align their centers (no matter what, that is where the = will be).

How can I center a column in align (or align* to be honest, I am not that clear on the difference)

share|improve this question
1  
I currently don't have access to latex, but maybe adding the \mathclap{} command to the stuff you put over the '=' helps? You can find it in the mathtools package –  Jakob van Bethlehem Sep 6 '12 at 6:53

3 Answers 3

up vote 7 down vote accepted

Since you don't need to number each row, use an array:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation*}
\begin{array}{@{}r@{{}\mathrel{}}c@{\mathrel{}{}}l@{}}
(-m)+m & \overset{\text{Ax 1.1 (i)}}{=} & m+(-m)\\
       & \overset{\text{Ax 1.4}}{=}     & 0
\end{array}
\end{equation*}
\end{document}

Notice that \overset is preferable to \stackrel and that \text will preserve spaces. Between the first and the second column I put the space normally used for a relation symbol (produced by {}\mathrel{}) and similarly for the other intercolumn space. If you want that the text is upright whatever is the context the formula is in (perhaps embedded in something in italics), use \textup instead of \text.

Here's the result:

enter image description here

However, this seems not particularly legible; usually I prefer setting the justification on the right:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
(-m)+m &= m+(-m) && \text{by Ax 1.1 (i)} \\
       &= 0  && \text{by Ax 1.4}
\end{align*}
\end{document}

enter image description here

share|improve this answer
    
actually, even with \overset, in this case \text is as good as \textrm, and maybe better, as it is designed to work in math. like \textrm it observes spaces and produces the correct size. (it does require amsmath.) –  barbara beeton Sep 6 '12 at 12:50
    
@barbarabeeton Thanks, I changed the answer accordingly. –  egreg Sep 6 '12 at 12:57
    
I still would not write too much like that, I think it is much more readable to add something like this into the text. I have some lectures here how do something like the above for almost every larger calculation. Very annoying to read, and not something that encourage the student to understand the steps in the calculation. –  daleif Sep 6 '12 at 13:17

One can still use the align environment,. in two ways:

  • For a casual use, the makebox package introduces a \makebox* command that takes two arguments: the first one is the text that defines the width of the box that contains the second argument. I used it to define an \oversetto with 3 arguments, the first (optional) defining the width of the \overset box.
  • A more systematic use requires the eqparbox package: its \eqmakebox command has the same arguments as \makebox (unstarred), plus a 3rd (optional) argument which is a tag. All \eqparboxes of the document sharing the same tag will have width equal to that of the widest one.

Here is an example of both ways:

\documentclass[12pt]{article}
\usepackage[margin=1cm]{geometry}
\usepackage{mathtools,amssymb}
\usepackage{eqparbox}
\usepackage{makebox}

\newcommand\textoverset[3][]{\mathrel{\overset{\scriptsize{\eqmakebox[#1]{#2}}}{#3}}}
\newcommand\oversetto[3][]{\overset{\text{\makebox*{#1}{#2}}}{#3}}

\thispagestyle{empty}

\begin{document}

{\bfseries With  \verb+\overset+: }

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

{\bfseries With  \verb+\textoverset+:}

\begin{align*}%over
x_1 + x_2 & \textoverset[O]{some text}{=} 2y³ \leq\\
y_i + y_2 & \textoverset[O]{some longer text}{\leq} 3z
\end{align*}

{\bfseries With  \verb+\oversetto+ :}

\begin{align*}
x_1 + x_2 & \oversetto[Some longer text]{some text}{=}2y³ \leq \\
y_i + y_2 & \overset{\text{some longer text}}{\leq} 3z
\end{align*}

\end{document} 

enter image description here

share|improve this answer

This might be one of those cases where using eqnarray (or eqnarray* if you do not want a numbered equation) might be appropriate (in general eqnarray is deprecated).

\begin{eqnarray*}
  (-m)+m & \stackrel{\mathrm{Ax 1.1 (i)}}{=}&   m+(-m)\\
         & \stackrel{\mathrm{Ax 1.4}}{=}&  0 \\
         & \stackrel{\mathrm{Ax 1.4 (iiii)}}{=}&  0 
\end{eqnarray*} 

Eventually, it is possible to use \mathclap{} from the mathtools package to improve the spacing around =.

\begin{eqnarray*}
  (-m)+m & \stackrel{\mathclap{\mathrm{Ax 1.1 (i)}}}{=}&   m+(-m)\\
         & \stackrel{\mathclap{\mathrm{Ax 1.4}}}{=}&  0
\end{eqnarray*}  

Alternatively it is possible to change the space around = with

\bgroup\arraycolsep=1.4pt
\begin{eqnarray*}
  (-m)+m & \stackrel{\mathrm{Ax 1.1 (i)}}{=}&   m+(-m)\\
         & \stackrel{\mathrm{Ax 1.4}}{=}&  0
\end{eqnarray*}
\egroup
share|improve this answer
    
Please, do not use eqnarray! –  tohecz Sep 6 '12 at 12:51
    
@tohecz if you look at the opening of the answer I wrote that eqnarray is deprecated but under the special circumstances of the question it might be right to use it. –  Guido Sep 6 '12 at 13:23
    
Guido, I know. I only wanted to stress it again: Do not use eqnarray! –  tohecz Sep 6 '12 at 13:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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