更新6:新样式 my curve 7与样式5原理相同。

更新6:新样式  my curve 7与样式5原理相同。

我有一个 tikz-cd 图,我想将箭头弯曲一定距离(以便它们的高度与连接端点的直线保持固定距离)。使用bend left,高度取决于宽度,例如在下图中。

在此处输入图片描述

我怎样才能指定距离(例如,这样我就可以使上例中的箭头具有相同的高度)?这些图表旨在从程序中输出,因此如果解决方案涉及手动计算,这是可以的,但应避免为此目的定义新的宏。

第 52.3 条TikZ & PGF 手册似乎相关,但我不知道如何使用那里的任何选项来实现这一点。

\documentclass{article}

\usepackage{tikz-cd}

\begin{document}

\begin{tikzcd}
    \bullet & \bullet && \bullet &&& \bullet
    \arrow[from=1-1, to=1-2, bend left]
    \arrow[from=1-2, to=1-4, bend left]
    \arrow[from=1-4, to=1-7, bend left]
\end{tikzcd}

\end{document}

我希望能够控制任意方向的箭头的高度:例如,下面的垂直和对角线箭头应该具有相同的高度。

在此处输入图片描述

\begin{tikzcd}
    \bullet & \bullet \\
    \bullet && \bullet \\
    \\
    \bullet &&&& \bullet
    \arrow[from=2-3, to=4-5, bend left]
    \arrow[from=1-1, to=2-1, bend left]
    \arrow[from=2-1, to=4-1, bend left]
    \arrow[from=1-2, to=2-3, bend left]
\end{tikzcd}

答案1

以下是我的建议:

更新6:新样式 my curve 7与样式5原理相同。

但像这样的模式my curve 7 = 9mm of .25

我的曲线 7

\documentclass{article}
\usepackage{tikz-cd}
\usetikzlibrary{calc}

    
\tikzset{my curve 7/.style args={#1of#2}{
        to path={.. controls ($(\tikztostart)!#2!(\tikztotarget)!#1!90:(\tikztotarget)$) 
            and ($(\tikztostart)!1-#2!(\tikztotarget)!#1!90:(\tikztotarget)$) 
            .. (\tikztotarget)\tikztonodes}},
             my curve 7/.default={7mm of 0.25}}  

\begin{document}
%With the  "\textbf{my curve 7}" style you can control the height of the arrows in any direction: eg. the vertical and diagonal arrows below are the same height. 
%
% As for the previous styles, by default the control points are placed at 0.25 and 0.75 from the length of the path and at a distance of 7 mm from the path.


\begin{tikzcd}
    \bullet & \bullet && \bullet &&& \bullet
    \arrow["a",blue,from=1-1, to=1-2,  my curve 7]
    \arrow["b",red,from=1-2, to=1-4,  my curve 7=7mm of .25]
    \arrow["c",violet,from=1-4, to=1-7,  my curve 7=7mm of .25]
   \end{tikzcd}

\begin{tikzcd}
    \bullet & \bullet && \bullet &&& \bullet
    \arrow["d"blue,from=1-2, to=1-1,  my curve 7]
    \arrow["e"red,from=1-4, to=1-2,  my curve 7=11mm of .4]
    \arrow["f"violet,from=1-7, to=1-4,  my curve 7]
\end{tikzcd}

\begin{tikzcd}
    \bullet & \bullet \\
    \bullet && \bullet \\
    \\
    \bullet &&&& \bullet
    \arrow["g",from=2-3, to=4-5,  my curve 7]
    \arrow["h",from=1-1, to=2-1,  my curve 7=11mm of .3]
    \arrow["i",from=2-1, to=4-1,  my curve 7=11mm of .3]
    \arrow["j",from=1-2, to=2-3,  my curve 7]
    \arrow["k",from=4-5, to=2-3,  my curve 7=11mm of .4]
    \arrow["l",from=2-1, to=1-1,  my curve 7]
    \arrow["m",from=4-1, to=2-1,  my curve 7]
    \arrow["n",from=2-3, to=1-2,  my curve 7=11mm of .4]
\end{tikzcd}
\end{document}

更新 5:新样式my curve 6:两个参数现在都是可选的。

代码改编自如何使用带有三个或四个参数的“style n args”

[在此处输入图片描述

\documentclass{article}
\usepackage{tikz-cd}
\usetikzlibrary{calc}
%\usepackage{amsmath}

% code adapted from https://tex.stackexchange.com/questions/532341/how-to-use-style-n-args-with-three-or-four-arguments
\tikzset{my curve 6/.style={varkors settings={#1},to path={.. controls ($(\tikztostart)!\pv{pos}!(\tikztotarget)!\pv{height}!90:(\tikztotarget)$) 
            and ($(\tikztostart)!1-\pv{pos}!(\tikztotarget)!\pv{height}!90:(\tikztotarget)$$) 
            .. (\tikztotarget)\tikztonodes}},
  varkors settings/.code={\tikzset{varkor/.cd,#1}
     \def\pv##1{\pgfkeysvalueof{/tikz/varkor/##1}}},
 varkor/.cd,pos/.initial=0.25,height/.initial=7mm}
    
    

\begin{document}
%With the  "\textbf{my curve 6}"   style you can control the height of the arrows in any direction: eg. the vertical and diagonal arrows below are the same height. Both arguments are now optional. 
%
% As for the previous styles, by default the control points are placed at 0.25 and 0.75 from the length of the path and at a distance of 7 mm from the path.


\begin{tikzcd}
    \bullet & \bullet && \bullet &&& \bullet
    \arrow["a",from=1-1, to=1-2,  my curve 6]
    \arrow["b",from=1-2, to=1-4,  my curve 6={pos=.25}]
    \arrow["c",from=1-4, to=1-7,  my curve 6={height=7mm}]
   \end{tikzcd}

\begin{tikzcd}
    \bullet & \bullet && \bullet &&& \bullet
    \arrow["d",from=1-2, to=1-1,  my curve 6]
    \arrow["e",from=1-4, to=1-2,  my curve 6={pos=.4,height=11mm}]
    \arrow["f",from=1-7, to=1-4,  my curve 6]
\end{tikzcd}

\begin{tikzcd}
    \bullet & \bullet \\
    \bullet && \bullet \\
    \\
    \bullet &&&& \bullet
    \arrow["g",from=2-3, to=4-5,  my curve 6]
    \arrow["h",from=1-1, to=2-1,  my curve 6={pos=.3,height=11mm}]
    \arrow["i",from=2-1, to=4-1,  my curve 6={pos=.3,height=11mm}]
    \arrow["j",from=1-2, to=2-3,  my curve 6]
\end{tikzcd}

\begin{tikzcd}
    \bullet & \bullet \\
    \bullet && \bullet \\
    \\
    \bullet &&&& \bullet
    \arrow["k",from=4-5, to=2-3,  my curve 6={pos=.4,height=11mm}]
    \arrow["l",from=2-1, to=1-1,  my curve 6]
    \arrow["m",from=4-1, to=2-1,  my curve 6]
    \arrow["n",from=2-3, to=1-2,  my curve 6={pos=.4}]
\end{tikzcd}
\end{document}

更新 4:风格my curve 5

使用 my curve 5 样式,您可以控制height箭头任何方向:例如下面的垂直箭头和对角箭头的高度相同。

与之前的样式一样,默认情况下控制点位于距离路径长度 0.25 和 0.75 处,距离路径 7 毫米处。

截屏

\documentclass{article}
\usepackage{tikz-cd}
\usetikzlibrary{calc}
\usepackage{amsmath}

\tikzset{my curve 5/.style 2 args={
        to path={.. controls ($(\tikztostart)!#1!(\tikztotarget)!#2!90:(\tikztotarget)$) 
            and ($(\tikztostart)!1-#1!(\tikztotarget)!#2!90:(\tikztotarget)$) 
            .. (\tikztotarget)\tikztonodes}},
             my curve 5/.default={.25}{7mm}
} 

\begin{document}
%With the  "\textbf{my curve 5}"   style you can control the height of the arrows in any direction: eg. the vertical and diagonal arrows below are the same height.
%
% As for the previous styles, by default the control points are placed at 0.25 and 0.75 from the length of the path and at a distance of 7 mm from the path.


\begin{tikzcd}
    \bullet & \bullet && \bullet &&& \bullet
    \arrow[from=1-1, to=1-2,  my curve 5]
    \arrow[from=1-2, to=1-4,  my curve 5]
    \arrow[from=1-4, to=1-7,  my curve 5]
   \end{tikzcd}

\begin{tikzcd}
    \bullet & \bullet && \bullet &&& \bullet
    \arrow[from=1-2, to=1-1,  my curve 5]
    \arrow[from=1-4, to=1-2,  my curve 5]
    \arrow[from=1-7, to=1-4,  my curve 5]
\end{tikzcd}

\begin{tikzcd}
    \bullet & \bullet \\
    \bullet && \bullet \\
    \\
    \bullet &&&& \bullet
    \arrow[from=2-3, to=4-5,  my curve 5]
    \arrow[from=1-1, to=2-1,  my curve 5={.3}{11mm}]
    \arrow[from=2-1, to=4-1,  my curve 5={.3}{11mm}]
    \arrow[from=1-2, to=2-3,  my curve 5]
\end{tikzcd}

\begin{tikzcd}
    \bullet & \bullet \\
    \bullet && \bullet \\
    \\
    \bullet &&&& \bullet
    \arrow[from=4-5, to=2-3,  my curve 5={.3}{9mm}]
    \arrow[from=2-1, to=1-1,  my curve 5]
    \arrow[from=4-1, to=2-1,  my curve 5]
    \arrow[from=2-3, to=1-2,  my curve 5={.3}{9mm}]
\end{tikzcd}

\end{document}

更新 3:样式my curve 4具有两个参数,默认为 0.25 和 7mm。

我的曲线 4

\documentclass{article}
\usepackage{tikz-cd}
\usetikzlibrary{calc}
\usepackage{amsmath}

\tikzset{my curve 4/.style 2 args={
        to path={.. controls ($(\tikztostart)!#1!(\tikztotarget)+(0,#2)$$) 
            and ($(\tikztostart)!1-#1!(\tikztotarget)+(0,#2)$$) 
            .. (\tikztotarget)\tikztonodes}},
            my curve 4/.default={.25}{7mm}
} 

\begin{document}
\begin{minipage}{.65\textwidth}

\begin{enumerate}

\item By default "$\textcolor{blue}{\text{my curve 4}}$".

The control points are placed at 0.25 and 0.75 of the path length, the height is 7 mm. 


\begin{tikzcd}
    \bullet & \bullet && \bullet &&& \bullet
    \arrow[from=1-1, to=1-2, my curve 4]
    \arrow[from=1-2, to=1-4, my curve 4]
    \arrow[from=1-4, to=1-7, my curve 4]
\end{tikzcd}

\begin{tikzcd}
    \bullet & \bullet && \bullet &&& \bullet
    \arrow[from=1-2, to=1-1, my curve 4]
    \arrow[from=1-4, to=1-2, my curve 4]
    \arrow[from=1-7, to=1-4, my curve 4]
\end{tikzcd}

\item You can change the location of these control points.

Here \mbox{"\textcolor{blue}{$\text{my curve 4=\{.4\}\{5mm\}}$"}}.

They are located at 0.4 and 0.6, the height is 5 mm.


\begin{tikzcd}
    \bullet & \bullet && \bullet &&& \bullet
    \arrow[from=1-1, to=1-2, my curve 4={.4}{5mm}]
    \arrow[from=1-2, to=1-4, my curve 4={.4}{5mm}]
    \arrow[from=1-4, to=1-7, my curve 4={.4}{5mm}]
\end{tikzcd}

\begin{tikzcd}
    \bullet & \bullet && \bullet &&& \bullet
    \arrow[from=1-2, to=1-1, my curve 4={.4}{5mm}]
    \arrow[from=1-4, to=1-2, my curve 4={.4}{5mm}]
    \arrow[from=1-7, to=1-4, my curve 4={.4}{5mm}]
\end{tikzcd}

\item Here: "\textcolor{blue}{$\text{my curve 4=\{.3\}\{9mm\}}$}".

They are located at 0.3 and 0.7, the height is 9 mm.


\begin{tikzcd}
    \bullet & \bullet && \bullet &&& \bullet
    \arrow[from=1-1, to=1-2, my curve 4={.3}{9mm}]
    \arrow[from=1-2, to=1-4, my curve 4={.3}{9mm}]
    \arrow[from=1-4, to=1-7, my curve 4={.3}{9mm}]
\end{tikzcd}

\begin{tikzcd}
    \bullet & \bullet && \bullet &&& \bullet
    \arrow[from=1-2, to=1-1, my curve 4={.3}{9mm}]
    \arrow[from=1-4, to=1-2, my curve 4={.3}{9mm}]
    \arrow[from=1-7, to=1-4, my curve 4={.3}{9mm}]
\end{tikzcd}
\end{enumerate}
\end{minipage}
\end{document}

更新 2:样式my curve 3的参数默认为 0.25。

我的曲线 3

\documentclass{article}
\usepackage{tikz-cd}
\usetikzlibrary{calc}
\usepackage{amsmath}

\tikzset{my curve 3/.style={
        to path={([xshift=-3pt]\tikztostart.north east) 
            .. controls ($(\tikztostart)!#1!(\tikztotarget)+(0,.7)$$) 
            and ($(\tikztostart)!1-#1!(\tikztotarget)+(0,.7)$$) 
            .. ([xshift=3pt]\tikztotarget.north west)\tikztonodes}},
            my curve 3/.default=.25
} 

\begin{document}
\begin{enumerate}

\item By default  "$\textcolor{blue}{\text{my curve 3}}$" the control points are placed at 0.25 and 0.75 of the path length. 


\begin{tikzcd}
    \bullet & \bullet && \bullet &&& \bullet
    \arrow[from=1-1, to=1-2, my curve 3]
    \arrow[from=1-2, to=1-4, my curve 3]
    \arrow[from=1-4, to=1-7, my curve 3]
\end{tikzcd}

\item You can change the location of these control points, here \mbox{"\textcolor{blue}{$\text{my curve 3}=.4$"}} they are located at 0.4 and 0.6.

 Indeed: $1-0.4=0.6$. 

\begin{tikzcd}
    \bullet & \bullet && \bullet &&& \bullet
    \arrow[from=1-1, to=1-2, my curve 3=.4]
    \arrow[from=1-2, to=1-4, my curve 3=.4]
    \arrow[from=1-4, to=1-7, my curve 3=.4]
\end{tikzcd}

\item Here they are located at 0.3 and 0.7. "\textcolor{blue}{$\text{my curve 3}=.3$}"

 Indeed: \mbox{$1-0.3=0.7$}. 

\begin{tikzcd}
    \bullet & \bullet && \bullet &&& \bullet
    \arrow[from=1-1, to=1-2, my curve 3=.3]
    \arrow[from=1-2, to=1-4, my curve 3=.3]
    \arrow[from=1-4, to=1-7, my curve 3=.3]
\end{tikzcd}

\end{enumerate}
\end{document}

更新 1:新样式my curve 2

它使用calc

我的曲线 2

\documentclass{article}
\usepackage{tikz-cd}
\usetikzlibrary{calc}

\tikzset{my curve 2/.style={to path={([xshift=-3pt]\tikztostart.north east) .. controls ($(\tikztostart)!.25!(\tikztotarget)+(0,.7)$) and ($(\tikztostart)!.75!(\tikztotarget)+(0,.7)$) .. ([xshift=3pt]\tikztotarget.north west)\tikztonodes}}}

\begin{document}

\begin{tikzcd}
    \bullet & \bullet && \bullet &&& \bullet
    \arrow[from=1-1, to=1-2, my curve 2]
    \arrow[from=1-2, to=1-4, my curve 2]
    \arrow[from=1-4, to=1-7, my curve 2]
\end{tikzcd}
\end{document}

旧答案:风格my curve

截屏

\documentclass{article}
\usepackage{tikz-cd}

\tikzset{my curve/.style={to path={([xshift=-3pt]\tikztostart.north east) .. controls ++(80:5ex) and ++(100:5ex) .. ([xshift=3pt]\tikztotarget.north west)\tikztonodes}}}

\begin{document}

\begin{tikzcd}
    \bullet & \bullet && \bullet &&& \bullet
    \arrow[from=1-1, to=1-2, my curve]
    \arrow[from=1-2, to=1-4, my curve]
    \arrow[from=1-4, to=1-7, my curve]
\end{tikzcd}

\end{document}

相关内容