In the source below, how should I modify the macro Func, which uses tikz-cd, so that it reproduces the output from the macro func, which uses just the array environment?
In particular, how should I:
- Control the row spacing with the
tikz-cdversion to robustly reproduce the row spacing from thearrayversion? - How do I shorten the arrows in the
tikz-cdversion so as to match the lengths in thearrayversion (and position the nodes in thetikz-cdversion so they are positioned the same way as the "X", "Y" and "x", "f(x)" items in thearrayversion?
As to (2), I tried to include option shorten=1em in each \ar command, but that produces weird results; and I tried to include instead scalearrow={0.5}{start}{end} but that creates a tikzcd error.
Note that I want to make the necessary modifications only within the macro Func, so that they do not affect other instances of the tizkcd environment!
Aim: Although the array version works well (especially since I also have variants of it to allow different kinds of vertical alignment then the items have different lengths), I want to try a tikz-cd version so as to facilitate additional "decoration" with tikz constructs.
\documentclass{article}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{tikz-cd}
\usetikzlibrary{arrows.meta,decorations.markings}
\tikzset{
>={Straight Barb[scale=0.8]},
commutative diagrams/arrow style=tikz
}
\newcommand{\from}{\protect\colon}
% version using array:
\newcommand{\func}[6][]{%
\arraycolsep=0pt
\begin{array}[#1]{rlcl}
{#2} \from, &{#3}&,\to, &,{#4}\
&{#5}&,\mapsto,&,{#6}
\end{array}}
% version using tikz-cd:
\newcommand{\Func}[6][]{%
\begin{tikzcd}[
ampersand replacement=&,
row sep=-4pt,
column sep = small,
/tikz/column 1/.append style = {nodes = {anchor=base east}}
]
{#2 \from #3} \ar[r] & {#4}\
{#5} \ar[r, mapsto] & {#6}
\end{tikzcd}}
\begin{document}
[
\func{f}{X}{Y}{x}{f(x)}
]
[
\Func{f}{X}{Y}{x}{f(x)}
]
\end{document}



tikz-cd? – egreg May 20 '22 at 15:50arrayand\toarrows, then useComputer Modern Rightarrowinstead ofStraight Barband adjust lengths locally instead of options to the environment. To shorten the arrows use theshortenkey, and to extend them (as you surly need in themapstoarrow) give a negative value to the key. – Luis Turcio May 20 '22 at 16:31