LaTeX forum ⇒ Math & Sciencehow to get the texts in multiple cases arrays aligned Topic is solved

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

how to get the texts in multiple cases arrays aligned

Postby NELLLY » Thu Feb 04, 2016 9:09 pm

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?
  1. \documentclass{article}
  2. \usepackage{amsmath, amssymb}
  3. \usepackage[english]{babel}
  4. \newcommand{\for}{\text{for }}
  5. \begin{document}
  6. \begin{align*}
  7. p^{00}_{p p'}&=
  8. \begin{cases}
  9. e^{-\lambda h}\,P_0(p'|p, n)& \for p_t\leq p_B (a_t=0)\\
  10. e^{-\lambda h}\,P_0(p'|p=0, n) & \for p_t>p_B (a_t=1)
  11. \end{cases}\\
  12. p^{01}_{p p'}&=
  13. \begin{cases}
  14. (1- e^{-\lambda h})\,P_1(p'|p, n)& \for p_t\leq p_B (a_t=0)\\
  15. (1-e^{-\lambda h})\,P_1(p'|p=0, n) & \for p_t>p_B (a_t=1)
  16. \end{cases}\\
  17. P^{10}_{p p'}&=
  18. \begin{cases}
  19. 0 &\for p_t\leq p_B (a_t=0)\\
  20. e^{-\lambda h}\, P_0(p'|p=0, n) &\for p_t>p_B (a_t=1)
  21. \end{cases}
  22. \end{align*}
  23. \end{document}

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

Postby Stefan Kottwitz » Thu Feb 04, 2016 9:21 pm

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.


  1. \documentclass{article}
  2. \usepackage{amsmath, amssymb}
  3. \usepackage[english]{babel}
  4. \newcommand{\for}{\text{for }}
  5.  
  6. \begin{document}
  7. \newlength{\widest}
  8. \settowidth{\widest}{$(1-e^{-\lambda h})\,P_1(p'|p=0, n)$}
  9. \begin{align*}
  10. p^{00}_{p p'}&=
  11. \begin{cases}
  12. \makebox[\widest][l]{$e^{-\lambda h}\,P_0(p'|p, n)$} & \for p_t\leq p_B (a_t=0)\\
  13. e^{-\lambda h}\,P_0(p'|p=0, n) & \for p_t>p_B (a_t=1)
  14. \end{cases}\\
  15. p^{01}_{p p'}&=
  16. \begin{cases}
  17. (1- e^{-\lambda h})\,P_1(p'|p, n)& \for p_t\leq p_B (a_t=0)\\
  18. (1-e^{-\lambda h})\,P_1(p'|p=0, n) & \for p_t>p_B (a_t=1)
  19. \end{cases}\\
  20. P^{10}_{p p'}&=
  21. \begin{cases}
  22. \makebox[\widest][l]{$0$} & \for p_t\leq p_B (a_t=0)\\
  23. e^{-\lambda h}\, P_0(p'|p=0, n) &\for p_t>p_B (a_t=1)
  24. \end{cases}
  25. \end{align*}
  26. \end{document}


Stefan
Site admin

NELLLY
Posts: 113
Joined: Thu Nov 26, 2009 2:21 am

Postby NELLLY » Thu Feb 04, 2016 9:41 pm

Excellent solution Stefan. Thanks :D


Return to “Math & Science”

Who is online

Users browsing this forum: No registered users and 3 guests