Aligning elements in set

You might just want to use a custom array for this.

Code

\documentclass[varwidth]{standalone}
\usepackage{amsmath,array}
\newcommand*\extraBar{\hspace{\tabcolsep}|\hspace{\tabcolsep}}
\begin{document}
\begin{equation*}
 P =
 \begin{array}[t]{@{} l @{} r@{} >{{}\to}l !{|} l@{}  l@{}}
    \{ & S & aX & bY & \extraBar  c  \\
       & X & bX & bS,                \\
       & Y & bS & cZ,                \\
       & Z & aS & b & \extraBar  c \}
 \end{array}
\end{equation*}
\end{document}

Output

enter image description here


For multiple alignment points, I usually just use the alignat environment:

enter image description here

Notes:

  • The alignat*= environment produces as many rl pairs as specified in the first paramater and does not insert additional space that the align environment does, so you need to insert the space that is desired between the alignment points.
  • The double && ensure that the subsequent columns are also left aligned.

References:

  • There is a brief discussion on the difference between align and alignat at align environment according to *first* character, rather than last.
  • The discussion at What is the mandatory argument of alignedat for? also applies to the mandatory parameter to for alignat.
  • Why is \mid so called?

Code:

\documentclass{article}
\usepackage{amsmath}

\begin{document}
\begin{alignat*}{4}
    P = \{ && S &\to aX && \mid bY && \mid c  \\
           && X &\to bX && \mid bS,                \\
           && Y &\to bS && \mid cZ,                \\
           && Z &\to aS && \mid b  && \mid c \}
\end{alignat*}
\end{document}

It seems to be that horizontal spacing is enormously big. Therefore I have chosen some values, giving a similar result, in my opinion. There is some manual work, but no additional packages are needed.

\documentclass{article}

\begin{document}

\[
\begin{array}{l@{\kern1pt}l@{\kern4pt|\kern4pt}l@{\kern4pt|\kern4pt}l}
P=\{&S\to{aX}  & bY  & c,\\
& X\to{bX}  & \multicolumn{2}{l}{\kern-\arraycolsep bS, } \\
& Y\to{bS}  & \multicolumn{2}{l}{\kern-\arraycolsep cZ, }\\
& Z\to{aS}  & b   &  c\}
\end{array}
\]

\end{document}

enter image description here