# Alignment between material inside and outside a cases environment

In the code below, I'd like to make the i=0,\ldots,n. line up, in the output, with the cases in the first part of the definition. Ideally, the full-stop would align with the semicolons and comma.

\documentclass{article}
\usepackage{mathtools}

\begin{document}

\begin{align*}
d_i(g_n,\ldots,g_0) &=
\begin{cases}
(d_0g_ng_{n-1},g_{n-2},\ldots,g_0),& \text{if $i=0$;}\\
(d_ig_n,\ldots,d_1g_{n-i+1},d_0g_{n-i}g_{n-i-1},g_{n-i-2},\ldots,g_0), \\
& \phantom{\text{if $i=0$;}}\llap{\text{if  $i=1,\ldots,n-1$;}} \\
(d_ng_n,\ldots,d_1g_1),& \text{if $i=0$,}
\end{cases}
\intertext{and}
\end{align*}

\end{document}

-

Werner beat me by 56 seconds but an alternative scheme is

\documentclass{article}
\usepackage{mathtools}

\begin{document}

\begin{align*}
d_i(g_n,\ldots,g_0) &=
\begin{cases}
(d_0g_ng_{n-1},g_{n-2},\ldots,g_0),& \text{if $i=0$;}\\
(d_ig_n,\ldots,d_1g_{n-i+1},d_0g_{n-i}g_{n-i-1},g_{n-i-2},\ldots,g_0), \\
& \phantom{\text{if $i=0$;}}\llap{\text{if  $i=1,\ldots,n-1$;}} \\
(d_ng_n,\ldots,d_1g_1),& \text{if $i=0$,}
\end{cases}
\intertext{and}
s_i(g_n,\ldots,g_0) &= (s_ig_n,\ldots,s_0g_{n-i},id_{G_{n-i}},g_{n-i-1},\ldots,g_0),&\llap{$i=0,\ldots,n$.\kern\minalignsep}
\end{align*}

\noindent X\dotfill X
\end{document}

-
+1. Clear looks solution. –  Sigur Jan 30 '13 at 1:38
Thanks. I went with the cleanest implementation. –  David Roberts Jan 30 '13 at 1:44

The following provides what you're after:

\documentclass{article}
\usepackage{mathtools}% http://ctan.org/pkg/mathtools

\begin{document}

\newsavebox{\mathbox}
\savebox{\mathbox}{$\left\{\begin{array}{@{}ll@{}} (d_ig_n,\ldots,d_1g_{n-i+1},d_0g_{n-i}g_{n-i-1},g_{n-i-2},\ldots,g_0), & \text{if$i=0$;} \\ (d_ig_n,\ldots,d_1g_{n-i+1},d_0g_{n-i}g_{n-i-1},g_{n-i-2},\ldots,g_0), & \text{if$i=0$;} \\ (d_ig_n,\ldots,d_1g_{n-i+1},d_0g_{n-i}g_{n-i-1},g_{n-i-2},\ldots,g_0), & \text{if$i=0$;} \end{array}\right.\kern-\nulldelimiterspace$}
\begin{align*}
d_i(g_n,\ldots,g_0) &=
\begin{cases}
(d_0g_ng_{n-1},g_{n-2},\ldots,g_0),& \text{if $i=0$;}\\
(d_ig_n,\ldots,d_1g_{n-i+1},d_0g_{n-i}g_{n-i-1},g_{n-i-2},\ldots,g_0), \\
& \phantom{\text{if $i=0$;}}\llap{\text{if  $i=1,\ldots,n-1$;}} \\
(d_ng_n,\ldots,d_1g_1),& \text{if $i=0$,}
\end{cases}
\intertext{and}
s_i(g_n,\ldots,g_0) &= \makebox[\wd\mathbox][l]{$(s_ig_n,\ldots,s_0g_{n-i},id_{G_{n-i}},g_{n-i-1},\ldots,g_0),\hfill i=0,\ldots,n.$}
\end{align*}

\end{document}


The solution stores a bunch of math content inside a box called \mathbox. This box contains an array with column specification @{}ll@{} - similar to that of cases. Additionally it includes a left extensible brace \left\{ (the null right delimiter \right. is removed using \kern-\nulldelimiterspace). The content in the array is constructed from the longest entry within the actual cases environment. I've used 3 of the same lines, although a single line with a zero-width vertical rule of sufficient length would also suffice. The intent is to provide an extensible left brace that is just as wide (horizontally) as the original cases, since only the width of \mathbox will be used.

Once the box is established, a regular \makebox[\wd\mathbox][l]{$...$} is used to set the content for the remaining math content.

-