# Aligning piecewise functions and function definition maths

I am unsure how to align the following so that \mathbb{N} is aligned with the n in f(n). I have tried \begin{align*} but that just gave me a bunch of errors. Any help will be much appreciated!

It suffices to show that $\mathbb{Z}\preceq \mathbb{N}$.
\\* Define $f : \mathbb{N}\longrightarrow \mathbb{Z}$ by $f(n) = \begin{cases} k &\text{if } n=2k \text{ for } k\in \mathbb{Z},\\ -k &\text{if } n=2k+1 \text{ for } k\in \mathbb{Z}. \end{cases}$

-
I'm not sure you really want a line break before “Define”, nor that you want “f(n)” aligned with the “ℕ”. –  egreg Dec 29 '13 at 20:31

The result is pretty horrible.

\documentclass{article}
\usepackage{amsmath,amssymb}
\begin{document}
It suffices to show that $\mathbb{Z}\preceq \mathbb{N}$.
$\begin{array}{@{} r @{} c @{} l @{} } \text{Define }f \colon &\mathbb{N} & {} \longrightarrow \mathbb{Z} \text{ by}\\[1ex] &f(n) &{}=\displaystyle \begin{cases} k &\text{if } n=2k \text{ for } k\in \mathbb{Z},\\ -k &\text{if } n=2k+1 \text{ for } k\in \mathbb{Z}. \end{cases} \end{array}$
\end{document}


\documentclass{article}
\usepackage{amsmath,amssymb}
\begin{document}
It suffices to show that $\mathbb{Z}\preceq \mathbb{N}$.
Define $f \colon\mathbb{N} \to \mathbb{Z}$ by
$f(n)= \begin{cases} k &\text{if } n=2k \text{ for } k\in \mathbb{Z},\\ -k &\text{if } n=2k+1 \text{ for } k\in \mathbb{Z}. \end{cases}$
\end{document}


I'd avoid the usage of k, speaking from a mathematical point of view:

\documentclass{article}
\usepackage{amsmath,amssymb}
\begin{document}
It suffices to show that $\mathbb{Z}\preceq \mathbb{N}$.
Define $f \colon\mathbb{N} \to \mathbb{Z}$ by
$f(n)= \begin{cases} \hphantom{-}\dfrac{n}{2} &\text{if n\in\mathbb{N} is even},\\[2ex] -\dfrac{n-1}{2} &\text{if n\in\mathbb{N} is odd}. \end{cases}$
\end{document}


-