我正在尝试从 xypic 转到 tikz,但是我似乎无法在 tikz 中找到许多 xypic 功能。
在 tikz 中,您可以轻松绘制双箭头,这与在 xypic 中使用的效果大致相同\ar@2
。我还在 xypic 中使用三箭头和四箭头,以及ar@3
和ar@4
(最后一个是自定义轴)。
我的问题是:如何在 Tikz 中绘制三重/四重箭头?
如果需要的话,我愿意尝试定义自定义箭杆,但我在 tikz 手册(顺便说一下,这非常强大)中找不到如何做到这一点。
答案1
这应该更通用。可选参数处理用于隐藏较小箭头的左和右模糊因子。
\documentclass{article}
\usepackage{xargs}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\newlength{\myline}% line thickness
\setlength{\myline}{1pt}
\newcommandx*{\triplearrow}[4][1=0, 2=1]{% #1 = shorten left (optional), #2 = shorten right (optionsl),
% #3 = draw options (must contain arrow type), #4 = path
\draw[line width=\myline,double distance=3\myline,#3] #4;
\draw[line width=\myline,shorten <=#1\myline,shorten >=#2\myline,#3] #4;
}
\newcommandx*{\quadarrow}[4][1=0, 2=2.5]{% #1 = shorten left (optional), #2 = shorten right (optionsl),
% #3 = draw options (must contain arrow type), #4 = path
\draw[line width=\myline,double distance=5\myline,#3] #4;
\draw[line width=\myline,double distance=\myline,shorten <=#1\myline,shorten >=#2\myline,#3] #4;
}
\begin{document}
\begin{tikzpicture}
\triplearrow{arrows={-Implies}}{(0,0) -- (1,1)}
\quadarrow[2.5]{arrows={Implies-Implies}}{(1,0) to[bend right] (2,1)}
\end{tikzpicture}
\end{document}
答案2
这非常不靠谱,而且代码也很难写。但是它给了你很大的灵活性,可以根据自己的喜好改变外观。唯一的缺点是:弯曲的箭头看起来很糟糕,因为弯曲半径不能正确适应。尽量使用小曲率。
% arara: pdflatex
\documentclass{article}
\usepackage{tikz-cd}
\tikzcdset{%
triple line/.code={\tikzset{%
double equal sign distance, % replace by double distance = 'measure'
double=\pgfkeysvalueof{/tikz/commutative diagrams/background color}}},
quadruple line/.code={\tikzset{%
double equal sign distance, % replace by double distance = 'measure'
double=\pgfkeysvalueof{/tikz/commutative diagrams/background color}}},
Rrightarrow/.code={\tikzcdset{triple line}\pgfsetarrows{tikzcd implies cap-tikzcd implies}},
RRightarrow/.code={\tikzcdset{quadruple line}\pgfsetarrows{tikzcd implies cap-tikzcd implies}}
}
\newcommand*{\tarrow}[2][]{\arrow[Rrightarrow, #1]{#2}\arrow[dash, shorten >= 0.5pt, #1]{#2}}
\newcommand*{\qarrow}[2][]{\arrow[RRightarrow, #1]{#2}\arrow[equal, double distance = 0.25pt, shorten >= 1.28pt, #1]{#2}}
\begin{document}
\begin{tikzcd}
\arrow{r}{1}\arrow{d}[swap]{1}
& \null \arrow[Rightarrow]{r}{2}\arrow[Rightarrow]{d}[swap]{2}
& \null \tarrow["3"]{r}\tarrow[swap, "3"]{d}
& \null\qarrow["4"]{r}\qarrow[swap, "4"]{d}
& \null \\
\null\arrow[bend right]{dr}
& \null\arrow[crossing over]{dl}\arrow[Rightarrow, bend right]{dr}
& \null\arrow[Rightarrow, crossing over]{dl}\tarrow[bend right]{dr}
& \null\tarrow{dl}\qarrow[bend right]{dr} % crossing over not working with this command. has to be done manually
& \null\qarrow{dl} \\ % crossing over not working with this command. has to be done manually
\null & \null & \null & \null & \null \\
\end{tikzcd}
\end{document}
如果您更喜欢这种xy
外观,您可以将轴的厚度设置为更大的值:
% arara: pdflatex
\documentclass{article}
\usepackage{tikz-cd}
\tikzcdset{%
triple line/.code={\tikzset{%
double distance = 3pt,
double=\pgfkeysvalueof{/tikz/commutative diagrams/background color}}},
quadruple line/.code={\tikzset{%
double distance = 5.3pt,
double=\pgfkeysvalueof{/tikz/commutative diagrams/background color}}},
Rrightarrow/.code={\tikzcdset{triple line}\pgfsetarrows{tikzcd implies cap-tikzcd implies}},
RRightarrow/.code={\tikzcdset{quadruple line}\pgfsetarrows{tikzcd implies cap-tikzcd implies}}
}
\newcommand*{\tarrow}[2][]{\arrow[Rrightarrow, #1]{#2}\arrow[dash, shorten >= 0.5pt, #1]{#2}}
\newcommand*{\qarrow}[2][]{\arrow[RRightarrow, #1]{#2}\arrow[equal, double equal sign distance, shorten >= 3.3pt, #1]{#2}}
\begin{document}
\begin{tikzcd}
\arrow{r} & \null \arrow[Rightarrow]{r} & \null \tarrow{r} & \null\qarrow{r} & \null
\end{tikzcd}
\end{document}
解决弯曲问题的一个折衷方案是定义自己的弯曲箭头命令,使其内线缩短 2.2pt。如下所示:
% arara: pdflatex
\documentclass{article}
\usepackage{tikz-cd}
\tikzcdset{%
triple line/.code={\tikzset{%
double equal sign distance, % replace by double distance = 'measure'
double=\pgfkeysvalueof{/tikz/commutative diagrams/background color}}},
quadruple line/.code={\tikzset{%
double equal sign distance, % replace by double distance = 'measure'
double=\pgfkeysvalueof{/tikz/commutative diagrams/background color}}},
Rrightarrow/.code={\tikzcdset{triple line}\pgfsetarrows{tikzcd implies cap-tikzcd implies}},
RRightarrow/.code={\tikzcdset{quadruple line}\pgfsetarrows{tikzcd implies cap-tikzcd implies}}
}
\newcommand*{\tcurvedarrow}[2][]{\arrow[Rrightarrow, #1]{#2}\arrow[dash, shorten >= 2.2pt, #1]{#2}}
\newcommand*{\qcurvedarrow}[2][]{\arrow[RRightarrow, #1]{#2}\arrow[equal, double distance = 0.25pt, shorten >= 2.2pt, #1]{#2}}
\begin{document}
\begin{tikzcd}[column sep=2]
\null\arrow[bend right]{dr}
& \null\arrow[Rightarrow, bend right]{dr}
& \null\tcurvedarrow[bend right]{dr}
& \null\qcurvedarrow[bend right]{dr}
& \null \\
& \null & \null & \null & \null \\
\end{tikzcd}
\end{document}
答案3
现在有一个简单的解决方案,使用tikz-nfold图书馆。
例子:
\documentclass{article}
\usepackage{tikz-cd}
\usetikzlibrary{nfold}
\begin{document}
\begin{tikzcd}
A \arrow[dr, Rightarrow, scaling nfold=4, bend right] & \\
& B
\end{tikzcd}
\end{document}
生成: