Math & Sciencehow to get the texts in multiple cases arrays aligned

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
NELLLY
Posts: 113
Joined: Thu Nov 26, 2009 2:21 am

how to get the texts in multiple cases arrays aligned

Post by NELLLY »

Hello, I have multiple cases arrays as shown below. I need the right hand part(for...)of each case to be vertically aligned with all the other ones. Is there any effective solution?

Code: Select all

\documentclass{article}
\usepackage{amsmath, amssymb}
\usepackage[english]{babel}
\newcommand{\for}{\text{for }}
\begin{document}
\begin{align*}
     p^{00}_{p p'}&=
    \begin{cases}
     e^{-\lambda h}\,P_0(p'|p, n)& \for p_t\leq p_B (a_t=0)\\
     e^{-\lambda h}\,P_0(p'|p=0, n) & \for p_t>p_B (a_t=1)
      \end{cases}\\
     p^{01}_{p p'}&=
    \begin{cases}
    (1- e^{-\lambda h})\,P_1(p'|p, n)& \for p_t\leq p_B (a_t=0)\\
    (1-e^{-\lambda h})\,P_1(p'|p=0, n) & \for p_t>p_B (a_t=1)
    \end{cases}\\
    P^{10}_{p p'}&=
    \begin{cases}
    0                                 &\for p_t\leq p_B (a_t=0)\\
    e^{-\lambda h}\, P_0(p'|p=0, n)   &\for p_t>p_B (a_t=1)
   \end{cases}
\end{align*}
\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
Stefan Kottwitz
Site Admin
Posts: 10321
Joined: Mon Mar 10, 2008 9:44 pm

how to get the texts in multiple cases arrays aligned

Post by Stefan Kottwitz »

Very good and complete minimal example! So it makes fun to work with it.

We could create a sophisticated automatic solution, but let's get it done simple and quickly but still self adjusting. :-)

You could save the width of the widest entry, and put just one entry of the shorter cases in a box of that width.

Code: Select all

\documentclass{article}
\usepackage{amsmath, amssymb}
\usepackage[english]{babel}
\newcommand{\for}{\text{for }}

\begin{document}
\newlength{\widest}
\settowidth{\widest}{$(1-e^{-\lambda h})\,P_1(p'|p=0, n)$}
\begin{align*}
     p^{00}_{p p'}&=
    \begin{cases}
     \makebox[\widest][l]{$e^{-\lambda h}\,P_0(p'|p, n)$} & \for p_t\leq p_B (a_t=0)\\
     e^{-\lambda h}\,P_0(p'|p=0, n) & \for p_t>p_B (a_t=1)
      \end{cases}\\
     p^{01}_{p p'}&=
    \begin{cases}
    (1- e^{-\lambda h})\,P_1(p'|p, n)& \for p_t\leq p_B (a_t=0)\\
    (1-e^{-\lambda h})\,P_1(p'|p=0, n) & \for p_t>p_B (a_t=1)
    \end{cases}\\
    P^{10}_{p p'}&=
    \begin{cases}
    \makebox[\widest][l]{$0$} & \for p_t\leq p_B (a_t=0)\\
    e^{-\lambda h}\, P_0(p'|p=0, n)   &\for p_t>p_B (a_t=1)
   \end{cases}
\end{align*}
\end{document}
Stefan
LaTeX.org admin
NELLLY
Posts: 113
Joined: Thu Nov 26, 2009 2:21 am

Re: how to get the texts in multiple cases arrays aligned

Post by NELLLY »

Excellent solution Stefan. Thanks :D
Post Reply