我正在尝试创建如上所示的图片,但在定位方面遇到了问题,如下所示。
我的代码:
\usepackage{tikz}
\usetikzlibrary{positioning, tikzmark}
\begin{equation*}
\begin{tikzpicture}[remember picture]
\node{$\subnode{m1}{$x$} \subnode{m2}{$\rightarrow$} \subnode{m3}{$y$}$};
\end{tikzpicture}
\end{equation*}
\begin{tikzpicture}[remember picture, overlay]
\node[above= 3mm of m2](M1){$w$};
\node[below= 3mm of m3](M2){$\varepsilon$};
\draw [->] (M1) edge (m1);
\draw [->] (M1) edge (m3);
\draw [->] (M2) edge (m3);
\end{tikzpicture}
我不明白为什么 w 不完全位于子节点 m2 上方,而 \varepsilon 不位于 y 下方
答案1
欢迎!这里不需要\subnode
,您只需将\tikzmarknode
s 放入等式中即可。不过,tikz-cd
无论如何,我都会使用 来完成整个操作。
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{positioning, tikzmark,cd}
\begin{document}
\begin{equation*}
\tikzmarknode{m1}{x} \tikzmarknode{m2}{\rightarrow} \tikzmarknode{m3}{y}
\begin{tikzpicture}[remember picture, overlay]
\node[above= 3mm of m2](M1){$w$};
\node[below= 3mm of m3](M2){$\varepsilon$};
\draw [->] (M1) edge (m1);
\draw [->] (M1) edge (m3);
\draw [->] (M2) edge (m3);
\end{tikzpicture}
\end{equation*}
\bigskip
\[\begin{tikzcd}[column sep=0pt,row sep=1.2em]
&w\arrow[dl]\arrow[dr]& \\
X \arrow[rr]& & y \\
& & \varepsilon\arrow[u]
\end{tikzcd}
\]
\end{document}
至于评论中提出的问题:
\documentclass{article}
\usepackage{mathtools}
\usepackage{tikz-cd}
\begin{document}
\[\begin{tikzcd}[column sep=0pt,row sep=1.2em]
&w\mathrlap{[\text{omitted value}]}\arrow[dl,"f"']\arrow[dr,"g"]& \\
x \arrow[rr]& & y \\
& & \varepsilon\arrow[u]
\end{tikzcd}
\]
\end{document}