4

I couldn't figure out how to do the following alignment:

\begin{equation}
\begin{aligned}
\textrm{Row I:} \qquad & A = 1, \quad j = 1, 2, \ldots, N \\
\textrm{Row II:} \qquad & A = 
\begin{cases}
2, & j = 1, 2, \ldots, m, \\
3, & j = m+1, \ldots, N
\end{cases} \\
\textrm{Row III:} \qquad & A = 4, \quad j = 1, 2, \ldots, N
\end{aligned}
\end{equation}

which gives

equation image

However, I want the equal signs for the 'j's aligned. Any ideas how this might be done? I know it could be done in a tabular environment using a multi-row environment, but the equation spacing would be all off.

5

Identify the widest entry and add the spacings manually; in the rows without cases add \hs and \hp, while only \hs is needed for the entries in cases.

\documentclass{article}
\usepackage{mathtools,calc}
\newcommand{\setwidest}[1]{%
  \renewcommand\widest{\mathmakebox[\widthof{#1}][l]}%
}
\newcommand{\widest}{}
\newcommand{\hp}{\hphantom{\Bigg\lbrace}}
\newcommand{\hs}{\hspace{2\arraycolsep}}

\begin{document}

\begin{equation}
\setwidest{222,}
\begin{aligned}
\textrm{Row I:}  \qquad & A = \widest{1,} \hs\hp  j = 1, 2, \dots, N \\
\textrm{Row II:} \qquad & A = 
\begin{cases}
\widest{222,} \hs j = 1, 2, \ldots, m, \\
\widest{3,} \hs j = m+1, \ldots, N
\end{cases} \\
\textrm{Row III:} \qquad & A = \widest{4,} \hs\hp j = 1, 2, \ldots, N
\end{aligned}
\end{equation}

\begin{equation}
\setwidest{1111111,}
\begin{aligned}
\textrm{Row I:}  \qquad & A = \widest{1111111,} \hs\hp  j = 1, 2, \dots, N \\
\textrm{Row II:} \qquad & A = 
\begin{cases}
\widest{222,}\hs j = 1, 2, \ldots, m, \\
\widest{3,}\hs j = m+1, \ldots, N
\end{cases} \\
\textrm{Row III:} \qquad & A = \widest{4,} \hs\hp j = 1, 2, \ldots, N
\end{aligned}
\end{equation}

\end{document}

enter image description here

2
  • Ah. I think this works for this example, but as soon as the size of the columns change, multiple phantoms might be necessary (e.g. change the "2" case to "222222222") – TSGM Oct 31 '14 at 23:26
  • @TSGM I changed the implementation. Some manual work is needed, though. – egreg Nov 1 '14 at 0:07
5

A solution using alignedat instead of aligned and aligned instead of cases. The alignment is also automatic regardless the width of the boxes and without \hphantoms.

\documentclass{article}
\usepackage{mathtools}
\begin{document}
\begin{equation}
\begin{alignedat}{3}
\textrm{Row I:} \qquad & A = 1,& \quad &j = 1, 2, \ldots, N \\
\textrm{Row II:} \qquad & A = \Bigg\lbrace
\begin{aligned}
2,\\
3333,  
\end{aligned} &
&\!\begin{aligned}
 j &= 1, 2, \ldots, m, \\
 j &= m+1, \ldots, N
\end{aligned}\\
\textrm{Row III:} \qquad & A = 4,& \quad &j = 1, 2, \ldots, N
\end{alignedat}
\end{equation}
\end{document}

enter image description here

or

\begin{aligned}
&2,\\
&3333,  
\end{aligned} &

if you want to align at left

enter image description here

2

A rudimentary implementation using an straight-forward array:

enter image description here

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\centering

-- Original --
\begin{equation}
  \begin{aligned}
    \textrm{Row I:} \qquad & A = 1, \quad j = 1, 2, \ldots, N \\
    \textrm{Row II:} \qquad & A = 
      \begin{cases}
        2, & j = 1, 2, \ldots, m, \\
        3, & j = m + 1, \ldots, N
      \end{cases} \\
    \textrm{Row III:} \qquad & A = 4, \quad j = 1, 2, \ldots, N
  \end{aligned}
\end{equation}

-- \verb|array| implementation --
\begin{equation}
  \renewcommand{\arraystretch}{1.4}
  \begin{array}{r@{\qquad}r@{}l@{\quad}r@{}l}
    \textrm{Row I:} & A & {}= 1, & j & {}= 1, 2, \ldots, N \\
    \textrm{Row II:} & A & {}= \Bigg\{
      \renewcommand{\arraystretch}{1.2}\begin{array}{@{}l@{}} 2, \\ 3, \end{array} & 
      \multicolumn{2}{@{}l@{}}{\renewcommand{\arraystretch}{1.2}\begin{array}{@{}r@{}l}
        j & {}= 1, 2, \ldots, m, \\
        j & {}= m + 1, \ldots, N
      \end{array}} \\
    \textrm{Row III:} & A & = 4, & j & {}= 1, 2, \ldots, N
  \end{array}
\end{equation}

\end{document}

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.