6

How to write a function mapping like this: MWE

\documentclass{standalone}
\usepackage{amsmath,amssymb}
\begin{document}
$ \begin{matrix} f'\colon & A \to \mathbb{R} \\ & x\mapsto f(x)=x^2 \end{matrix} $
\end{document}

dfd

It is not alignment well.

and it must be like

enter image description here

L F
  • 851
  • 1
    Please complete the code rather than posting mere fragments, which are of much less help. How should it look? Don't use $$ in LaTeX. – cfr Jan 27 '16 at 03:35
  • I believe http://tex.stackexchange.com/a/32024/21344 has the answer you seek. :-) – Paul Gessler Jan 27 '16 at 03:55

1 Answers1

4

(The following code uses math examples you posted initially.)

Depending on the type of alignment you want, one of the following two solutions may work for you.

enter image description here

\documentclass{article}
\usepackage{array}
\begin{document}

If you want flush-left alignment:
\[
f\colon \begin{array}{>{\displaystyle}l} 
          X \rightarrow Y \\ 
          x\mapsto f(x)=\frac{x-1}{2} 
         \end{array}
\]

\bigskip
If the arrows have to be aligned vertically:
\[
f\colon \begin{array}{>{\displaystyle}r @{} >{{}}c<{{}} @{} >{\displaystyle}l} 
          X &\rightarrow& Y \\ 
          x &\mapsto& f(x)=\frac{x-1}{2} 
         \end{array}
\]
\end{document}

Addendum: To align the first row of the array with f\colon, provide the [t] placement option after \begin{array}

enter image description here

\documentclass{article}
\usepackage{array}
\begin{document}
If \verb+f\colon+ should be on the same line as \verb+X\to Y+:
\[
\setlength\arraycolsep{0pt}
f\colon \begin{array}[t]{ >{\displaystyle}r >{{}}c<{{}}  >{\displaystyle}l } 
          X &\to& Y \\ 
          x &\mapsto& f(x)=\frac{x-1}{2} 
         \end{array}
\]
\end{document}
Mico
  • 506,678