12

I want to get this function:

enter image description here

I wrote two options, but I can't match the picture. Here is the first one:

\begin{displaymath}
        P[\chi_{n+1}=j|\chi_{n}=i]=
        \begin{dcases}
                \frac{N-i}{N}&\text{si }j=i+1\\
                \frac{i}{N}&\text{si }j=i-1\\
                0&\text{otro caso}
        \end{dcases}
\end{displaymath}

Case 1

And here is the second one: (This one is kind of compressed)

\begin{displaymath}
        P[\chi_{n+1}=j|\chi_{n}=i]=
        \left\{\begin{array}{cc}
                \dfrac{N-i}{N} & \text{si }j=i+1\\
                \dfrac{i}{N} & \text{si }j=i-1\\
                0 & \text{en otro caso}
        \end{array}\right
\end{displaymath}

How can improve the code?. Thanks for the support.

  • What kind of "improvement" are you looking for? – Werner Jan 18 '17 at 5:44
  • 1
    A minor suggestion: Use \mid instead of | to denote conditioning on some event. – Mico Jan 18 '17 at 5:59
  • (Or \newcommand{\given}{\mid}, but yes.) – wchargin Jan 18 '17 at 20:10
12

The issue seems to be that you want the "column" to the right of the brace to be centered rather than left justified, which is what happens in all of the cases environments (at least, in all of the ones that I know about). To fix this this the OP's idea of using an array seems to be the way to go, but a few tweaks are needed.

  • First, if you use \left\{ then there has to be a matching \right<delimiter>. As there isn't a matching right delimiter, in this case, you can use \right.. Personally, I don't like the sizes that \left....\right produces so, instead, I have defined a macro \Bigger that will scale the following delimiter to the specified height in millimeters, which defaults to 7mm. Except for the optional argument, this is similar to the \bigl, \biggl, \Big ... amsmath macros.
  • Next, as the OP says, the rows of the array are too close together. You can adjust the spacing between rows using the optional argument to the \\ command. So \\[3mm] will add an extra 3mm between the rows, which seems about right.
  • The array environment comes with padding, so there is too much space between the brace and the equations. You can remove the left-padding by adding @{} to the array specifications.
  • I have added some punctuation.
  • Finally, as suggested in the comments, \mid is better than |.

With these changes the MWE produces:

enter image description here

This is pretty close to the "ideal" image given at the top of the question. Here is the full code:

\documentclass{article}
\usepackage{amsmath}

% an ams-style operator for resizing delimiters
% Usage: \Bigger[, \Bigger[8][, \Bigger[10](, ...
\newcommand\Bigger[2][7]{\left#2\rule{0mm}{#1truemm}\right.}

\begin{document}

\begin{displaymath}
        P[\chi_{n+1}=j\mid\chi_{n}=i]=
        \Bigger[14]\{\begin{array}{@{}cl}
                \dfrac{N-i}{N}, & \text{si }j=i+1,\\[3mm]
                \dfrac{i}{N},   & \text{si }j=i-1,\\[3mm]
                0,              & \text{en otro caso}.
        \end{array}
\end{displaymath}

\end{document}
8

This seems to be a precise stylistic choice, so you should somehow make it the default by defining your own environment.

\documentclass{article}
\usepackage{amsmath,mathtools}

\makeatletter % some generic helpers
\newcommand{\LCASES}[1]{$\m@th\displaystyle{#1}$\hfil}
\newcommand{\CCASES}[1]{\hfil$\m@th\displaystyle{#1}$\hfil}
\newcommand{\RCASES}[1]{\hfil$\m@th\displaystyle{#1}$}
\makeatother

\newcases{ecases}{\quad}{\CCASES{##}}{\LCASES{##}}{\lbrace}{.}
\newcases{ecases*}{\quad}{\CCASES{##}}{{##}\hfil}{\lbrace}{.}

\begin{document}

\begin{equation*}
P[\chi_{n+1}=j\mid\chi_{n}=i]=
\begin{ecases*}
  \frac{N-i}{N} & si $j=i+1$,\\
  \frac{i}{N}  & si $j=i-1$,\\
  0            & en otro caso.
\end{ecases*}
\end{equation*}

\end{document}

The ecases environment has the second column cells typeset in math mode, whereas in ecases* they're in text mode.

enter image description here

Say that the publisher to whom you submit your book tells you their editorial policy is to align left the cases. You can answer that it's really easy, because returning to the default just requires changing two lines:

\newcases{ecases}{\quad}{\LCASES{##}}{\LCASES{##}}{\lbrace}{.}
\newcases{ecases*}{\quad}{\LCASES{##}}{{##}\hfil}{\lbrace}{.}

and you'd get

enter image description here

  • I couldn't find \newcases described in either the amsmath or mathtools manuals, however, @Werner has given a nice description of it in his answer to tex.stackexchange.com/questions/27520/…. – Andrew Jan 18 '17 at 8:59
  • @Andrew Yes, it's not really documented and perhaps it should be expanded a bit to allow for avoiding low level functions (something like I did it my code). – egreg Jan 18 '17 at 9:24
  • 1
    Funny, I thought I had documented this back in the day but you are correct: it's not mentioned in the manual and should be. – Morten Høgholm Jan 18 '17 at 15:21
  • @MortenHøgholm I'm quite sure that at some point in time the macro was documented. Maybe adding some boilerplate macros like above would make it friendlier. – egreg Jan 18 '17 at 17:47
  • @egreg I checked in my old sources and I didn't have it there either. Perhaps Lars has time to add it. – Morten Høgholm Jan 18 '17 at 17:59
4

Here, I use a TABstack for the cases. In particular, a \tabularCenterstack allows the column alignments to be individually specified. The baselineskip between cases can be simply set, as shown in the MWE.

\documentclass{scrartcl}
\usepackage{amsmath,tabstackengine}
\TABstackMath% SETS STACKS IN MATH MODE
\TABstackMathstyle{\displaystyle}% DEFINE STYLE OF MATH STACKS
\setstackgap{L}{2.5\baselineskip}% SETS BASELINESKIP FOR LONG-STACKED LINES
\setstacktabulargap{2\tabcolsep}% DEFINES INTERCOLUMN GAP
\begin{document}
\begin{displaymath}
        P[\chi_{n+1}=j|\chi_{n}=i]=
        \left\{
        \tabularCenterstack{cl}{
                \frac{N-i}{N}&\text{si }j=i+1\\
                \frac{i}{N}&\text{si }j=i-1\\
                0&\text{otro caso}
        }
        \right.
\end{displaymath}
\end{document}

enter image description here

2

I would actually like to suggest that you not fully replicate the screenshot you've posted.

Instead, I'd go for a fully symmetrical look, in which the = symbols in the middle row to the right of the curly brace are perfectly aligned with the = symbols to the left. This may be achieved easily with the help of a judiciously constructed \vphantom term.

enter image description here

\documentclass{article}
\usepackage{mathtools} % for 'dcases*' env.
\newcommand\zzz{\vphantom{\dfrac{\mathstrut}{\mathstrut}}} % to be inserted in all 3 rows
\begin{document}
\[
        \Pr[\, \chi^{}_{n+1}=j \mid \chi^{}_{n}=i \,]=
        \begin{dcases*}
                \frac{N-i}{N}\zzz & si $j=i+1$\\
                \frac{i}{N}\zzz   & si $j=i-1$\\
                0 \zzz            & otro caso
        \end{dcases*}
\]
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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