9

I would like to define a mathematical function by its action. Something like

     \documentclass{article}
     \begin{document}
     \[
        \begin{array}{cccc}
         f\colon & R\times R & \rightarrow & R\times R\\
                 & v & \mapsto & f(v)
        \end{array}
      \]
      \end{document}

In this way, spacing is horrible. What is the best way to produce it?

I want the elements in the second line centered with respect to the element of the first line.

ShreevatsaR
  • 45,428
  • 10
  • 117
  • 149
guest
  • 91

4 Answers4

9

I would go with something simple and, at least for me, quite classical:

\documentclass{article}
\usepackage{mathtools}
\begin{document}
\[
  f\colon R\times R \to R\times R,\quad v \mapsto f(v)
\]
or
\[
  f\colon \biggl\{\begin{array}{@{}r@{\;}l@{}}
    R\times R &\to R\times R
  ,\\
    v &\mapsto f(v)
  \end{array}
\]
\end{document}

enter image description here

yo'
  • 51,322
5

One might do with array, by removing the intercolumn spaces. But the result won't be good anyway.

Here are three other ways, in increasing order of preference, to accomplish your need.

\documentclass{article}
\usepackage[tiny]{titlesec} % just to get small section titles
\usepackage{amsmath}
\usepackage[all,cmtip]{xy}
\usepackage{tikz-cd}

\begin{document}

\section{First way}
With only \texttt{amsmath}
\begin{align*}
f\colon R\times R &\to R\times R\\
v & \mapsto f(v)
\end{align*}

\section{Second way}
With \texttt{amsmath} and \texttt{xy}
\[
\xymatrix@R=0pt@C=1pc{
 f\colon R\times R \ar[r] & R\times R \\
 {\hphantom{f\colon{}}} v \ar@{|->}[r] & f(v)
}
\]

\section{Third way}
With \texttt{amsmath} and \texttt{tikz-cd}
\[
\begin{tikzcd}[row sep=0pt,column sep=1pc]
 f\colon R\times R \arrow{r} & R\times R \\
  {\hphantom{f\colon{}}} v \arrow[mapsto]{r} & f(v)
\end{tikzcd}
\]

\end{document}

enter image description here

David Carlisle
  • 757,742
egreg
  • 1,121,712
  • I personally prefer the First way: I find it easier to parse than the other two approaches, because it produces \to and \mapsto that are horizontally aligned. – jub0bs Sep 26 '13 at 13:09
  • NICE! Quick question: suppose we need to write the set "Domain of the function f". I assume that you are with me that the name of this set is dom(f). So, how would you write dom: \mathrm{dom}, \operatorname{dom}, ...? – manooooh Jun 29 '19 at 23:14
  • 1
    @manooooh It’s obviously an operator – egreg Jun 30 '19 at 09:25
2

Why are you using an array in the first place. Assuming you mare using the amsmath package (recommendable), I'd simply write

\begin{gather*}
   f\colon R\times R \to R\times R
   \\
   v \mapsto f(v)
\end{gather}
ShreevatsaR
  • 45,428
  • 10
  • 117
  • 149
daleif
  • 54,450
0

Another solution I have found is

\begin{align*}
  f\colon R\times R &\to R\times R\\
  \setbox0\hbox{$R\times R$}%
  \makebox[\wd0][c]{$v$}&
  \setbox1\hbox{$R\times R$}%
  \mapsto\makebox[\wd1][c]{$f(v)$}
\end{align*}

and it is close to my intentions: I want the elements to be centered with respect to sets but the \mapsto has to be of the same length of \to.

What I don't like in this solution is that I must decide by myself which of the two is bigger (the set or the element) and I have to modify the code manually; e.g.:

\begin{align*}
  \setbox0\hbox{$(v_1,v_2)$}%
  f\colon\makebox[\wd0][c]{$R^2$}&
  \setbox1\hbox{$f((v_1,v_2))$}%
  \to\makebox[\wd1][c]{$R^2$}\\
  (v_1,v_2)&\mapsto f((v_1,v_2))%
\end{align*}
ShreevatsaR
  • 45,428
  • 10
  • 117
  • 149
Guest
  • 1