我想画一个圆角,但下面的代码似乎不符合预期。右上角转向了错误的方向。
\documentclass{article}
\usepackage[pdftex,active,tightpage]{preview}
\setlength\PreviewBorder{2mm}
\usepackage{xifthen}
\usepackage{tikz}
\usetikzlibrary{calc,shapes.multipart,chains,arrows,positioning}
\begin{document}
\begin{preview}
\tikzset{>=latex}
\def\N{6}
\newcommand{\connect}[2]{
\path[*->] ($(#1 north)!0.5!(#1 south)$) edge [bend left] (#2);
}
\newcommand{\drawme}[3]{
\draw[*->,rounded corners=10pt] ($(#1 north)!0.5!(#1 south)$) |- ++(0,#3) -| (#2);
}
\newcommand{\annotation}[2] {
\draw[->] ([yshift=1cm]#1) -- node [above,sloped] {#2} (#1);
}
\begin{tikzpicture}[
list/.style={
very thick, rectangle split,
rectangle split parts=3, draw,
rectangle split horizontal, minimum size=18pt,
inner sep=5pt, text=black,
rectangle split part fill={blue!20, red!20, blue!20}
},
->, start chain=M0 going right,very thick
]
\foreach \i in {1,...,\N} {
\node[list,on chain] (P\i) {\nodepart{second} $P\i$};
}
\foreach \i [evaluate=\i as \j using int(\i+1)] in {1,...,\N} {
\ifthenelse{\i<\N} {
\connect{P\i.three}{P\j.north west}
\connect{P\j.one}{P\i.south east}
}{
\drawme{P\i.three}{P1.north west}{1cm}
\drawme{P1.one}{P\i.south east}{-1cm}
}
}
\annotation{P2.north}{begin};
\annotation{P1.north}{end};
\end{tikzpicture}
\end{preview}
\end{document}
输出:
答案1
更改您\drawme
的
\newcommand{\drawme}[3]{
\draw[*->,rounded corners=10pt] ($(#1 north)!0.5!(#1 south)$) -- ++(0,#3) -| (#2);
}
我已经|- ++(0,#3)
改为-- ++(0,#3)
代码:
\documentclass{article}
\usepackage[pdftex,active,tightpage]{preview}
\setlength\PreviewBorder{2mm}
\usepackage{xifthen}
\usepackage{tikz}
\usetikzlibrary{calc,shapes.multipart,chains,arrows,positioning}
\begin{document}
\begin{preview}
\tikzset{>=latex}
\def\N{6}
\newcommand{\connect}[2]{
\path[*->] ($(#1 north)!0.5!(#1 south)$) edge [bend left] (#2);
}
\newcommand{\drawme}[3]{
\draw[*->,rounded corners=10pt] ($(#1 north)!0.5!(#1 south)$) -- ++(0,#3) -| (#2);
}
\newcommand{\annotation}[2] {
\draw[->] ([yshift=1cm]#1) -- node [above,sloped] {#2} (#1);
}
\begin{tikzpicture}[
list/.style={
very thick, rectangle split,
rectangle split parts=3, draw,
rectangle split horizontal, minimum size=18pt,
inner sep=5pt, text=black,
rectangle split part fill={blue!20, red!20, blue!20}
},
->, start chain=M0 going right,very thick
]
\foreach \i in {1,...,\N} {
\node[list,on chain] (P\i) {\nodepart{second} $P\i$};
}
\foreach \i [evaluate=\i as \j using int(\i+1)] in {1,...,\N} {
\ifthenelse{\i<\N} {
\connect{P\i.three}{P\j.north west}
\connect{P\j.one}{P\i.south east}
}{
\drawme{P\i.three}{P1.north west}{1cm}
\drawme{P1.one}{P\i.south east}{-1cm}
}
}
\annotation{P2.north}{begin};
\annotation{P1.north}{end};
\end{tikzpicture}
\end{preview}
\end{document}