I have encountered this situation a lot and the following method can be adapted to almost all cases. Similar to Barbara's solution, this involves deciding what is the largest text and using \makebox
to set the type into a box equal to the width of the largest string.
If also inserted a few \phantoms
to get exact alignment of the cases.
\documentclass{article}
\usepackage{amstext}
\newcommand*{\LongestText}{fermentum fringilla mauris }%
\newlength{\LargestSize}%
\settowidth{\LargestSize}{\LongestText}%
\newcommand*{\MakeBox}[1]{\makebox[\LargestSize][l]{#1}}%
\newcommand*{\MakeBoxText}[1]{\text{\MakeBox{#1}}}%
\begin{document}
\begin{itemize}
\item Lorem ipsum dolor sit amet, consectetur adipiscing elit:
\begin{equation}
f(x) = \left\{
\begin{array}{l l}
1\phantom{-} & \MakeBoxText{ nisl justo, hendrerit} \\
0\phantom{-} & \MakeBoxText{ sagittis condimentum}
\end{array} \right.
\end{equation}
\item Duis magna nunc, ultrices at fringilla non, feugiat sed massa:
\begin{equation}
g(x) = \left\{
\begin{array}{l l}
-1 & \MakeBoxText{ fermentum fringilla mauris eget} \\
\phantom{-}0 & \MakeBoxText{ gravida ipsum vitae}
\end{array} \right.
\end{equation}
\end{itemize}
\end{document}
Update: 2011-09-23: In order to be able to handle a general case you can use the technique shown above to each element of the function separately:
- the function name
- the case values
- the case text
Then each portion gets places in a fixed width box and everything lines up exactly even with more complicated expressions:

Below, I have three macros which are to be used for each of the portions. I have chosen a [r]
alignment for the function name, and a [l]
alignment for the case values and case text.
\documentclass{article}
\usepackage{amsmath}
\newcommand*{\LongestName}{\ensuremath{h(x)+g(x)}}% function name
\newcommand*{\LongestValue}{\ensuremath{-1}}% function value
\newcommand*{\LongestText}{fermentum fringilla mauris }%
\newlength{\LargestNameSize}%
\newlength{\LargestValueSize}%
\newlength{\LargestTextSize}%
\settowidth{\LargestNameSize}{\LongestName}%
\settowidth{\LargestValueSize}{\LongestValue}%
\settowidth{\LargestTextSize}{\LongestText}%
% Choose alignment of the various elements here: [r], [l] or [c]
\newcommand*{\MakeBoxName}[1]{{\makebox[\LargestNameSize][r]{\ensuremath{#1}}}}%
\newcommand*{\MakeBoxValue}[1]{\ensuremath{\makebox[\LargestValueSize][l]{\ensuremath{#1}}}}%
\newcommand*{\MakeBoxText}[1]{\makebox[\LargestTextSize][l]{#1}}%
\begin{document}
\begin{itemize}
\item Lorem ipsum dolor sit amet, consectetur adipiscing elit:
\begin{equation}
\MakeBoxName{f(x)} = \left\{
\begin{array}{l l}
\MakeBoxValue{1} & \MakeBoxText{ nisl justo, hendrerit} \\
\MakeBoxValue{0} & \MakeBoxText{ sagittis condimentum}
\end{array} \right.
\end{equation}
\item Duis magna nunc, ultrices at fringilla non, feugiat sed massa:
\begin{equation}
\MakeBoxName{g(x)} = \left\{
\begin{array}{l l}
\MakeBoxValue{-1} & \MakeBoxText{ fermentum fringilla mauris eget}\\
\MakeBoxValue{\phantom{-}0} & \MakeBoxText{ gravida ipsum vitae}
\end{array} \right.
\end{equation}
\item Duis magna nunc, ultrices at fringilla non, feugiat sed massa:
\begin{equation}
\MakeBoxName{h(x)+g(x)} = \left\{
\begin{array}{l l}
\MakeBoxValue{\sin x} & \MakeBoxText{ fermentum fringilla mauris eget} \\
\MakeBoxValue{0} & \MakeBoxText{ gravida ipsum vitae}
\end{array} \right.
\end{equation}
\end{itemize}
\end{document}
Not sure how you prefer to have the function values aligned, but this is how I have been aligning them. You can remove the \phantom{-}
and and adjust the alignments as desired.
\phantom
in the first cases environment:\begin{cases} 0 & \text{now} \\ 1\phantom{-} & \text{then} \end{cases}
. – Gonzalo Medina Sep 22 '11 at 17:15\intertext
ing can help you here, since you cross several environment boundaries. The only solution is a manual one: you have to adjust the widths yourself. A more extreme solution can possibly be obtained using the{alignat}
environment combined with\intertext
, but you would basically be reimplementing a lot of other things. – Ryan Reich Sep 22 '11 at 19:42