21

I don't know what the big { thing is called so can't search and when tried and write in LaTeX and didn't find this expression or structure in word either.

enter image description here

Pål GD
  • 889

3 Answers3

45

output

\documentclass{article}
\usepackage{mathtools}          %loads amsmath as well
\DeclarePairedDelimiter\Floor\lfloor\rfloor
\DeclarePairedDelimiter\Ceil\lceil\rceil

\begin{document}
\[
  T(n) =
  \begin{cases}
                                   0 & \text{if $n=1$} \\
                                   1 & \text{if $n=2$} \\
  T(\Floor{n/2}) + T(\Ceil{n/2}) + 2 & \text{if $n>2$}
  \end{cases}
\]
\end{document}
Sean Allred
  • 27,421
  • 2
    Your choice of alignment in the source file is odd and moreso because it's completely different from the output obtained. I'd surely align the &s but I'd align the first part of the lines on the left (so 0 and 1 aligned with T( instead of the + 2). I understand the reasoning behind aligning numbers but having that much spaces looks strange and it's hard to see what's there in the first two rows, besides it suggest the false idea that the output would resemble that alignment which is false. – Bakuriu Apr 11 '15 at 08:11
  • 2
    & \text{if $n=1$} is easier. – egreg Apr 11 '15 at 09:16
  • @egreg Easier in what sense? It's two extra keystrokes and presumably more work for the compiler, too. – David Richerby Apr 11 '15 at 10:48
  • 2
    @DavidRicherby Easier to read from the typescript. – egreg Apr 11 '15 at 10:55
  • 1
    @egreg: & if $n=1$ is still easier, using the cases* environment from mathtools. – Bernard Apr 11 '15 at 12:15
  • @Bernard Of course. – egreg Apr 11 '15 at 12:15
  • @Bakuriu Personal preference, of course :) My eyes have a harder time matching up the different cells appropriately for reading. Personally, I don't get any such suggestion about what the output looks like from the source file – I just care about what the document means – the quicker I can read it, the quicker I can figure that out :) But, if it's quicker for you to read it right-aligned, by all means :) – Sean Allred Apr 11 '15 at 14:51
  • @egreg I used to do that, but the idea of switching out of math mode and then immediately back into it just seems…weird to me. But alas, if it's easier to read, it's of course better (assuming there are no side-effects?) :) Edit I ran a diff of a PDF produced with both methods – there is no difference. \text{if $n=1$} should be preferred. – Sean Allred Apr 11 '15 at 14:53
6

With only a partial alignment, due to the long last line:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{fourier}
\usepackage{mathtools} %loads amsmath as well
\DeclarePairedDelimiter\Floor⎣⎦
\DeclarePairedDelimiter\Ceil⎣⎦

\begin{document}

\[ T(n) =
  \begin{cases*}
    0 \quad& if $ n = 1 $ \\
    1 & if $ n = 2 $ \\
    \mathrlap{T(\Floor{n/2}) + T(\Ceil{n/2}) + 2 \quad \text{if } n > 2}
  \end{cases*}\]

\end{document} 

enter image description here

Bernard
  • 271,350
4

This is one way to obtain the desired result in LaTeX

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{align}
T(n) = \left\{ \begin{array}{cc} 
                0 & \hspace{5mm} n=1 \\
                1 & \hspace{5mm} n=2 \\
                T( \lfloor \frac{n}{2} \rfloor) + T(\lceil \frac{n}{2} \rceil
                      )+ 2 & \hspace{5mm} n > 2 \\
                \end{array} \right.
\end{align}

\end{document}

Output

Leucippus
  • 1,636