9

I'm struggling with aligning my equations and provide a number for them. I googled but haven't found a solution for the array environment. I tried the align env. but only with the array env. I managed to get the result I was looking for. Now I want to label the two conversation equations at the end of the line (preferably vertically centered).

\documentclass[12pt,a4paper]{scrartcl}
\usepackage{amsmath}
\usepackage{amssymb,amsthm}
\begin{document}
\begin{equation}
\begin{array}{lrcl}
\textbf{Conservation of energy}     & E_{kin}               &=& E'_{kin}                \\
                & m_1 v_1^2 + m_2 v_2^2         &=& m_1 {v'}_{1}^{2} + m_2 {v'}_{2}^{2} \\
                & m_1 (v_1^2 - {v'}_1^2)        &=& m_2 ({v'}_2^2 - v_2^2)      \\
                & m_1 (v_1 + {v'}_1) (v_1 - {v'}_1)     &=& m_2 ({v'}_2 + v_2) ({v'}_2 - v_2)   \\
\\

\textbf{Conservation of momentum}   & p                 &=& p' \\
                & m_1 v_1 + m_2 v_2             &=& m_1 {v'}_1 + m_2 {v'}_2\\
                & m_1 (v_1 - {v'}_1)            &=& m_2 ({v'}_2 - v_2)\\
\end{array}
\end{equation}
\end{document}

To make it clearer: I want the black number to be gone and the red numbers to appear:

Screenshot with added numbers

  • No \begin{equation} ? It seems there are many problems in the posted code – Majid Abdolshah Sep 12 '16 at 7:55
  • Whoops, that went missing when I edited it here. What other problems do you see? – infinitezero Sep 12 '16 at 7:56
  • It is ok now. I had some problems for compiling. Now it is fixed. Thanks. – Majid Abdolshah Sep 12 '16 at 7:58
  • 1
    the array environment is for arrays and matrices etc, it is not at all designed for typesetting full equations, the spacing is wrong for that and the entries are in textstyle not displaystyle which is why your images look so cramped. You should use align or aligned from the amsmath package. – David Carlisle Sep 12 '16 at 7:58
  • 1
    align is designed to number each row, it is better to use split or aligned or gathered which are designed to number the equation as a whole. – David Carlisle Sep 12 '16 at 8:10
10

enter image description here

amsmath has several environments designed to number each row, or as here number the group as a whole. Do not use array for such display constructs the spacing and style are not designed for that.

\documentclass[12pt,a4paper]{scrartcl}
\usepackage{amsmath}
\usepackage{amssymb,amsthm}
\begin{document}

\textbf{Conservation of energy}
\begin{equation}
\begin{split}
  E_{\mathrm{kin}}                  &= E'_{\mathrm{kin}}                   \\
  m_1 v_1^2 + m_2 v_2^2             &= m_1 {v'}_{1}^{2} + m_2 {v'}_{2}^{2} \\
  m_1 (v_1^2 - {v'}_1^2)            &= m_2 ({v'}_2^2 - v_2^2)              \\
  m_1 (v_1 + {v'}_1) (v_1 - {v'}_1) &= m_2 ({v'}_2 + v_2) ({v'}_2 - v_2) 
\end{split}
\end{equation}

\textbf{Conservation of momentum}  
\begin{equation}
\begin{split}
  p                  &= p'                      \\
  m_1 v_1 + m_2 v_2  &= m_1 {v'}_1 + m_2 {v'}_2 \\
  m_1 (v_1 - {v'}_1) &= m_2 ({v'}_2 - v_2)
\end{split}
\end{equation}


\end{document}
  • @infinitezero Oh! Aligning bot parts on the ='s was unnecessary? If I only know... – Przemysław Scherwentke Sep 12 '16 at 8:19
  • 2
    @PrzemysławScherwentke do what feels right not what the OP asks for:-) – David Carlisle Sep 12 '16 at 8:25
  • Yeah it was necessary but this solution covers it. – infinitezero Sep 12 '16 at 8:25
  • @infinitezero just updated with fixed markup for kin (never use math italic for words, it is designed to make consecutive letters look like a product of variables, not a word) – David Carlisle Sep 12 '16 at 8:28
  • 1
    @infinitezero here the = in each block are aligned but each block is centred so there is no actual alignment between the first and second equation environments, but there is no reason to have alignment there so that's OK:-) – David Carlisle Sep 12 '16 at 8:39
3

You could do it this way:

\documentclass[12pt,a4paper]{scrartcl}
\usepackage{amsmath}
\usepackage{amssymb,amsthm}
\begin{document}
\begin{align}
  & \textbf{Conservation of energy} 
   & E_{kin}                          &= E'_{kin}                         \notag\\
  && m_1 v_1^2 + m_2 v_2^2            &= m_1 {v'}_{1}^{2} + m_2 {v'}_{2}^{2}    \\
  && m_1 (v_1^2 - {v'}_1^2)           &= m_2 ({v'}_2^2 - v_2^2)           \notag\\
  && m_1 (v_1 + {v'}_1) (v_1 - {v'}_1)&= m_2 ({v'}_2 + v_2) ({v'}_2 - v_2)\notag\\[2ex]
  & \textbf{Conservation of momentum}
   & p                                &= p'                               \notag\\
  && m_1 v_1 + m_2 v_2                &= m_1 {v'}_1 + m_2 {v'}_2                \\
  && m_1 (v_1 - {v'}_1)               &= m_2 ({v'}_2 - v_2)               \notag
\end{align}
\end{document}

enter image description here

  • This is almost perfect! Now if there was a way to get the (1) between the 2nd and 3rd line, it'd be the icing on the cake. :) – infinitezero Sep 12 '16 at 8:05
  • Remove an equation to get an odd number of lines. Form before content. :-) – gernot Sep 12 '16 at 8:09
3

You can use alignedat, but some manual work is needed for sharing the column widths across the two parts; we identify the widest columns in the global alignment and set three dimensions before doing the display.

\documentclass[12pt,a4paper]{scrartcl}
\usepackage{amsmath,mathtools,amssymb,amsthm}

\usepackage{lipsum} % just for the example

\newlength{\izA}\newlength{\izB}\newlength{\izC}
\newcommand{\mmb}[3]{\mathmakebox[#1][#2]{\displaystyle#3}}

\begin{document}

\lipsum*[2]
%%% settings for the display
\settowidth{\izA}{\textbf{Conservation of momentum}}%
\settowidth{\izB}{$\displaystyle m_1 (v_1 + {v'}_1) (v_1 - {v'}_1)$}%
\settowidth{\izC}{$\displaystyle m_2 ({v'}_2 + v_2) ({v'}_2 - v_2)$}%
%%%
\begin{gather}
\begin{alignedat}{2}
&\mmb{\izA}{l}{\textbf{Conservation of energy}}
   & \mmb{\izB}{r}{E_{\mathrm{kin}}}   &= \mmb{\izC}{l}{E'_{\mathrm{kin}}}    \\
  && m_1 v_1^2 + m_2 v_2^2             &= m_1 {v'}_{1}^{2} + m_2 {v'}_{2}^{2} \\
  && m_1 (v_1^2 - {v'}_1^2)            &= m_2 ({v'}_2^2 - v_2^2)              \\
  && m_1 (v_1 + {v'}_1) (v_1 - {v'}_1) &= m_2 ({v'}_2 + v_2) ({v'}_2 - v_2)
\end{alignedat}
\\
\begin{alignedat}{2}
&\textbf{Conservation of momentum}
   & \mmb{\izB}{r}{p}                  &= \mmb{\izC}{l}{p'}                   \\
  && m_1 v_1 + m_2 v_2                 &= m_1 {v'}_1 + m_2 {v'}_2             \\
  && m_1 (v_1 - {v'}_1)                &= m_2 ({v'}_2 - v_2)
\end{alignedat}
\end{gather}
\lipsum[3]

\end{document}

enter image description here

Alternative solution with split, so we need less measuring.

\documentclass[12pt,a4paper]{scrartcl}
\usepackage{amsmath,mathtools,amssymb,amsthm}

\usepackage{lipsum} % just for the example

\newlength{\lefthandside}
\newcommand{\leftbox}[2][]{%
  \makebox[\lefthandside][s]{#1\hfill$\displaystyle#2$}%
}

\begin{document}

\lipsum*[2]
%%% settings for the display
\settowidth{\lefthandside}{%
  \textbf{Conservation of momentum}%
  \quad
  $\displaystyle m_1 (v_1 + {v'}_1) (v_1 - {v'}_1)$%
}%
%%%
\begin{align}
\begin{split}
\leftbox[\textbf{Conservation of energy}]
  {E_{\mathrm{kin}}}                        &= E'_{\mathrm{kin}} \\
\leftbox{m_1 v_1^2 + m_2 v_2^2}             &= m_1 {v'}_{1}^{2} + m_2 {v'}_{2}^{2} \\
\leftbox{m_1 (v_1^2 - {v'}_1^2)}            &= m_2 ({v'}_2^2 - v_2^2)              \\
\leftbox{m_1 (v_1 + {v'}_1) (v_1 - {v'}_1)} &= m_2 ({v'}_2 + v_2) ({v'}_2 - v_2)
\end{split}
\\
\begin{split}
\leftbox[\textbf{Conservation of momentum}]
  {p}                                       &= p'                   \\
\leftbox{m_1 v_1 + m_2 v_2}                 &= m_1 {v'}_1 + m_2 {v'}_2             \\
\leftbox{m_1 (v_1 - {v'}_1)}                &= m_2 ({v'}_2 - v_2)
\end{split}
\end{align}
\lipsum[3]

\end{document}

enter image description here

2

If some manual work is allowed, the following solution gives the desired effect:

\documentclass[12pt,a4paper]{scrartcl}
\usepackage{amsmath}
\usepackage{amssymb,amsthm}
\begin{document}


\newlength{\comom} 
\settowidth{\comom}{\textbf{Conservation of momentum}}
\newlength{\rfour}
\settowidth{\rfour}{$m_1 (v_1 + {v'}_1) (v_1 - {v'}_1)   $}
\begin{eqnarray}
%\begin{array}{lrcl}
\begin{array}{p{\comom}rcl}
\textbf{Conservation of energy}     & E_{kin}               &=& E'_{kin}                \\
                & m_1 v_1^2 + m_2 v_2^2         &=& m_1 {v'}_{1}^{2} + m_2 {v'}_{2}^{2} \\
                & m_1 (v_1^2 - {v'}_1^2)        &=& m_2 ({v'}_2^2 - v_2^2)      \\
                & m_1 (v_1 + {v'}_1) (v_1 - {v'}_1)     &=& m_2 ({v'}_2 + v_2) ({v'}_2 - v_2)   
 \end{array}               
\\
\begin{array}{p{\comom}rcl}
\textbf{Conservation of momentum}   & \makebox[\rfour][r]{$p               $}  &=& \makebox[\rfour][l]{$p'$} \\
                & m_1 v_1 + m_2 v_2             &=& m_1 {v'}_1 + m_2 {v'}_2\\
                & m_1 (v_1 - {v'}_1)            &=& m_2 ({v'}_2 - v_2)\\
\end{array}
\end{eqnarray}
\end{document}

enter image description here

There are better solutions, but they need, e.g., some familiarity with amsmath package.

  • Hey, this is also a good answer, however I prefer the easier solution above :-) – infinitezero Sep 12 '16 at 8:27
2

If you want the titles to be aligned with the leftmargin, here are two solutions, based on the \shortintertext command from mathtoolsand on the flalign environment. Each has two variants, according to whether the groups of = signs are aligned or not. The variants also differ in the placement of the equation numbers:

\documentclass[12pt,a4paper]{scrartcl}
\usepackage{mathtools}
\usepackage{amssymb,amsthm}
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.2pt}

\begin{document}

\begin{align}
  \shortintertext{\bfseries Conservation of energy}
  E_\mathrm{kin}    & = E'_\mathrm{kin}                         \notag \\
  m_1 v_1^2 + m_2 v_2^2       & = m_1 {v'}_{1}^{2} + m_2 {v'}_{2}^{2}            \\
  m_1 (v_1^2 - {v'}_1^2)       & = m_2 ({v'}_2^2 - v_2^2)           \notag        \\
  m_1 (v_1 + {v'}_1) (v_1 - {v'}_1) & = m_2 ({v'}_2 + v_2) ({v'}_2 - v_2)\notag        \\[2ex]
  \shortintertext{\bfseries Conservation of momentum}
  p     & = p'                               \notag        \\
  m_1 v_1 + m_2 v_2     & = m_1 {v'}_1 + m_2 {v'}_2                        \\
  m_1 (v_1 - {v'}_1)      & = m_2 ({v'}_2 - v_2)               \notag
\end{align}
\vspace{1cm}
\begin{flalign}
  & \textbf{Conservation \rlap{of energy}}
  & E_\mathrm{kin}      &= E'_\mathrm{kin}             &  &              \notag\\
  && m_1 v_1^2 + m_2 v_2^2     &= m_1 {v'}_{1}^{2} + m_2 {v'}_{2}^{2} \raisetag{1cm}   \\
  && m_1 (v_1^2 - {v'}_1^2)      &= m_2 ({v'}_2^2 - v_2^2)           \notag\\
  && m_1 (v_1 + {v'}_1) (v_1 - {v'}_1)&= m_2 ({v'}_2 + v_2) ({v'}_2 - v_2)\notag\\[2ex]
  & \textbf{Conservation \rlap{of momentum}}
  & p   &= p'                               \notag\\
  && m_1 v_1 + m_2 v_2  &= m_1 {v'}_1 + m_2 {v'}_2                \\
  && m_1 (v_1 - {v'}_1)  &= m_2 ({v'}_2 - v_2)               \notag
\end{flalign}
\newpage
\begin{gather}
  \shortintertext{\bfseries Conservation of energy}
  \begin{aligned}
    E_\mathrm{kin}  & = E'_\mathrm{kin}                     \\
    m_1 v_1^2 + m_2 v_2^2     & = m_1 {v'}_{1}^{2} + m_2 {v'}_{2}^{2} \\
    m_1 (v_1^2 - {v'}_1^2)      & = m_2 ({v'}_2^2 - v_2^2)              \\
    m_1 (v_1 + {v'}_1) (v_1 - {v'}_1) & = m_2 ({v'}_2 + v_2) ({v'}_2 - v_2)
  \end{aligned}\\[2ex]
  \shortintertext{\bfseries Conservation of momentum}
  \begin{aligned}
    p   & = p'                      \\
    m_1 v_1 + m_2 v_2  & = m_1 {v'}_1 + m_2 {v'}_2 \\
    m_1 (v_1 - {v'}_1) & = m_2 ({v'}_2 - v_2)
  \end{aligned}
\end{gather}
\vspace{1cm}

\begin{flalign}
  & \textbf{Conservation of energy }
  &  & \begin{aligned}[t]
  E_\mathrm{kin}    &= E'_\mathrm{kin}                \\
  m_1 v_1^2 + m_2 v_2^2      &= m_1 {v'}_{1}^{2} + m_2 {v'}_{2}^{2}    \\
  m_1 (v_1^2 - {v'}_1^2)     &= m_2 ({v'}_2^2 - v_2^2)    \\
  m_1 (v_1 + {v'}_1) (v_1 - {v'}_1)&= m_2 ({v'}_2 + v_2) ({v'}_2 - v_2)
  \end{aligned}
  &  &
  \\[2ex]
  & \textbf{Conservation of  momentum}
  & &  \begin{aligned}[t]
  p     &= p'          \\
  m_1 v_1 + m_2 v_2   &= m_1 {v'}_1 + m_2 {v'}_2                \\
  m_1 (v_1 - {v'}_1)   &= m_2 ({v'}_2 - v_2)
  \end{aligned}
  &  &
\end{flalign}

\end{document}

enter image description here

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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