5

I only installed LaTeX just over 3 weeks ago and I've written about 20 pages of Maths coursework. I have a bit of an issue with arrays - I am trying to use something like dcases to show a piecewise function. My function involves fractions and they come out too small but I can't seem to follow other people's answers to this problem because I am not familiar with the packages etc. Please could you look at my document set-up, as below, and suggest what I'm doing wrong? When I use the amsmath package, things disappear off the ends of pages and everything moves!

\documentclass[11pt]{article}       % use "amsart" instead of "article" for AMSLaTeX format
%\usepackage{geometry}                      % See geometry.pdf to learn the layout options. There are lots.
%\geometry{a4paper}                         % ... or a4paper or a5paper or ... 
%\geometry{landscape}                       % Activate for for rotated page geometry
%\usepackage[parfill]{parskip}          % Activate to begin paragraphs with an empty line rather than an indent
%\usepackage{graphicx}              % Use pdf, png, jpg, or eps with pdflatex; use eps in DVI mode
                                % TeX will automatically convert eps --> pdf in pdflatex        
%\usepackage{mathtools}
\usepackage{amssymb}
%\usepackage[hmargin=2.5cm,vmargin=3cm,bindingoffset=3cm]{geometry}
\usepackage[margin=0.8in,include foot]{geometry}
\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{Chloe Jones A2460906}
\chead{TMA MST326 03}
\rhead{\thepage}
\lfoot{}
\cfoot{}
\rfoot{}
\title{TMA MST326 03}
%\author{Chloe Jones A2460906}
%\date{March 2015}                          % Activate to display a given date or no date
\begin{document}
%\maketitle


H= \begin{array}{lr}
 \\
0 & : \textrm{n even,}\ \  n\neq2\\
\\
 \frac{5\pi + 2n\pi +  5\pi - 2n\pi  }{ \pi ^2 \left({4 - n^2  }\right)}    & :  \textrm{n odd}
 \end{array}
\right.

3
  • 3
    Can you make your code into a minimal working example (MWE)? There is nothing wrong with what you've posted. We need to see a working example in order to help you resolve the issue. – cfr Mar 29 '15 at 15:12
  • 1
    Please, may you give us a image with the formula that you would like write. – Giacomo Alessandroni Mar 29 '15 at 15:23
  • Sorry I have limited time for a coursework deadline - I've changed my values here - and I would find it too difficult to post an image but I would be grateful if you could help with my code please. I was just trying to input a large brace for a piecewise function. The function is zero for odd n and the value of the function is a fraction involving n when n is odd. Thank you for your replies. – Chloe Mar 30 '15 at 10:15
11

The cases environment, provided by the amsmath package, is ready-made for your math expression. Note that the cases environment renders each line in text-style math mode (aka inline math mode). If you don't need to conserve space, consider using a dcases environment instead: It displays the fractional term in display-style math mode and also increases the space between rows.

Either way, the entire expression, starting with H=, has to be in math mode. This can be achieved by placing it in a \[ ... \] group.

enter image description here

\documentclass[11pt]{article} 
\usepackage{mathtools} % loads 'amsmath' package, provides 'dcases' env.
\begin{document}
Using a \texttt{cases} environment:
\[
H= \begin{cases}
0 & \text{if $n$ even, $n\neq2$}\\
\frac{5\pi + 2n\pi +  5\pi - 2n\pi}{\pi^2 (4 - n^2)} & \text{if $n$ odd}
 \end{cases}
\]

\bigskip
Using a \texttt{dcases} environment:
\[
H= \begin{dcases}
0 & \text{if $n$ even, $n\neq2$}\\
\frac{5\pi + 2n\pi +  5\pi - 2n\pi}{\pi^2 (4 - n^2)} & \text{if $n$ odd}
 \end{dcases}
\]
\end{document}

Addendum -- As @daleif has observed in a comment, the dcases* environment may also be of interest. It differs from the dcases environment in that the material after the & character is automatically placed in text mode, obviating the need for the \text{...} wrappers. Using a dcases* environment, one could write the solution as follows:

\[
H= \begin{dcases*}
0 & if $n$ even, $n\neq2$\\
\frac{5\pi + 2n\pi +  5\pi - 2n\pi}{\pi^2 (4 - n^2)} & if $n$ odd
\end{dcases*}
\]
6
  • 1
    Even funnier: dcases* then you don't need \text in the second column (hardly any is using that version) – daleif Dec 20 '15 at 11:26
  • 1
    @daleif - Thanks for this note. I've provided an addendum to illustrate its use for the example at hand. – Mico Dec 20 '15 at 20:18
  • 1
    Your wording is a little off, shouldn't it be "after the & char is..." – daleif Dec 20 '15 at 20:19
  • 1
    But shouldn't it still say "after the & character" , that $ char does not make sense? – daleif Dec 20 '15 at 20:31
  • 1
    @daleif - Two typos, back to back. :-( – Mico Dec 20 '15 at 20:34

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.