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.

What is the best way to split an overlong formula such as the following one to multiple lines:

\documentclass{scrartcl}
\usepackage{amsmath}

\begin{document}

\begin{eqnarray}
P2‘‘ &=& 
\begin{pmatrix}
(1-\cos \alpha) \times x\times x + \cos \alpha (1-\cos \alpha) \times  x\times  y -\sin \alpha \times  z  (1-\cos \alpha) \times x\times z +\sin \alpha \times  y \\
(1-\cos \alpha) \times  x\times y + \sin \alpha \times  z (1-\cos \alpha) \times y\times y + \cos \alpha  (1-\cos \alpha) \times y\times z - \sin \alpha \times  x  \\
(1-\cos \alpha) \times  x\times z - \sin \alpha \times  y (1-\cos \alpha) \times y\times z + \sin \alpha \times  x  (1-\cos \alpha) \times z\times z + \cos \alpha  
 \end{pmatrix} \\ 
&\times & 
 \begin{pmatrix}
  p2‘_X \\
  p2‘_Y \\
  p2‘_Z
 \end{pmatrix}
\end{eqnarray}

\end{document}

long formula

share|improve this question
    
I recommend using \cdot instead of \times. –  azetina Dec 15 '12 at 16:32
    
Is it a cross product with everything else being vectors? Otherwise the expression is not a valid multiplication. And if it is so, can you split them up into individual steps? –  percusse Dec 15 '12 at 16:44
    
The align environment is the preferred replacement for eqnarray. (Note when you switch that it requires fewer & symbols for alignment.) See tex.stackexchange.com/questions/196/eqnarray-vs-align –  Ethan Bolker Dec 15 '12 at 16:49
1  
get rid of the X for times, use . (or nothing) which will reduce the width of your formula by about 25-50% –  Nicholas Hamilton Dec 15 '12 at 16:52

4 Answers 4

up vote 7 down vote accepted

A variation of barbara's idea, but without the added complications. Just use \hfill in suitable places in order to shove left or right the entry. To one of them I add a fixed space, to give more room. Also some vertical spacings are used to separate each "cell" from the next.

\documentclass{scrartcl}
\usepackage{amsmath}

\begin{document}
\begin{equation}
P2 =
\begin{pmatrix}
  (1-\cos\alpha) \cdot x\cdot x + \cos\alpha (1-\cos\alpha) \cdot x\cdot y \hfill
\hspace{2.5pc} %%% space added to a wide half line, adjust visually
\\
  \hfill{}-\sin\alpha \cdot z (1-\cos\alpha) \cdot x\cdot z +\sin\alpha \cdot y
\\[1ex]
  (1-\cos\alpha) \cdot x\cdot y + \sin\alpha \cdot z (1-\cos\alpha) \cdot y\cdot y \hfill\\
  \hfill{}+ \cos\alpha (1-\cos\alpha) \cdot y\cdot z - \sin\alpha \cdot x
\\[1ex]
  (1-\cos\alpha) \cdot x\cdot z - \sin\alpha \cdot y (1-\cos\alpha) \cdot y\cdot z \hfill\\
  \hfill{}+ \sin\alpha \cdot x (1-\cos\alpha) \cdot z\cdot z + \cos\alpha
\end{pmatrix}
\cdot
\begin{pmatrix}
  p2_X \\[1ex]
  p2_Y \\[1ex]
  p2_Z
\end{pmatrix}
\end{equation}
\end{document}

enter image description here

share|improve this answer
    
this is really much better than mine. i was trying too hard. –  barbara beeton Dec 15 '12 at 18:33

I think this is one of those problems where some local redefinitions could be very useful.

I've defined matrices A and p in the below, and used \cdot instead of \times (assuming that this doesn't change the meaning drastically- if it does, let me know)

screenshot

I've also used align instead of eqnarray as detailed in \eqnarray vs \align

\documentclass{scrartcl}
\usepackage{amsmath}

\begin{document}

We have the matrix equation
\begin{align}
P2'' &= A \cdot  p
\end{align}
where
\[
A=\begin{pmatrix}
(1-\cos \alpha) \cdot x\cdot x + \cos \alpha (1-\cos \alpha) \cdot  x\cdot  y -\sin \alpha \cdot  z  (1-\cos \alpha) \cdot x\cdot z +\sin \alpha \cdot  y \\
(1-\cos \alpha) \cdot  x\cdot y + \sin \alpha \cdot  z (1-\cos \alpha) \cdot y\cdot y + \cos \alpha  (1-\cos \alpha) \cdot y\cdot z - \sin \alpha \cdot  x  \\
(1-\cos \alpha) \cdot  x\cdot z - \sin \alpha \cdot  y (1-\cos \alpha) \cdot y\cdot z + \sin \alpha \cdot  x  (1-\cos \alpha) \cdot z\cdot z + \cos \alpha  
 \end{pmatrix} 
 \]
 and
 \[
 p=\begin{pmatrix}
  p2‘_X \\
  p2‘_Y \\
  p2‘_Z
 \end{pmatrix}
 \]

\end{document}
share|improve this answer
    
+1 Too complicated formulas are simply too complicated. As my fav teacher says: simplify, simplify, simplify. It is much easier to understand couple simple equations than one very complex one. –  tohecz Dec 16 '12 at 0:05
  1. \begin{small}\begin{eqnarray}...\end{eqnarray}\end{small}

  2. read this: Avoid eqnarray! Lars Madsen

share|improve this answer

here's a different approach.

major changes:

  • eqnarray is replaced by align;
  • i've replaced \times by \cdot as suggested by azetina;
  • the multiple lines of the first pmatrix have been packed into a minipage and within the box, multlined from mathtools has been used, with alternate "middle" lines shoved left or right as appropriate;
  • math has to be specified explicitly within the minipage;
  • multlined doesn't seem to want to use the entire specified width of the minipage so some extra space had to be added to the right-adjusted lines; pmatrix doesn't like just a single line (the minipage), so it was replaced with \left( ... \right); minipage width was adjusted by experiment, and a small \vspace added at the top for better appearance.

output of example code

\documentclass{scrartcl}
\usepackage{mathtools}

\begin{document}
\begin{align}
P2 &=
\left(
 {\begin{minipage}{.72\textwidth}
  \vspace{2pt}
  \abovedisplayskip=2pt \abovedisplayshortskip=2pt
  $\begin{multlined}
(1-\cos \alpha) \cdot x\cdot x + \cos \alpha (1-\cos \alpha)\\
 \shoveright{\kern8em
  \cdot  x\cdot  y -\sin \alpha \cdot  z  (1-\cos \alpha)
   \cdot x\cdot z +\sin \alpha \cdot  y } \\
 \shoveleft{
(1-\cos \alpha) \cdot  x\cdot y + \sin \alpha \cdot  z (1-\cos \alpha) } \\
 \shoveright{\kern8em
  \cdot y\cdot y + \cos \alpha  (1-\cos \alpha)
   \cdot y\cdot z - \sin \alpha \cdot  x } \\
 \shoveleft{
(1-\cos \alpha) \cdot  x\cdot z - \sin \alpha \cdot  y (1-\cos \alpha) } \\
  \kern8em
  \cdot y\cdot z + \sin \alpha \cdot  x  (1-\cos \alpha)
   \cdot z\cdot z + \cos \alpha 
  \end{multlined}$
 \end{minipage}}
\right) \\
&\quad\cdot
 \begin{pmatrix}
  p2_X \\
  p2_Y \\
  p2_Z
 \end{pmatrix}
\end{align}

\end{document}
share|improve this answer
    
If you switch the last two terms in each row of the wide matrix then the long term is on a line by itself (rather than split), which makes the algebra much more readable. –  Ethan Bolker Dec 15 '12 at 20:31
    
@EthanBolker -- you're right. that's what egreg has done, and his answer is better in other ways too. –  barbara beeton Dec 15 '12 at 20:34

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.