Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I've seen these questions, but in my case the equation content is too long to add the text description at the end and it overflows into the margin.

\[
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), &\text{if  $i=1,\ldots,n-1$;}\\
 (d_ng_n,\ldots,d_1g_1),& \text{if $i=0$}
 \end{cases}\\
\]

What I'd like is something similar to would be produced by replacing the one overly long line by the two lines

 (d_ig_n,\ldots,d_1g_{n-i+1},d_0g_{n-i}g_{n-i-1},g_{n-i-2},\ldots,g_0), &\\
 & \hspace{-10.5ex}\text{if  $i=1,\ldots,n-1$;}\\

...but this is clearly not the way to do it. I'd also prefer not to break the long equation itself onto two lines, only put the text on the next line. Is there some nice way that will end up with the result that the semicolons are aligned automatically without tweaking the horizontal spacing?

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

In direct answer to your question (that is, keep the lengthy equation on one line, and the condition on another with aligned semi-colon), using \phantom and a left overlap can help obtain the appropriate alignment:

enter image description here

\documentclass{article}
\usepackage{mathtools}% http://ctan.org/pkg/mathtools
\begin{document}
\[
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), &\text{if  $i=1,\ldots,n-1$;} \\
 (d_ng_n,\ldots,d_1g_1),& \text{if $i=0$}
 \end{cases}
\]

\[
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}
\]
\end{document}

\phantom{\text{if $i=0$;}} ensures that your far enough "to the right" in terms of conditional construction, while \llap sets a zero-width box that is right-aligned (resulting in a left overlap) to properly align with the semi-colon of the first case.

share|improve this answer
    
Wow, thanks! That was quick. I knew there should be a sensible way to do it. –  David Roberts Jan 25 '13 at 5:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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