考虑:
\documentclass[a4paper, 11pt]{article}
\usepackage[protrusion=true,expansion=true]{microtype} % Better typography
\usepackage{graphicx} % Required for including pictures
\usepackage{wrapfig} % Allows in-line images
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,positioning}
\usetikzlibrary{calc,decorations.markings}
\usepackage{mathpazo} % Use the Palatino font
\usepackage[T1]{fontenc}
\tikzstyle{error} = [circle, draw, fill=red!20,
text width=4.0em, text badly centered, node distance=3cm, inner sep=0pt]
\tikzstyle{block} = [rectangle, draw, fill=blue!20,
text width=5em, text centered, rounded corners, minimum height=4em]
\tikzstyle{line} = [draw, -latex']
\tikzstyle{cloud} = [draw, ellipse,fill=red!20, node distance=3cm,
minimum height=2em]
\begin{document}
\begin{tikzpicture}[node distance = 2cm, auto]
% Place nodes
\node [block] (X1) {X1};
\node [block, below of=X1, node distance=3cm] (X2) {X2};
\node [block, below right = .25cm and 1.5cm of X1] (Y) {Y};
\node [error, right of = X1, node distance=3.7cm] (error) {error};
% Draw edges
\path [line] (X1) -- (X2);
%\path [line] (error) -- node {1}(X1);
\end{tikzpicture}
\end{document}
我正在寻找一种方法在 X1 和 X2 之间绘制一条弯曲的双头箭头,如下所示:
有什么建议么?
答案1
我做了以下事情:
- 通过删除所有未使用的库和包,将您的代码示例精简为最小工作示例 (MWE)。
- 在使用样式的定义中使用最新的语法(
\tikzstyle
已弃用)。 - 对于图片元素的定位,使用由库确定的语法
positioning
(观察...=of ...
和之间的区别...=of ...
)。 对于块之间的箭头我使用选项
bend right
:\documentclass[tikz, margin=3mm]{standalone} \usetikzlibrary{arrows.meta, calc, positioning} \tikzset{ error/.style = {circle, draw, fill=red, align=center, inner sep=0pt}, block/.style = {rectangle, draw, fill=blue!20, rounded corners, text width=5em, minimum height=4em, align=center}, } \begin{document} \begin{tikzpicture}[ node distance = 8mm and 12mm ] % Place nodes \node [block] (X1) {X1}; \node [block, below=of X1] (X2) {X2}; \node [block, below right=of X1] (Y) {Y}; \node [error, right=of X1] (error) {error}; % Draw edges \draw [Latex-Latex] (X1.west) to[bend right=45] (X2.west); \end{tikzpicture} \end{document}
注意:我没有费心精确复制您的节点的位置。
答案2
这是你想要的吗?
\documentclass[a4paper, 11pt]{article}
\usepackage[protrusion=true,expansion=true]{microtype} % Better typography
\usepackage{graphicx} % Required for including pictures
\usepackage{wrapfig} % Allows in-line images
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,positioning}
\usetikzlibrary{calc,decorations.markings}
\usepackage{mathpazo} % Use the Palatino font
\usepackage[T1]{fontenc}
\tikzstyle{error} = [circle, draw, fill=red!20,
text width=4.0em, text badly centered, node distance=3cm, inner sep=0pt]
\tikzstyle{block} = [rectangle, draw, fill=blue!20,
text width=5em, text centered, rounded corners, minimum height=4em]
\tikzstyle{line} = [draw, -latex']
\tikzstyle{cloud} = [draw, ellipse,fill=red!20, node distance=3cm,
minimum height=2em]
\begin{document}
\begin{tikzpicture}[node distance = 2cm, auto]
% Place nodes
\node [block] (X1) {X1};
\node [block, below of=X1, node distance=3cm] (X2) {X2};
\node [block, below right = .25cm and 1.5cm of X1] (Y) {Y};
\node [error, right of = X1, node distance=3.7cm] (error) {error};
% Draw edges
\path [<->] (X1) edge[bend right=90] (X2);
%\path [line] (error) -- node {1}(X1);
\end{tikzpicture}
\end{document}
答案3
in
您可以使用和控制“撞击角度” out
。
\documentclass[a4paper, 11pt]{article}
\usepackage[protrusion=true,expansion=true]{microtype} % Better typography
\usepackage{graphicx} % Required for including pictures
\usepackage{wrapfig} % Allows in-line images
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,positioning}
\usetikzlibrary{calc,decorations.markings}
\usepackage{mathpazo} % Use the Palatino font
\usepackage[T1]{fontenc}
\tikzstyle{error} = [circle, draw, fill=red!20,
text width=4.0em, text badly centered, node distance=3cm, inner sep=0pt]
\tikzstyle{block} = [rectangle, draw, fill=blue!20,
text width=5em, text centered, rounded corners, minimum height=4em]
\tikzstyle{line} = [draw, -latex']
\tikzstyle{cloud} = [draw, ellipse,fill=red!20, node distance=3cm,
minimum height=2em]
\begin{document}
\begin{tikzpicture}[node distance = 2cm, auto]
% Place nodes
\node [block] (X1) {X1};
\node [block, below of=X1, node distance=3cm] (X2) {X2};
\node [block, below right = .25cm and 1.5cm of X1] (Y) {Y};
\node [error, right of = X1, node distance=3.7cm] (error) {error};
% Draw edges
\draw [latex-latex,in=135,out=225] (X1.west) to (X2.west);
%\path [line] (error) -- node {1}(X1);
\end{tikzpicture}
\end{document}