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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to write the following equation in such a way that right align is possible. That is all right most elements are in same column. Here left align is done.

\begin{eqnarray*}
y_{0}&= &(r_{73} + 1)r_{9} + ((r_{73} + 1)r_{93} + r_{73} + 1)r_{108} + ((r_{73} + 1)r_{93} + r_{73} + 1)r_{110} + ((r_{73} + 1)r_{93} + \\
      &  &r_{73} + 1)r_{98} + ((r_{73} + 1)r_{93} + (r_{73} + r_{93})r_{115} + r_{73} +1)r_{123} + ((r_{73} + 1)r_{93} + (r_{73} + r_{93})\\
      &  &r_{115} + r_{73} + 1)r_{85} + ((r_{73} + 1)r_{93} + (r_{73} + r_{93})r_{115} + ((r_{68} + 1)r_{73} + ((r_{68} + 1)r_{73} + r_{68} \\
      &  & + 1)r_{93} +((r_{73} + 1)r_{93} + r_{73} + 1)r_{110} + ((r_{68} + 1)r_{73} + (r_{68} + 1)r_{93} + (r_{73} + r_{93})r_{110})r_{115} \\
      &  &+ r_{68} + 1)r_{131} +r_{73} + 1)r_{88} + ((r_{68} + 1)r_{73} + ((r_{68} + 1)r_{73} + r_{68} + 1)r_{93} + ((r_{68}r_{73} + r_{68})\\
      &  &r_{93} + r_{68}r_{73} +r_{68})r_{110} + ((r_{68} + 1)r_{73} + (r_{68} + 1)r_{93} + (r_{68}r_{73} + r_{68}r_{93})r_{110})r_{115} + \\
      &  &r_{68} + 1)r_{131} + (r_{15} + r_{36} +r_{48} + r_{6} + r_{61} + r_{7})r_{73} + ((r_{73} + r_{93})r_{108} + (r_{73} + r_{93})r_{110} \\
      &  &+ (r_{73} + r_{93})r_{98} + (r_{15} +r_{36} + r_{48} + r_{6} + r_{61} + r_{7})r_{73} + (r_{15} + r_{36} + r_{48} + r_{6} + r_{61} \\
      &  &+ r_{7} + r_{9})r_{93} + r_{73}r_{9} + 1)r_{115} +((r_{73} + 1)r_{9} + (r_{15} + r_{36} + r_{48} + r_{6} + r_{61} + r_{7})r_{73}  \\
      &  &+ r_{15} + r_{36} + r_{48} + r_{6} + r_{61} + r_{7} + 1)r_{93} +r_{103} + r_{11} + r_{113} + r_{12} + r_{128} + r_{14} + r_{15} \\
      &  &+ r_{20} + r_{36} + r_{41} + r_{48} + r_{53} + r_{6} + r_{61} + r_{66}+ r_{7} + r_{90}\\ 
\end{eqnarray*}
share|improve this question
6  
Avoid eqnarray! – qubyte Jan 6 '12 at 16:13
    
possible duplicate of How can I split an equation over two lines – lockstep Jan 6 '12 at 18:58
up vote 3 down vote accepted

I would also recommend that you use the align environment, but would recommend that you:

  • not break lines when you are in brackets if possible
  • in the cases where it is necessary to break within a brackets to somehow visually indicate that. Here I have used a slightly larger bracket, but perhaps an even larger bracket or a square bracket would be better to allow for easily finding the matching brackets. I have also added extra indentation when this is the case

enter image description here

Notes:

  • You parenthesis are not balanced. I have a comment in the code to indicate where and have left that as is.
  • The [showframe] option of the geometry package was used to show where the margins are. So, the code fits within the default width of the article class. This might need to be adjusted based on your text width dimentions.

Code:

\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{amsmath}

\begin{document}
\begin{align*}
y_{0}
&= (r_{73} + 1)r_{9} 
+ ((r_{73} + 1)r_{93} + r_{73} + 1)r_{108} 
+ ((r_{73} + 1)r_{93} + r_{73} + 1)r_{110}\\
&\quad+ ((r_{73} + 1)r_{93} + r_{73} + 1)r_{98}
+ ((r_{73} + 1)r_{93} + (r_{73} + r_{93})r_{115} + r_{73} +1)r_{123}\\
&\quad+ ((r_{73} + 1)r_{93} + (r_{73} + r_{93})r_{115} + r_{73} + 1)r_{85}\\
% This is a long expression
&\quad+ \big((r_{73} + 1)r_{93} + (r_{73} + r_{93})r_{115} + ((r_{68} + 1)r_{73} 
 + ((r_{68} + 1)r_{73} + r_{68}+ 1)r_{93} \\
&\quad\qquad+((r_{73} + 1)r_{93} + r_{73} + 1)r_{110} + ((r_{68} + 1)r_{73} + (r_{68} + 1)r_{93} + (r_{73} + r_{93})r_{110})r_{115}\\
&\quad\qquad+ r_{68} + 1)r_{131}
+r_{73} + 1\big)r_{88} \\
% -------------------------------------
&\quad+ ((r_{68} + 1)r_{73} % Not sure where this opening ( is supposed to close
+ ((r_{68} + 1)r_{73} + r_{68} + 1)r_{93} \\
% Another long expression:
&\quad+ \big((r_{68}r_{73} + r_{68}
r_{93} + r_{68}r_{73} +r_{68})r_{110} + ((r_{68} + 1)r_{73} + (r_{68} + 1)r_{93} \\
&\quad\qquad+ (r_{68}r_{73} + r_{68}r_{93})r_{110})r_{115} + r_{68} + 1 \big)r_{131}\\
% ----------------------
&\quad+ (r_{15} + r_{36} +r_{48} + r_{6} + r_{61} + r_{7})r_{73} \\
%
% Another long expression:
&\quad+ \big((r_{73} + r_{93})r_{108} + (r_{73} + r_{93})r_{110}
+ (r_{73} + r_{93})r_{98} + (r_{15} +r_{36} + r_{48} + r_{6} + r_{61} + r_{7})r_{73} \\
&\quad\qquad+ (r_{15} + r_{36} + r_{48} + r_{6} + r_{61} + r_{7} + r_{9})r_{93} \\
&\quad\qquad+ r_{73}r_{9} + 1\big)r_{115} \\
% -----------------------------------------------
% Another long expression:
&\quad+ \big((r_{73} + 1)r_{9} 
+ (r_{15} + r_{36} + r_{48} + r_{6} + r_{61} + r_{7})r_{73}
+ r_{15} + r_{36} + r_{48} + r_{6} + r_{61} + r_{7} + 1\big)r_{93}\\
% -----------------------------------------------
% Rest are single terms so we can break them anywhere
&\quad+r_{103} + r_{11} + r_{113} + r_{12} + r_{128} + r_{14} + r_{15}
+ r_{20} + r_{36} + r_{41} + r_{48} + r_{53} + r_{6} + r_{61} + r_{66}\\
&\quad+ r_{7} + r_{90}
\end{align*}
\end{document}
share|improve this answer

Use align from the amsmath package:

\documentclass{minimal}
\usepackage{amsmath}

\begin{document}
\begin{align*}
y_{0}=(r_{73} + 1)r_{9} + ((r_{73} + 1)r_{93} + r_{73} + 1)r_{108} + ((r_{73} + 1)r_{93} + r_{73} + 1)r_{110} + ((r_{73} + 1)r_{93}& + \\
      r_{73} + 1)r_{98} + ((r_{73} + 1)r_{93} + (r_{73} + r_{93})r_{115} + r_{73} +1)r_{123} + ((r_{73} + 1)r_{93} + (r_{73} + r_{93})&\\
      r_{115} + r_{73} + 1)r_{85} + ((r_{73} + 1)r_{93} + (r_{73} + r_{93})r_{115} + ((r_{68} + 1)r_{73} + ((r_{68} + 1)r_{73} + r_{68} &\\
       + 1)r_{93} +((r_{73} + 1)r_{93} + r_{73} + 1)r_{110} + ((r_{68} + 1)r_{73} + (r_{68} + 1)r_{93} + (r_{73} + r_{93})r_{110})r_{115} &\\
      + r_{68} + 1)r_{131} +r_{73} + 1)r_{88} + ((r_{68} + 1)r_{73} + ((r_{68} + 1)r_{73} + r_{68} + 1)r_{93} + ((r_{68}r_{73} + r_{68})&\\
      r_{93} + r_{68}r_{73} +r_{68})r_{110} + ((r_{68} + 1)r_{73} + (r_{68} + 1)r_{93} + (r_{68}r_{73} + r_{68}r_{93})r_{110})r_{115}& + \\
      r_{68} + 1)r_{131} + (r_{15} + r_{36} +r_{48} + r_{6} + r_{61} + r_{7})r_{73} + ((r_{73} + r_{93})r_{108} + (r_{73} + r_{93})r_{110} &\\
      + (r_{73} + r_{93})r_{98} + (r_{15} +r_{36} + r_{48} + r_{6} + r_{61} + r_{7})r_{73} + (r_{15} + r_{36} + r_{48} + r_{6} + r_{61} &\\
      + r_{7} + r_{9})r_{93} + r_{73}r_{9} + 1)r_{115} +((r_{73} + 1)r_{9} + (r_{15} + r_{36} + r_{48} + r_{6} + r_{61} + r_{7})r_{73}  &\\
      + r_{15} + r_{36} + r_{48} + r_{6} + r_{61} + r_{7} + 1)r_{93} +r_{103} + r_{11} + r_{113} + r_{12} + r_{128} + r_{14} + r_{15} &\\
      + r_{20} + r_{36} + r_{41} + r_{48} + r_{53} + r_{6} + r_{61} + r_{66}+ r_{7} + r_{90}&
\end{align*}
\end{document}

If you want everything to be right up against the margins, just replace eqnarray with flalign, also from amsmath:

\documentclass{minimal}
\usepackage{amsmath}

\begin{document}
\begin{flalign*}
y_{0}=&& (r_{73} + 1)r_{9} + ((r_{73} + 1)r_{93} + r_{73} + 1)r_{108} + ((r_{73} + 1)r_{93} + r_{73} + 1)r_{110} + ((r_{73} + 1)r_{93} &+ \\
      &  &r_{73} + 1)r_{98} + ((r_{73} + 1)r_{93} + (r_{73} + r_{93})r_{115} + r_{73} +1)r_{123} + ((r_{73} + 1)r_{93} + (r_{73} + r_{93})\\
      &  &r_{115} + r_{73} + 1)r_{85} + ((r_{73} + 1)r_{93} + (r_{73} + r_{93})r_{115} + ((r_{68} + 1)r_{73} + ((r_{68} + 1)r_{73} + r_{68} \\
      &  & + 1)r_{93} +((r_{73} + 1)r_{93} + r_{73} + 1)r_{110} + ((r_{68} + 1)r_{73} + (r_{68} + 1)r_{93} + (r_{73} + r_{93})r_{110})r_{115} \\
      &  &+ r_{68} + 1)r_{131} +r_{73} + 1)r_{88} + ((r_{68} + 1)r_{73} + ((r_{68} + 1)r_{73} + r_{68} + 1)r_{93} + ((r_{68}r_{73} + r_{68})\\
      &  &r_{93} + r_{68}r_{73} +r_{68})r_{110} + ((r_{68} + 1)r_{73} + (r_{68} + 1)r_{93} + (r_{68}r_{73} + r_{68}r_{93})r_{110})r_{115} &+ \\
      &  &r_{68} + 1)r_{131} + (r_{15} + r_{36} +r_{48} + r_{6} + r_{61} + r_{7})r_{73} + ((r_{73} + r_{93})r_{108} + (r_{73} + r_{93})r_{110} \\
      &  &+ (r_{73} + r_{93})r_{98} + (r_{15} +r_{36} + r_{48} + r_{6} + r_{61} + r_{7})r_{73} + (r_{15} + r_{36} + r_{48} + r_{6} + r_{61} \\
      &  &+ r_{7} + r_{9})r_{93} + r_{73}r_{9} + 1)r_{115} +((r_{73} + 1)r_{9} + (r_{15} + r_{36} + r_{48} + r_{6} + r_{61} + r_{7})r_{73}  \\
      &  &+ r_{15} + r_{36} + r_{48} + r_{6} + r_{61} + r_{7} + 1)r_{93} +r_{103} + r_{11} + r_{113} + r_{12} + r_{128} + r_{14} + r_{15} \\
      &  &+ r_{20} + r_{36} + r_{41} + r_{48} + r_{53} + r_{6} + r_{61} + r_{66}+ r_{7} + r_{90}\\ 
\end{flalign*}
\end{document}
share|improve this answer

Without too much manual intervention (I just replaced +1 with \plusone in order to avoid the worst breaks):

\documentclass{article}
\usepackage{amsmath}

\usepackage{lipsum}

\newenvironment{verylongequation}[1]
 {\begin{equation}\setupverylongequation{#1}}
 {\stopverylongequation\end{equation}}
\newenvironment{verylongequation*}[1]
 {\begin{equation*}\setupverylongequation{#1}}
 {\stopverylongequation\end{equation*}}

\makeatletter

\newcommand{\plusone}{+\nobreak 1}
\newcommand{\setupverylongequation}[1]{%
  \begin{minipage}{.8\linewidth}
  \medmuskip=1\medmuskip % no stretching or shrinking
  \raggedright
  \settowidth{\dimen@}{$#1={}$}%
  \setlength{\leftskip}{\dimen@}%
  \setlength{\parindent}{-\dimen@}%
  $#1=
}
\newcommand{\stopverylongequation}{$\end{minipage}}
\makeatother

\begin{document}

\lipsum*[2]
\begin{verylongequation*}{y_{0}}
(r_{73} \plusone)r_{9} + ((r_{73} \plusone)r_{93} + r_{73} \plusone)r_{108} + ((r_{73} \plusone)r_{93} 
+ r_{73} \plusone)r_{110} + ((r_{73} \plusone)r_{93} + r_{73} \plusone)r_{98} + ((r_{73} 
\plusone)r_{93} + (r_{73} + r_{93})r_{115} + r_{73} \plusone)r_{123} + ((r_{73} \plusone)r_{93} + (r_{73} + 
r_{93}) r_{115} + r_{73} \plusone)r_{85} + ((r_{73} \plusone)r_{93} + (r_{73} + r_{93})r_{115} + ((r_{68} 
\plusone)r_{73} + ((r_{68} \plusone)r_{73} + r_{68} \plusone)r_{93} +((r_{73} \plusone)r_{93} + r_{73} 
\plusone)r_{110} + ((r_{68} \plusone)r_{73} + (r_{68} \plusone)r_{93} + (r_{73} + 
r_{93})r_{110})r_{115} + r_{68} \plusone)r_{131} +r_{73} \plusone)r_{88} + ((r_{68} \plusone)r_{73} + 
((r_{68} \plusone)r_{73} + r_{68} \plusone)r_{93} + ((r_{68}r_{73} + r_{68}) r_{93} + r_{68}r_{73} 
+r_{68})r_{110} + ((r_{68} \plusone)r_{73} + (r_{68} \plusone)r_{93} + (r_{68}r_{73} + 
r_{68}r_{93})r_{110})r_{115} + r_{68} \plusone)r_{131} + (r_{15} + r_{36} +r_{48} + r_{6} + r_{61} + 
r_{7})r_{73} + ((r_{73} + r_{93})r_{108} + (r_{73} + r_{93})r_{110} + (r_{73} + r_{93})r_{98} + (r_{15} 
+r_{36} + r_{48} + r_{6} + r_{61} + r_{7})r_{73} + (r_{15} + r_{36} + r_{48} + r_{6} + r_{61} + r_{7} + 
r_{9})r_{93} + r_{73}r_{9} \plusone)r_{115} +((r_{73} \plusone)r_{9} + (r_{15} + r_{36} + r_{48} + 
r_{6} + r_{61} + r_{7})r_{73} + r_{15} + r_{36} + r_{48} + r_{6} + r_{61} + r_{7} \plusone)r_{93} 
+r_{103} + r_{11} + r_{113} + r_{12} + r_{128} + r_{14} + r_{15} + r_{20} + r_{36} + r_{41} + r_{48} + 
r_{53} + r_{6} + r_{61} + r_{66}+ r_{7} + r_{90}
\end{verylongequation*}

\end{document}

enter image description here

share|improve this answer

Another option: split environment, again from package amsmath, nested into equation*.

Very important the guideline by Peter Grill not to brake lines within brackets (that I only partially followed below). This way, left alignment is achieved.

\documentclass{article}
\usepackage{amsmath}

\begin{document}
\begin{equation*}
\begin{split}
y_{0} & = (r_{73} + 1)r_{9} + ((r_{73} + 1)r_{93} + r_{73} + 1)r_{108} + ((r_{73} + 1)r_{93} + r_{73} + 1)r_{110}\\
& + ((r_{73} + 1)r_{93} + r_{73} + 1)r_{98} + ((r_{73} + 1)r_{93} + (r_{73} + r_{93})r_{115} + r_{73} +1)r_{123}\\
& + ((r_{73} + 1)r_{93} + (r_{73} + r_{93}) r_{115} + r_{73} + 1)r_{85}\\
& + ((r_{73} + 1)r_{93} + (r_{73} + r_{93})r_{115} + ((r_{68} + 1)r_{73} + ((r_{68} + 1)r_{73} + r_{68} + 1)r_{93}\\
& + ((r_{73} + 1)r_{93} + r_{73} + 1)r_{110} + ((r_{68} + 1)r_{73} + (r_{68} + 1)r_{93} + (r_{73} + r_{93})r_{110})r_{115}\\
& + r_{68} + 1)r_{131} +r_{73} + 1)r_{88} + ((r_{68} + 1)r_{73} + ((r_{68} + 1)r_{73} + r_{68} + 1)r_{93}\\
& + ((r_{68}r_{73} + r_{68})r_{93} + r_{68}r_{73} +r_{68})r_{110} + ((r_{68} + 1)r_{73} + (r_{68} + 1)r_{93}\\
& + (r_{68}r_{73} + r_{68}r_{93})r_{110})r_{115} + r_{68} + 1)r_{131} + (r_{15} + r_{36} +r_{48} + r_{6} + r_{61} + r_{7})r_{73}\\
& + ((r_{73} + r_{93})r_{108} + (r_{73} + r_{93})r_{110} + (r_{73} + r_{93})r_{98}\\
& + (r_{15} +r_{36} + r_{48} + r_{6} + r_{61} + r_{7})r_{73} + (r_{15} + r_{36} + r_{48} + r_{6} + r_{61} + r_{7} + r_{9})r_{93}\\
& + r_{73}r_{9} + 1)r_{115} +((r_{73} + 1)r_{9} + (r_{15} + r_{36} + r_{48} + r_{6} + r_{61} + r_{7})r_{73}\\
& + r_{15} + r_{36} + r_{48} + r_{6} + r_{61} + r_{7} + 1)r_{93} +r_{103} + r_{11} + r_{113} + r_{12} + r_{128} + r_{14}\\
& + r_{15} + r_{20} + r_{36} + r_{41} + r_{48} + r_{53} + r_{6} + r_{61} + r_{66}+ r_{7} + r_{90}
\end{split}
\end{equation*}
\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.