Function definitions with TikZ
Are you sure you want to use TikZ for that?
\documentclass{article}
\usepackage{tikz}
\usepackage{amsmath,mathtools}
\begin{document}
With TikZ:
\begin{center}
\begin{tikzpicture}
\node[anchor=east] (a) at (0,0) {$\mathbf{C}(A,X)$};
\node[anchor=west] (b) at (3,0) {$\mathbf{C}(A,Y)$};
\draw[->] (a) to node (f) [above] {$\mathbf{C}(A,f)$} (b);
\node[anchor=east] (c) at (0,-0.55) {$\varphi$};
\node[anchor=west] (d) at (3,-0.55) {$f \circ \varphi$};
\draw[|->] (c) to node (g) {} (d);
\end{tikzpicture}
\end{center}
Without TikZ:
\begin{align*}
\mathbf{C}(A,X)&\xrightarrow{~\mathbf{C}(A,f)~}\mathbf{C}(A,Y)\\
\varphi&\xmapsto{\hphantom{~\mathbf{C}(A,f)~}}f \circ \varphi
\end{align*}
\end{document}
EDIT: If you want to keep your TikZ pictures and gradually switch to the LaTeX syntax, and if you are worried about the arrow heads, then there are good news: As @CarLaTeX pointed out, TikZ has dozens of arrow styles, some of which resemble (or coincide modulo global TikZ options) the standard LaTeX arrows. (The latter can also be changed, but this requires much more effort.) Just load the arrows.meta
library, and redefine the arrow style e.g. by saying
\usetikzlibrary{arrows.meta}
\tikzset{>={Computer Modern Rightarrow}}
Here is the complete code.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\tikzset{>={Computer Modern Rightarrow}}
\usepackage{amsmath,mathtools}
\begin{document}
With TikZ:
\begin{center}
\begin{tikzpicture}
\node[anchor=east] (a) at (0,0) {$\mathbf{C}(A,X)$};
\node[anchor=west] (b) at (3,0) {$\mathbf{C}(A,Y)$};
\draw[->] (a) to node (f) [above] {$\mathbf{C}(A,f)$} (b);
\node[anchor=east] (c) at (0,-0.55) {$\varphi$};
\node[anchor=west] (d) at (3,-0.55) {$f \circ \varphi$};
\draw[|->] (c) to node (g) {} (d);
\end{tikzpicture}
\end{center}
Without TikZ:
\begin{align*}
\mathbf{C}(A,X)&\xrightarrow{~\mathbf{C}(A,f)~}\mathbf{C}(A,Y)\\
\varphi&\xmapsto{\hphantom{~\mathbf{C}(A,f)~}}f \circ \varphi
\end{align*}
\end{document}
Off-topic, but you may also want to look at \mathbb{C}
or \mathbbm{C}
(which requires \usepackage{bbm}
in the document preamble) instead of \mathbf{C}
.
With array
(and some coercion).
\documentclass{article}
\usepackage{amsmath}
\newcommand{\xxxrightarrow}[2][]{%
\xrightarrow[\quad #1 \quad]{\quad #2 \quad}%
}
\newcommand{\xxxmapstofill}{%
{\mapstochar}
\smash{-}\mkern-7mu
\cleaders\hbox{$\mkern-2mu\smash{-}\mkern-2mu$}\hfill
\mkern-7mu\mathord\rightarrow
}
\newcommand{\function}[5]{%
\begin{array}{@{}c@{}c@{}c@{}}
#1 & \;\xxxrightarrow{#2}\; & #3 \\
#4 & \;\xxxmapstofill\; & #5
\end{array}%
}
\begin{document}
\[
\function{\mathbf{C}(A,X)}{\mathbf{C}(A,f)}{\mathbf{C}(A,Y)}
{\varphi}{f\circ\varphi}
\]
\end{document}
The command \xxxrightarrow
is based on \xrightarrow
, but with some space added around the superscript or subscript, as it seems you want longer arrows (you shouldn't, in my opinion).
The cell below the arrow is filled with an arrow composed with \mapstochar
, which is the small vertical bar which is used for making \mapsto
. For the filling I use a modified version of \rightarrowfill
essentially removing the dollar signs around its definition, which is find in the kernel file fontmath.ltx
:
\def\rightarrowfill{$\m@th\smash-\mkern-7mu%
\cleaders\hbox{$\mkern-2mu\smash-\mkern-2mu$}\hfill
\mkern-7mu\mathord\rightarrow$}
Since I'm using it in an array
cell, it should already be in math mode. The \cleaders
provide for the repetition segment and so for filling the space.
I, instead, I have used another way with tikz-cd
.
\documentclass{article}
\usepackage{tikz-cd}
\usepackage{amsmath,mathtools}
\begin{document}
\begin{tikzcd}
\mathbf{C}(A,X) \arrow[rr, "{\mathbf{C}(A,f)}"] & & \mathbf{C}(A,Y) \\
\varphi \arrow[rr, maps to] & & f \circ \varphi
\end{tikzcd}
\end{document}
Here there is another version, but I think that the length depends on the characters used. I did a lot of tests. I used the same length [12em]
.
\documentclass{article}
\usepackage{tikz-cd}
\usepackage{amsmath,mathtools}
\begin{document}
\[
\begin{tikzcd}
\mathbf{C}(A,X) \ar[r,shift left=.25ex,"{\mathbf{C}(A,f)}"] & [12em] \mathbf{C}(A,Y) \\
\varphi\ar[r,maps to] & [12em]
f \circ \varphi \\
\end{tikzcd}
\]
\end{document}