4

my goal

Hi all,

I want to write my equation which is like the attached picture. I tried to write this code below but I couldn't make "Hp" starting from the same positions.

How should I write code to have the picture like this.

\begin{eqnarray} \label{eq:5}
Se & = & \left\{
                \begin{array}{ll}
                  \frac{1}{{[1+|\alpha H_{p}|^{n}]}^{m}}     & \quad H_{p}<0\\
                  1  & \quad H_{p} \geq0
                \end{array}
              \right.   \nonumber
 \\
 \theta & = & \left\{
                \begin{array}{ll}
                  \theta_{r}+Se(\theta_{s}-\theta_{r})  & \quad H_{p}<0\\
                  \theta_{s}     & \quad H_{p} \geq0 
                \end{array}
              \right. 
\\  
C & = & \left\{
                \begin{array}{ll}
                  \frac{\alpha m}{1-m}(\theta_{s}-\theta_{r})Se^{\frac{1}{m}}\left(1-Se^{\frac{1}{m}}\right)^{m}    & \quad H_{p}<0\\
                  0     & \quad H_{p} \geq0
                \end{array}
              \right.   \nonumber   
\\  
k_{r} & = & \left\{
                \begin{array}{ll}
                  Se^{l}\left[1-\left(1-Se^{\frac{1}{m}}\right)^{m} \right]^2   & \quad H_{p}<0\\
                  1     & \quad H_{p} \geq0
                \end{array}
              \right.   \nonumber                                            
\end{eqnarray}
lockstep
  • 250,273
Sepideh
  • 41

4 Answers4

2

Please do not use eqnarray! It is deprecated since years. For such things, there are cases from amsmath or the newer mathtools. Just put everything inside of an align. The trick in order to align the most right column is to use an \hphantom here. I hope, this is what you wanted to have.

% arara: pdflatex

\documentclass{article}
\usepackage{mathtools}
\newcommand{\Se}{\operatorname{\mathit{S\kern-.15em e}}}

\begin{document}
\begin{align*}
    \theta &=  
    \begin{dcases}
        \theta_{r}+\Se(\theta_{s}-\theta_{r}) & H_{p}<0 \\ 
        \mathrlap{\theta_{s}}\hphantom{\frac{\alpha m}{1-m}(\theta_{s}-\theta_{r})\Se^{\frac{1}{m}}\bigl(1-\Se^{\frac{1}{m}}\bigr)^{m}} & H_{p} \geq 0 
    \end{dcases}\\
    \Se &=  
    \begin{dcases}
        \frac{1}{{\bigl[1+\lvert\alpha H_{p}\rvert^{n}\bigr]}^{m}} & H_{p}<0 \\ 
        \mathrlap{1}\hphantom{\frac{\alpha m}{1-m}(\theta_{s}-\theta_{r})\Se^{\frac{1}{m}}\bigl(1-\Se^{\frac{1}{m}}\bigr)^{m}} & H_{p} \geq 0 
    \end{dcases} \\
    C &=
    \begin{dcases} 
        \frac{\alpha m}{1-m}(\theta_{s}-\theta_{r})\Se^{\frac{1}{m}}\bigl(1-\Se^{\frac{1}{m}}\bigr)^{m} & H_{p}<0 \\ 
        0 & H_{p} \geq 0 
    \end{dcases} \\
    k_{r} &= 
    \begin{dcases}
        \Se^{l}\Bigl[1-\bigl(1-\Se^{\frac{1}{m}}\bigr)^{m} \Bigr]^2 & H_{p}<0 \\ 
        \mathrlap{1}\hphantom{\frac{\alpha m}{1-m}(\theta_{s}-\theta_{r})\Se^{\frac{1}{m}}\bigl(1-\Se^{\frac{1}{m}}\bigr)^{m}} & H_{p} \geq 0 
    \end{dcases}
\end{align*}
\end{document}

enter image description here


As recommended by daleif, you could also define some certain width and put your lower rows in a mathmakebox with left alignment. This would look like:

\begin{align*}
    \theta &=  
    \begin{dcases}
        \theta_{r}+\Se(\theta_{s}-\theta_{r}) & H_{p}<0 \\ 
        \mathmakebox[5cm][l]{\theta_{s}} & H_{p} \geq 0 
    \end{dcases}\\
    \Se &=  
    \begin{dcases}
        \frac{1}{{\bigl[1+\lvert\alpha H_{p}\rvert^{n}\bigr]}^{m}} & H_{p}<0 \\ 
        \mathmakebox[5cm][l]{1} & H_{p} \geq 0 
    \end{dcases} \\
    C &=
    \begin{dcases} 
        \frac{\alpha m}{1-m}(\theta_{s}-\theta_{r})\Se^{\frac{1}{m}}\bigl(1-\Se^{\frac{1}{m}}\bigr)^{m} & H_{p}<0 \\ 
        \mathmakebox[5cm][l]{0} & H_{p} \geq 0 
    \end{dcases} \\
    k_{r} &= 
    \begin{dcases}
        \Se^{l}\Bigl[1-\bigl(1-\Se^{\frac{1}{m}}\bigr)^{m} \Bigr]^2 & H_{p}<0 \\ 
        \mathmakebox[5cm][l]{1} & H_{p} \geq 0 
    \end{dcases}
\end{align*}
LaRiFaRi
  • 43,807
  • Many thanks for answer, but it is equation that I didn't put it in my screenshot. It is just one equation in total. so, how is it possible to write and having equation number? – Sepideh Mar 17 '16 at 12:42
  • @Sepideh You mean for every line? – LaRiFaRi Mar 17 '16 at 12:49
  • @Sepideh Just remove the asterisk and do something like here: http://tex.stackexchange.com/q/17528 if you want just one number. – LaRiFaRi Mar 17 '16 at 12:56
  • No, actually for all of these four functions create one equation in my thesis. – Sepideh Mar 17 '16 at 12:57
  • 1
    @Sepideh Replace align* with aligned, and then wrap it in an equation environment, so you have \begin{equation}\begin{aligned} <all the four equations> \end{aligned}\end{equation}. – Torbjørn T. Mar 17 '16 at 13:01
  • Ok, great. It works but, what does this line means? \newcommand{\Se}{\operatorname{\mathit{S\kern-.15em e}}} – Sepideh Mar 17 '16 at 13:20
  • Instead of all those \phantoms wouldn't it be easier (nad easier to understand) if you just wrapped the 1's and 0's in \mathmakebox for some common width? – daleif Mar 17 '16 at 13:27
  • @Sepideh @Torbjorn T. Just \begin{align} should be enough. No equation or aligned needed. Oh, got it wrong, just one number? Then use split. See my link above. @daleif. Sure, would be easier to read. But like this now we have the minimum required width and consistent spacing between dcases columns. Maybe there are more cases later in the document that's why I prefer the 'perfect' spacing. – LaRiFaRi Mar 17 '16 at 13:36
  • @Sepideh The Se is just my personal taste. Remove it, if you do not like it. It looks as if Se is meant as one variable. So I was thinking about something like here: http://tex.stackexchange.com/q/129397 – LaRiFaRi Mar 17 '16 at 13:38
  • @LaRiFaRi -- the parentheses in the last two parts don't really need to be that big; \bigl and \bigr would suffice. then, the brackets in the last part could also be a size smaller. – barbara beeton Mar 17 '16 at 13:57
  • @barbarabeeton true, edited. – LaRiFaRi Mar 17 '16 at 14:09
  • @LaRiFaRi, sure, but down right isn't that much extra work, and new users can be put off by a solution like this as it contains a lot of redundant code – daleif Mar 17 '16 at 14:10
  • @LaRiFaRi I've added an answer where I rewrite your solution a bit. – daleif Mar 17 '16 at 14:17
  • @just seen it, posted your comment in my last edit at the same time... :-) – LaRiFaRi Mar 17 '16 at 14:17
2

Here's a solution that uses four dcases environments placed inside an aligned environment contained in an equation environment. I would actually not bother providing a common alignment of the four pairs of conditioning statements. Instead, I'd concentrate on (a) not letting some of the individual lines become too tall, e.g., by writing ...^{1/m} rather than ...^\frac{1}{m} and (b) providing a bit more vertical whitespace between the four sets of subequations.

enter image description here

\documentclass{article}
\usepackage{mathtools} % for 'dcases'  environment
\newcommand\Se{\textit{Se}}
\begin{document}
\begin{equation} \label{eq:5}
\begin{aligned}
\Se  &= \begin{dcases}
        \frac{1}{[1+\lvert\alpha H_p \rvert^{n}]^{m}} & H_p<0\\
        1  &  H_p\geq0
        \end{dcases}  \\[2ex]
\theta &= \begin{dcases}
          \theta_{r}+\Se (\theta_{s}-\theta_{r})  & H_p<0\\
          \theta_{s}     & H_p\geq0
          \end{dcases}\\[2ex]
C &= \begin{dcases}
     \frac{\alpha m}{1-m}(\theta_{s}-\theta_{r})\Se ^{1/m} \bigl(1-\Se ^{1/m}\bigr)^{m}    & H_p<0\\
     0     & H_p\geq0
     \end{dcases}\\[2ex]
k_{r} &= \begin{dcases}
         \Se^{l}\bigl[1-(1-\Se ^{1/m})^{m} \bigr]^2   & H_p<0\\
         1     & H_p\geq0
         \end{dcases}
\end{aligned}
\end{equation}
\end{document} 

Addendum: If you believe it's preferable to align the four conditioning pairs as well, here's a straightforward way to achieve this goal: (a) Save the longest term in the equations to a macro named, say, \longestterm and measure its width; (b) place one term each of subequations 1, 2, and 4 in a \parbox whose width is that of \longestterm.

enter image description here

\documentclass{article}
\usepackage{mathtools} % for 'dcases'  environment
\newcommand\Se{\textit{Se}}

\newlength\mylen
\newcommand\longestterm{\frac{\alpha m}{1-m}(\theta_{s}-\theta_{r})\Se ^{1/m} (1-\Se ^{1/m}) ^{m}}
\settowidth\mylen{$\displaystyle\longestterm$}

\begin{document}
\begin{equation} \label{eq:5}
\begin{aligned}
\Se    &= \begin{dcases}
          \frac{1}{[1+\lvert\alpha H_p\rvert^{n}]^{m}} & H_p<0\\
          \parbox{\mylen}{$1$}  &  H_p\geq0
          \end{dcases}  \\[2ex]
\theta &= \begin{dcases}
          \theta_{r}+\Se(\theta_{s}-\theta_{r}) & H_p<0\\
          \parbox{\mylen}{$\theta_{s}$} & H_p\geq0
          \end{dcases}\\[2ex]
C      &= \begin{dcases}
          \longestterm & H_p<0\\
          0 & H_p\geq0
          \end{dcases}\\[2ex]
k_{r}  &= \begin{dcases}
          \Se^{l}\bigl[1-(1-\Se^{1/m})^{m} \bigr]^2 & H_p<0\\
          \parbox{\mylen}{$1$}  & H_p\geq0
          \end{dcases}
\end{aligned}
\end{equation}
\end{document} 
Mico
  • 506,678
1

This is just a supplement to LaRiFaRis solution, doing the same thing with less code

\documentclass{article}
\usepackage{mathtools}
\newcommand{\Se}{\operatorname{\mathit{S\kern-.15em e}}}

\newcommand\mybox[1]{}
\begin{document}
% jsut to make this function for this patciluar case 
\renewcommand\mybox[1]{
  \mathrlap{#1}
  \hphantom{\frac{\alpha m}{1-m}(\theta_{s}-\theta_{r})\Se^{\frac{1}{m}}\bigl(1-\Se^{\frac{1}{m}}\bigr)^{m}}
}
\begin{align*}
    \theta &=  
    \begin{dcases}
        \theta_{r}+\Se(\theta_{s}-\theta_{r}) & H_{p}<0 \\ 
        \mybox{\theta_{s}} & H_{p} \geq 0 
    \end{dcases}\\
    \Se &=  
    \begin{dcases}
        \frac{1}{{\bigl[1+\lvert\alpha H_{p}\rvert^{n}\bigr]}^{m}} & H_{p}<0 \\ 
        \mybox{1} & H_{p} \geq 0 
    \end{dcases} \\
    C &=
    \begin{dcases} 
        \frac{\alpha
          m}{1-m}(\theta_{s}-\theta_{r})\Se^{\frac{1}{m}}\bigl(1-\Se^{\frac{1}{m}}\bigr)^{m}
        & H_{p}<0 \\ 
        % this is the widest, so no need to do it here, but we do for
        % completness 
        \mybox{0} & H_{p} \geq 0 
    \end{dcases} \\
    k_{r} &= 
    \begin{dcases}
        \Se^{l}\Bigl[1-\bigl(1-\Se^{\frac{1}{m}}\bigr)^{m} \Bigr]^2 & H_{p}<0 \\ 
        \mybox{1} & H_{p} \geq 0 
    \end{dcases}
\end{align*}
\end{document}
daleif
  • 54,450
0

A simple solution with eqparbox: I define an \eqmathbox command, which makes all commands with the same tag have length equal to the longest contents (two compilations required):

\documentclass{article}
\usepackage{mathtools} % for 'dcases' environment
\usepackage{eqparbox}
\newcommand\eqmathbox[2][M]{\eqmakebox[#1][l]{$\displaystyle#2$}}
\newcommand\Se{\textit{Se}}

\begin{document}

\begin{equation} \label{eq:5}
\begin{aligned}
\Se &= \begin{dcases}
          \eqmathbox{\frac{1}{[1+\lvert\alpha H_p\rvert^{n}]^{m}}} & H_p<0\\
          1 & H_p\geq0
          \end{dcases} \\[2ex]
\theta &= \begin{dcases}
          \eqmathbox{\theta_{r}+\Se(\theta_{s}-\theta_{r})}
          & H_p<0\\
            \theta_{s} & H_p\geq0
          \end{dcases}\\[2ex]
C &= \begin{dcases}
          \eqmathbox{\frac{\alpha m}{1-m}(\theta_{s}-\theta_{r})Se^{\frac{1}{m}}\left(1-Se^{\frac{1}{m}}\right)^{m}} & H_p<0\\
          0 & H_p\geq0
          \end{dcases}\\[2ex]
k_{r} &= \begin{dcases}
          \eqmathbox{\Se^{l}\bigl[1-(1-\Se^{1/m})^{m} \bigr]^2} & H_p<0\\
           1 & H_p\geq0
          \end{dcases}
\end{aligned}
\end{equation}

\end{document} 

enter image description here

Bernard
  • 271,350