3

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

  • 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 3:35
  • I believe tex.stackexchange.com/a/32024/21344 has the answer you seek. :-) – Paul Gessler Jan 27 '16 at 3:55
2

(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}
| improve this answer | |
  • can it be improved for f and X \to Y in the same line? – Luis Felipe Jan 27 '16 at 3:58
  • @LuisFelipe - Sure: Just insert [t] after \begin{array}, i.e., write \begin{array}[t]{...}. – Mico Jan 27 '16 at 4:00

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.