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 want to centre the formula inside the equals. So far I have

\begin{alignat*}{2}    
v_2(16)&=\frac{2}{5}[v_3(32)+v_3(8)] &&= 0, \\
v_2(4)&=\frac{2}{5}[v_3(8)+v_3(2)] &&= 1.20,\\   
v_2(1)&=\frac{2}{5}[v_3(2)+v_3(0.50)] &&= 3.
\end{alignat*}

Basically I have

 A =BBB = CC

 A =B   = CCCC

but I want

 A = BBB = CC

 A =  B  =CCCC
share|improve this question
    
Hi Joshua, Welcome to TeX.SE! I marked up your code using {}; I also removed the thanks, which is just our policy here- we like to say thanks by upvoting :) It helps keep the site more like a Q&A site- welcome! :) –  cmhughes Mar 16 '13 at 19:17
1  
Do the answers to the following question help you? Align two inequalities –  Hendrik Vogt Mar 16 '13 at 19:46

4 Answers 4

up vote 6 down vote accepted

To have each of the three "columns" centered, you could use the array environment. Note (i) the specification of the = column dividers in the header of the array environment, to ensure math-appropriate spacing, and (ii) the reset of the \arraystretch parameter to get a look that's appropriate for a group of displayed equations.

\documentclass{article}
\begin{document}
\renewcommand\arraystretch{1.33} % default value: 1.0
\[
\begin{array}{c @{{}={}} c @{{}={}} c}
v_2(16) & \frac{2}{5}[v_3(32)+v_3(8)]    & 0, \\
v_2(4)  & \frac{2}{5}[v_3(8) +v_3(2)]    & 1.20,\\   
v_2(1 ) & \frac{2}{5}[v_3(2) +v_3(0.50)] & 3.
\end{array}
\]
\end{document}

enter image description here

If you want to typeset the left-most column flush-right against the first = sign and the right-most column flush-left against the second = sign, you could set {r @{{}={}} c @{{}={}} l} as the array header specification.


Rather than center-set the middle portions of the equations, I would actually recommend maintaining the alignat* environment while adding a further alignment point, at the + sign. I'd also use \tfrac rather than frac:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{alignat*}{3}    
v_2(16)&=\tfrac{2}{5}[v_3(32) &&+v_3(8)]    &&= 0, \\
v_2(4) &=\tfrac{2}{5}[v_3(8)  &&+v_3(2)]    &&= 1.20,\\   
v_2(1) &=\tfrac{2}{5}[v_3(2)  &&+v_3(0.50)] &&= 3.
\end{alignat*}
\end{document}

enter image description here

share|improve this answer

If you type

\documentclass{amsart}

\newlength\wantedwidth
\newcommand{\fakewidth}[2]{%
  \settowidth{\wantedwidth}{\ensuremath{#2}}%
  \makebox[\wantedwidth]{\ensuremath{#1}}%
}

\begin{document}
\begin{alignat*}{2}    
  v_2(16)&=\fakewidth{\frac{2}{5}[v_3(32)+v_3(8)]}
                    {\frac{2}{5}[v_3(2)+v_3(0.50)]}
                    &&= \fakewidth{0,}{1.20} \\
  v_2(4)&=\fakewidth{\frac{2}{5}[v_3(8)+v_3(2)]}
                    {\frac{2}{5}[v_3(2)+v_3(0.50)]} 
                    &&= 1.20,\\   
  v_2(1)&=\fakewidth{\frac{2}{5}[v_3(2)+v_3(0.50)]}
                    {\frac{2}{5}[v_3(2)+v_3(0.50)]}
                    &&= \fakewidth{3.}{1.20}
\end{alignat*}

\end{document}

then you'll get

enter image description here

share|improve this answer
    
@Mico: Oops, yes; I just corrected that. –  Phil Hirschhorn Mar 16 '13 at 20:22

This is similar to a problem I addressed in this answer. You can do this by inserting some "rubber lengths", i.e. stretchable space, if you override the alignment defaults of the alignat environment. In your case:

\documentclass{article}
\usepackage{amsmath}
\newcommand*\centermathcell[1]{\omit\hfil$\displaystyle#1$\hfil\ignorespaces}
\begin{document}
\begin{alignat*}{2}
  v_2(16) &={}& \centermathcell{\frac{2}{5}[v_3(32)+v_3(8)]}   &= 0, \\
  v_2(4)  &={}& \centermathcell{\frac{2}{5}[v_3(8)+v_3(2)]}    &= 1.20,\\
  v_2(1)  &={}& \centermathcell{\frac{2}{5}[v_3(2)+v_3(0.50)]} &= 3.
\end{alignat*}
\end{document}

enter image description here

The macro \centermathcell (which is descriptively named but which you can of course shorten) uses \omit to remove the default alignment in the current cell, and replaces it with centering. (The \ignorespaces is there to prevent whitespace after \centermathcell from creating spurious gaps in the output.) I've reorganized the columns a bit so that the material which must be centered entirely occupies its own column.

This has the advantage over using the array environment that the behavior of alignat is otherwise preserved, and is less verbose than the \fakewidth idea. It has the disadvantage of going outside the LaTeX typesetting structures and coding paradigm, since \omit is a TeX primitive and you are "not supposed to know" how alignat is implemented (in this case, as an \halign of some sort).

share|improve this answer

This seems to be more complicated than suitable for the align environments. You can use generic array here:

\documentclass{article}
\begin{document}
\[%
\begin{array}{r@{\,}l@{\,}c@{\,}l@{\,}l}
A&=&BBB&=&CC\\
A&=&B&=&CCCC
\end{array}
\]
\end{document}
share|improve this answer

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.