抱歉,问题标题不具体,但我真的不知道该写些什么。
问题
为了便于绘制交换图,我定义了一个命令,使在 Tikz 中绘制箭头更加容易。语法应该类似于\arrow[ARROW OPTIONS]{src}{tgt}{label}[LABEL OPTIONS]
。该命令定义为
\NewDocumentCommand{\arrow}{ommmo}{
\IfNoValueTF{#1}{
\IfNoValueTF{#5}{
\draw[->] (#2) edge[decorate] node[font=\footnotesize] {\ensuremath{#4}} (#3);
}{
\draw[->] (#2) edge[decorate] node[#5,font=\footnotesize] {\ensuremath{#4}} (#3);
}
}{
\IfNoValueTF{#5}{
\draw[->,#1] (#2) edge[decorate,#1] node[font=\footnotesize] {\ensuremath{#4}} (#3);
}{
\draw[->,#1] (#2) edge[decorate,#1] node[#5,font=\footnotesize] {\ensuremath{#4}} (#3);
}
}
}
在大多数情况下,代码运行良好,假设我已经定义了节点并像
\node (src) at (-1,0) {};
\node (tgt) at (1,0) {};
\arrow{src}{tgt}{}
但是,如果我跳过定义节点并像下面这样使用它
\arrow{-1,0}{1,0}{}
突然,箭头源处出现了一个新的箭头,始终指向上方。由于下面 MWE 中的箭头长度不同,我认为这与路径适应节点的方式有关。但由于节点的背景不透明,我无法弄清楚为什么会出现上述额外的箭头,我非常感谢您的帮助。谢谢。
平均能量损失
% --- begin package declaration
\documentclass{article}
\usepackage{xparse} % better command definition
\usepackage{xstring} % strings
\usepackage{tikz}
\usetikzlibrary{matrix} % node placement
\usetikzlibrary{calc} % calculation
\usetikzlibrary{decorations.pathmorphing} %snaked
\usetikzlibrary{arrows} % right hook->
\usetikzlibrary{arrows.meta} % -Implies
% --- tikz styles and commands
\tikzset{diagram/.append style={
baseline={($(current bounding box.center) + (0pt,-0.15\baselineskip)$)}
}}
\tikzset{objects/.append style={
matrix of nodes,
ampersand replacement=\&, % replaces the column indicator from & to \&
text height=1.75ex, text depth=0.5ex, % fixes some text alignment issues with nodes
column sep={5em,between origins}, row sep={4.5em,between origins} % width of node does not influence column spacing
}}
\tikzset{equals/.append style={
-,
double,
double distance=0.2em
}}
\tikzset{incl/.append style={right hook->}}
\tikzset{epi/.append style={->>}}
\tikzset{mono/.append style={>->}}
\tikzset{mapsto/.append style={|->}}
\tikzset{implies/.append style={
arrows={-Implies},
double,
double distance=0.2em
}}
\tikzset{snaked/.append style={
decoration={
snake,
amplitude=.4mm,
segment length=2mm,
pre length=1mm,
post length=1mm
}
}}
\tikzset{zigzaged/.append style={
decoration={
zigzag,
amplitude=.4mm,
segment length=2mm,
pre length=1mm,
post length=1mm
}
}}
\NewDocumentEnvironment{diagram}{}{
\tikzpicture[diagram]
}{
\endtikzpicture
}
\NewDocumentCommand{\arrow}{ommmo}{
\IfNoValueTF{#1}{
\IfNoValueTF{#5}{
\draw[->] (#2) edge[decorate] node[font=\footnotesize] {\ensuremath{#4}} (#3);
}{
\draw[->] (#2) edge[decorate] node[#5,font=\footnotesize] {\ensuremath{#4}} (#3);
}
}{
\IfNoValueTF{#5}{
\draw[->,#1] (#2) edge[decorate,#1] node[font=\footnotesize] {\ensuremath{#4}} (#3);
}{
\draw[->,#1] (#2) edge[decorate,#1] node[#5,font=\footnotesize] {\ensuremath{#4}} (#3);
}
}
}
\begin{document}
\begin{diagram}
\node (src) at (-1,0) {};
\node (tgt) at (1,0) {};
\arrow{src}{tgt}{}
\end{diagram}
\begin{diagram}
\arrow{-1,0}{1,0}{}
\end{diagram}
\end{document}
答案1
我最近遇到了几乎相同的问题。在 的定义中\arrow
,用 替换\draw
。\path
不过,我不太明白为什么这样做有效,甚至没有必要。