4

I have

\begin{eqnarray*}
\phi(n) = \phi(pq) = & pq - (\# of multiples of p) - (\# of multiples of q) + (\# of multiples of pq) \\
& = & pq - q - p +1 \\
& = & (p-1)(1-1) \\
\end{eqnarray*}

But the last two equations on the RHS are to the far right and not aligned under the first RHS equation.

Also I get "# of multiples of p" all bunched up together .. how do i fix that?

Mico
  • 506,678
Jacob
  • 41
  • 1
    Welcome to TeX.SX! For your second problem: If you want to write text in math mode, wrap it into a \text command, i.e. \text{$\#$ of multiples of $p$}. – moewe Dec 04 '14 at 05:40
  • 2
  • @moewe - Unless the text-mode and math-mode symbols for # are different, it's not necessary to surround the \# particles with $ symbols, right? – Mico Dec 04 '14 at 06:05
  • @Mico Exactly, but I wasn't sure about a difference in the output and would have preferred to see the math-mode # in this context (if there is a difference). – moewe Dec 04 '14 at 06:24

2 Answers2

3

I would use an align* environment instead of an eqnarray* environment; the latter is badly deprecated. In the align environment, a single & symbol is used to mark the alignment point.

To typeset strings of "normal text" in upright-roman rather than math-italic, use the \text macro.

enter image description here

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
\phi(n) = \phi(pq) &= pq - (\text{\# of multiples of $p$}) - 
     (\text{\# of multiples of $q$}) + (\text{\# of multiples of $pq$}) \\
&= pq - q - p +1 \\
&= (p-1)(1-1) 
\end{align*}
\end{document}
Mico
  • 506,678
2

The problem is that you have one & in the first line, but two in the other lines. With eqnarray you need an & on either side of the = for things to align correctly.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{eqnarray*}
\phi(n) = \phi(pq) & = & pq - \text{(\# of multiples of \(p\)) - (\# of multiples of \(q\)) + (\# of multiples of \(pq\))} \\
 & = & pq - q - p +1 \\
 & = & (p-1)(1-1) \\
\end{eqnarray*}
\end{document}

enter image description here

By the way, align is much preferred to eqnarray. See eqnarray vs align for reasons why.

erik
  • 12,673
  • 3
    eqnarray should always have two & the right hand side above is centred as that is supposed to be the middle column with the operator eqnarray is intended to set the right hand slide left aligned. – David Carlisle Dec 04 '14 at 12:41
  • @DavidCarlisle Ah yes, I guess I should have read the link more closely myself. I have updated my answer. Thank you for pointing out my error. – erik Dec 04 '14 at 15:19
  • 1
    +1 for providing an excellent example of why one should not use eqnarray (and, instead, should use align): The first row contains two = symbols, and the amount of whitespace placed around them is wildly different, courtesy of eqnarray's shortcomings... – Mico Dec 04 '14 at 16:31