用坐标绘制箭头

用坐标绘制箭头

我正在尝试绘制带有坐标的箭头,以便它们不会穿过现有节点,但我做不到。是否有任何参数可以指示箭头坐标(顺便说一下,这是我第一次使用 Tikz 绘制,所以我还是新手)?

这是我当前的绘图和代码,我想添加像绿色的箭头:

在此处输入图片描述

\documentclass{article}
\usepackage[utf8]{inputenc}

\title{Sigma demostration draw}
\author{}

\usepackage{tikz}
\usetikzlibrary{shapes}
\usepackage{amsmath}
\usetikzlibrary{positioning,calc}
\usetikzlibrary{arrows,automata}

\begin{document}
\maketitle
\clearpage
\begin{tikzpicture}[remember picture,overlay,shift={($(current page.west)+(5.5cm,-3cm)$)}]
 % flecha
 [->,>=stealth',shorten >=1pt,auto,node distance=1cm,font=\scriptsize]
 % estilo circulo
 \tikzstyle{circulo}=[circle,fill=cyan,draw=none,text=black,draw=cyan!40, fill=cyan!10, very thick, minimum size=9mm]
 % estilo cuadrado
 \tikzstyle{cuadrado}=[rectangle,fill=blue,draw=none,text=black,draw=blue!40, fill=blue!10, very thick, minimum size=6mm, minimum width=11mm]
  % estilo cuadrado pequeño
 \tikzstyle{cuadrado2}=[rectangle,fill=blue,draw=none,text=black,draw=blue!40, fill=blue!10, very thick, minimum size=3mm, minimum width=7mm, minimum height=5mm]
  % estilo elipse
 \tikzstyle{elipse}=[rectangle,rounded corners=8,fill=cyan,draw=none,text=black,draw=cyan!40, fill=cyan!10, very thick, minimum size=6mm]
 % cuadrado transparente
 \tikzstyle{transparente}=[rectangle,fill=white,draw=none,text=black,minimum size=6mm]

% G1
\node[cuadrado] (g1_1) {$(y_m)$};
\node[circulo] (g1_2) [left = 1cm of g1_1] {$y_m$};
\node[circulo] (g1_3) [right = 1cm of g1_1] {$\neg y_m$};
\node[cuadrado] (g1_4) [above left = 0.5cm of g1_2] {$y_m$};
\node[cuadrado] (g1_6) [above right = 0.5cm of g1_3] {$\neg y_m$};
\node[cuadrado] (g1_8) [above right = 0.5cm of g1_2] {$[y_m^k]$};
\node[cuadrado] (g1_9) [above left = 0.5cm of g1_3] {$[\neg y_m^k]$};
\node[cuadrado] (g1_10) [above = 0.5cm of g1_8] {$[y_m^1]$};
\node[cuadrado] (g1_11) [above = 0.5cm of g1_9] {$[\neg y_m^1]$};

% G2
\node[cuadrado] (g2_1) [above = 3cm of g1_1] {$(y_1)$};
\node[circulo] (g2_2) [left = 1cm of g2_1] {$y_1$};
\node[circulo] (g2_3) [right = 1cm of g2_1] {$\neg y_1$};
\node[cuadrado] (g2_4) [above left = 0.5cm of g2_2] {$y_1$};
\node[cuadrado] (g2_6) [above right = 0.5cm of g2_3] {$\neg y_1$};
\node[cuadrado] (g2_8) [above right = 0.5cm of g2_2] {$[y_1^k]$};
\node[cuadrado] (g2_9) [above left = 0.5cm of g2_3] {$[\neg y_1^k]$};
\node[cuadrado] (g2_10) [above = 0.5cm of g2_8] {$[y_1^1]$};
\node[cuadrado] (g2_11) [above = 0.5cm of g2_9] {$[\neg y_1^1]$};

% G3
\node[cuadrado] (g3_1) [above = 8cm of g1_1] {$(x_n)$};
\node[circulo] (g3_2) [left = 1cm of g3_1] {$x_n$};
\node[circulo] (g3_3) [right = 1cm of g3_1] {$\neg x_n$};
\node[cuadrado] (g3_4) [above left = 0.5cm of g3_2] {$x_n$};
\node[cuadrado] (g3_5) [below left = 0.5cm of g3_2] {$\langle x_n\rangle$};
\node[cuadrado] (g3_6) [above right = 0.5cm of g3_3] {$\neg x_n$};
\node[cuadrado] (g3_7) [below right = 0.5cm of g3_3] {$\langle \neg x_n\rangle$};
\node[cuadrado] (g3_8) [above right = 0.5cm of g3_2] {$[x_m^k]$};
\node[cuadrado] (g3_9) [above left = 0.5cm of g3_3] {$[\neg x_m^k]$};
\node[cuadrado] (g3_10) [above = 0.5cm of g3_8] {$[x_m^1]$};
\node[cuadrado] (g3_11) [above = 0.5cm of g3_9] {$[\neg x_m^1]$};

% G4
\node[cuadrado] (g4_1) [above = 12cm of g1_1] {$(x_1)$};
\node[circulo] (g4_2) [left = 1cm of g4_1] {$x_1$};
\node[circulo] (g4_3) [right = 1cm of g4_1] {$\neg x_1$};
\node[cuadrado] (g4_4) [above left = 0.5cm of g4_2] {$x_1$};
\node[cuadrado] (g4_5) [below left = 0.5cm of g4_2] {$\langle x_1\rangle$};
\node[cuadrado] (g4_6) [above right = 0.5cm of g4_3] {$\neg x_1$};
\node[cuadrado] (g4_7) [below right = 0.5cm of g4_3] {$\langle\neg x_1\rangle$};
\node[cuadrado] (g4_8) [above right = 0.5cm of g4_2] {$[x_1^k]$};
\node[cuadrado] (g4_9) [above left = 0.5cm of g4_3] {$[\neg x_1^k]$};
\node[cuadrado] (g4_10) [above = 0.5cm of g4_8] {$[x_1^1]$};
\node[cuadrado] (g4_11) [above = 0.5cm of g4_9] {$[\neg x_1^1]$};

% G10
\node[circulo] (g10_1) [below = 1.5cm of g1_1] {$u_0$};
\node[cuadrado] (g10_2) [below left = 0.6cm of g10_1] {$u_0$};
\node[cuadrado] (g10_3) [below right = 0.6cm of g10_1] {$u_0 \_ u_0^,$};
\node[circulo] (g10_4) [below = 1.2cm of g10_1] {$u_0^,$};
\node[cuadrado] (g10_5) [below left = 0.6cm of g10_4] {$u_0^,$};


% G5
\node[elipse] (g5_1) [right = 1.4cm of g4_7] {$\thinspace x_1 \vee\neg x_n\vee y_1$};
\node[transparente] (g20_1) [right = 1cm of g5_1] {$\dotsb$};
\node[circulo] (g5_2) [right = 2.4cm of g5_1] {$c_i$};
\node[transparente] (g20_2) [right = 0.8cm of g5_2] {$\dotsb$};
\node[circulo] (g5_3) [right = 2.2cm of g5_2] {$c_k$};
\node[transparente] (g5_4) [above left = 0.7cm of g5_2] {$\dotsb$};
\node[transparente] (g5_5) [above = 0.7cm of g5_2] {$\dotsb$};
\node[transparente] (g5_6) [above right = 0.7cm of g5_2] {$\dotsb$};
\node[transparente] (g5_7) [above left = 0.7cm of g5_3] {$\dotsb$};
\node[transparente] (g5_8) [above = 0.7cm of g5_3] {$\dotsb$};
\node[transparente] (g5_9) [above right = 0.7cm of g5_3] {$\dotsb$};
\node[cuadrado2] (g5_10) [below = 0.4cm of g5_1] {$[c_1]$};
\node[cuadrado2] (g5_11) [below right = 0.5cm of g5_1] {$[c_1]$};
\node[cuadrado2] (g5_12) [below left = 0.5cm of g5_2] {$[c_i]$};
\node[cuadrado2] (g5_13) [below right = 0.5cm of g5_2] {$[c_i]$};
\node[cuadrado2] (g5_14) [below left = 0.5cm of g5_3] {$[c_k]$};
\node[cuadrado2] (g5_15) [below right = 0.5cm of g5_3] {$[c_k]$};

% G6
\node[circulo] (g6_1) [below = 3cm of g5_2] {$all$};
\node[cuadrado] (g6_2) [below left = 1cm of g6_1] {$u_0 \_ all$};
\node[cuadrado] (g6_3) [below right = 1cm of g6_1] {$all \_ all^,$};
\node[circulo] (g6_4) [below = 1cm of g6_3] {$all^,$};
\node[cuadrado] (g6_5) [below = 1cm of g6_4] {$all^,$};
\node[cuadrado] (g6_6) [right = 1cm of g6_1] {$all$};

% G7
\node[circulo] (g7_1) [below = 14cm of g5_12] {$col_i$};
\node[cuadrado2] (g7_2) [above right = 0.3cm of g7_1] {$col_i$};
\node[transparente] (g70_1) [below = 1cm of g7_1] {$\dotsb$};
\node[cuadrado2] (g7_6) [left = 0.1cm of g70_1] {$[\neg x_1^k]$};
\node[transparente] (g70_2) [left = 0.03cm of g7_6] {$\dotsb$};
\node[cuadrado2] (g7_5) [left = 0.1cm of g70_2] {$[\neg x_1^1]$};
\node[cuadrado2] (g7_4) [left = 0.3cm of g7_5] {$[x_1^k]$};
\node[transparente] (g70_3) [left = 0cm of g7_4] {$\dotsb$};
\node[cuadrado2] (g7_3) [left = 0cm of g70_3] {$[x_1^1]$};
% --------------------------
\node[cuadrado2] (g7_7) [right = 0.1cm of g70_1] {$[y_m^1]$};
\node[transparente] (g70_4) [right = 0.07cm of g7_7] {$\dotsb$};
\node[cuadrado2] (g7_8) [right = 0.7cm of g7_7] {$[y_m^k]$};
\node[cuadrado2] (g7_9) [right = 0.1cm of g7_8] {$[\neg y_m^1]$};
\node[transparente] (g70_5) [right = 0.07cm of g7_9] {$\dotsb$};
\node[cuadrado2] (g7_10) [right = 0.7cm of g7_9] {$[\neg y_m^k]$};

% G8
\node[circulo] (g8_1) [below = 13cm of g5_1] {$col_1$};
\node[cuadrado2] (g8_2) [above right = 0.5cm of g8_1] {$col_1$};
\node[cuadrado2] (g8_3) [above left = 0.5cm of g8_1] {$ ? $};
\node[cuadrado2] (g8_4) [below left = 0.9cm of g8_1] {$ ? $};
\node[cuadrado2] (g8_5) [below right = 0.9cm of g8_1] {$ ? $};
\node[transparente] (g80_1) [above = 0.2cm of g8_1] {$\dotsb$};
\node[transparente] (g80_2) [below = 0.5cm of g8_1] {$\dotsb$};

% G9
\node[circulo] (g9_1) [below = 13cm of g5_3] {$col_n{}_+{}_m$};
\node[cuadrado2] (g9_2) [above right = 0.6cm of g9_1] {$col_n{}_+{}_m$};
\node[cuadrado2] (g9_3) [above left = 0.6cm of g9_1] {$ ? $};
\node[cuadrado2] (g9_4) [below left = 0.4cm of g9_1] {$ ? $};
\node[cuadrado2] (g9_5) [below right = 0.4cm of g9_1] {$ ? $};
\node[transparente] (g90_1) [above = 0.2cm of g9_1] {$\dotsb$};
\node[transparente] (g90_2) [below = 0.1cm of g9_1] {$\dotsb$};


\path   
% G1
    (g1_2) 
        edge [below] node {k} (g1_1)
        edge [left, pos=0.3] node {n} (g1_4)
        edge [left, pos=0.5] node {1} (g1_8)
        edge [bend left, left, pos=0.5] node {1} (g1_10)
    (g1_3) 
        edge [below] node {k} (g1_1)
        edge [right, pos=0.3] node {n} (g1_6)
        edge [right, pos=0.5] node {1} (g1_9)
        edge [bend right, right, pos=0.5] node {1} (g1_11)
% G2
    (g2_2) 
        edge [below] node {k} (g2_1)
        edge [left, pos=0.3] node {n} (g2_4)
        edge [left, pos=0.5] node {1} (g2_8)
        edge [bend left, left, pos=0.5] node {1} (g2_10)
    (g2_3) 
        edge [below] node {k} (g2_1)
        edge [right, pos=0.3] node {n} (g2_6)
        edge [right, pos=0.5] node {1} (g2_9)
        edge [bend right, right, pos=0.5] node {1} (g2_11)
% G3
    (g3_2) 
        edge [below] node {k+1} (g3_1)
        edge [left, pos=0.3] node {n-1} (g3_4)
        edge [left, pos=0.2] node {1} (g3_5)
        edge [left, pos=0.5] node {1} (g3_8)
        edge [bend left, left, pos=0.5] node {1} (g3_10)
    (g3_3) 
        edge [below] node {k+1} (g3_1)
        edge [right, pos=0.3] node {n-1} (g3_6)
        edge [right, pos=0.2] node {1} (g3_7)
        edge [right, pos=0.5] node {1} (g3_9)
        edge [bend right, right, pos=0.5] node {1} (g3_11)
% G4
    (g4_2) 
        edge [below] node {k+1} (g4_1)
        edge [left, pos=0.3] node {n-1} (g4_4)
        edge [left, pos=0.2] node {1} (g4_5)
        edge [left, pos=0.5] node {1} (g4_8)
        edge [bend left, left, pos=0.5] node {1} (g4_10)
    (g4_3) 
        edge [below] node {k+1} (g4_1)
        edge [right, pos=0.3] node {n-1} (g4_6)
        edge [right, pos=0.2] node {1} (g4_7)
        edge [right, pos=0.5] node {1} (g4_9)
        edge [bend right, right, pos=0.5] node {1} (g4_11)
% G10
    (g10_1) 
        edge [above  left, pos=0.5] node {k+1} (g10_2)
        edge [above  right, pos=0.5] node {n} (g10_3)
    (g10_4) 
        edge [below right, pos=0.5] node {n+2} (g10_3)
        edge [below right, pos=0.5] node {k} (g10_5)
% G5
    (g5_1)  
        edge [left, pos=0.5] node {M-1} (g5_10)
        edge [above right, pos=0.7] node {M-1} (g5_11)
    (g5_2)  
        edge [right, pos=0.8] node {2n-2} (g5_4)
        edge [right, pos=0.6] node {2n-2} (g5_5)
        edge [right, pos=0.4] node {2n-2} (g5_6)
        edge [above left, pos=0.7] node {M-1} (g5_12)
        edge [above right, pos=0.7] node {M-1} (g5_13)
    (g5_3)  
        edge [right, pos=0.8] node {2n-2} (g5_7)
        edge [right, pos=0.6] node {2n-2} (g5_8)
        edge [right, pos=0.4] node {2n-2} (g5_9)
        edge [above left, pos=0.7] node {M-1} (g5_14)
        edge [above right, pos=0.7] node {M-1} (g5_15)
% G6
    (g6_1)  
        edge [above left, pos=0.6] node {1} (g6_2)
        edge [above right, pos=0.6] node {k+3} (g6_3)
        edge [above, pos=0.5] node {n} (g6_6)
        edge [right, pos=0.5] node {1} (g5_11)
        edge [right, pos=0.5] node {1} (g5_13)
        edge [below right, pos=0.5] node {1} (g5_15)
    (g6_4)  
        edge [right, pos=0.3] node {3M} (g6_3)
        edge [right, pos=0.3] node {M} (g6_5)
% G7  
    (g7_1) 
        edge [below right, pos=0.5] node {n} (g7_2)
        edge [above, pos=0.85] node {1} (g7_3)
        edge [above, pos=0.85] node {1} (g7_4)
        edge [above, pos=0.85] node {1} (g7_5)
        edge [left, pos=0.7] node {1} (g7_6)
        edge [right, pos=0.7] node {1} (g7_7)
        edge [above, pos=0.85] node {1} (g7_8)
        edge [above, pos=0.85] node {1} (g7_9)
        edge [above, pos=0.85] node {1} (g7_10)
        %edge [above, pos=0.85] node {1} (g5_10)
        %edge [above, pos=0.85] node {1} (g5_12)
        %edge [above, pos=0.85] node {1} (g5_14)

% G8
    (g8_1) 
        edge [below right, pos=0.5] node {n} (g8_2)
        edge [below right, pos=0.5] node {} (g8_3)
        edge [below right, pos=0.5] node {} (g8_4)
        edge [below right, pos=0.5] node {} (g8_5)
        edge [below right, pos=0.5] node {} (g80_1)
        edge [below right, pos=0.5] node {} (g80_2)
  
% G9
    (g9_1) 
        edge [below right, pos=0.5] node {n} (g9_2) 
        edge [below right, pos=0.5] node {} (g9_3)
        edge [below right, pos=0.5] node {} (g9_4)
        edge [below right, pos=0.5] node {} (g9_5)
        edge [below right, pos=0.5] node {} (g90_1)
        edge [below right, pos=0.5] node {} (g90_2)
        
    ;

\end{tikzpicture}
\end{document}

此外,我不明白为什么箭头没有出现。这条线有问题吗?

 [->,>=stealth',shorten >=1pt,auto,node distance=1cm,font=\scriptsize]

我还有点疑问,如何在节点内写换行符。红色的节点我希望它看起来像这样:

在此处输入图片描述

我怎样才能让它在顶部显示“c1”并在底部显示该子句的其余部分?

答案1

您需要稍微清理一下代码。有一些冗余定义,例如fill=cyan,draw=none,draw=cyan!40,fill=cyan!10。最后一个定义始终在前面,因此您可以删除第一个定义。

然后,你可能想使用\tikzset而不是\tikzstyle(虽然关于哪一个更好可能会有一些争议,但我认为使用\tikzset已经成为标准)。此外,你需要将你的风格分配给某个东西。你不能简单地写,[->,>=stealth',shorten >=1pt]因为这不属于任何东西。你需要告诉 TicirculoZ 应将此定义应用于哪些元素。其他样式(如cuadrado等)已完成此操作。

为了绘制箭头,您可以使用\draw宏并连接不同的节点,或多或少就像已经为黑线完成的那样。

您已经加载了shapes带有真实椭圆节点的库。您可以利用它。为了在节点内输入换行符,您需要为此节点设置对齐方式。

下面是一个简化的示例,它使用部分代码来帮助您入门。

\documentclass[border=5pt]{standalone}

\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}
\usetikzlibrary{arrows,shapes}

\tikzset{
 % flecha
 flecha/.style={->,>=stealth',green!50!black,shorten >=1pt}, 
 % estilo circulo
 circulo/.style={circle,text=black,draw=cyan!40, fill=cyan!10, very thick, minimum size=9mm}, 
 % estilo cuadrado
 cuadrado/.style={rectangle,text=black,draw=blue!40, fill=blue!10, very thick, minimum size=6mm, minimum width=11mm}, 
 % estilo cuadrado pequeño
 cuadrado2/.style={cuadrado, minimum size=3mm, minimum width=7mm, minimum height=5mm}, 
 % estilo elipse
 elipse/.style={rectangle,rounded corners=8,text=black,draw=cyan!40, fill=cyan!10, very thick, minimum size=6mm}, 
 % elipse real
 elipse2/.style={ellipse,text=black,draw=cyan!40, fill=cyan!10, very thick, minimum size=6mm, inner sep=1pt}, 
 % cuadrado transparente
 transparente/.style={rectangle,fill=white,draw=none,text=black,minimum size=6mm}
}

\begin{document}
\begin{tikzpicture}
%[remember picture,overlay,shift={($(current page.west)+(5.5cm,-3cm)$)}]

% G1
\node[cuadrado] (g1_1) {$(y_m)$};
\node[circulo] (g1_2) [left = 1cm of g1_1] {$y_m$};
\node[circulo] (g1_3) [right = 1cm of g1_1] {$\neg y_m$};
\node[cuadrado] (g1_4) [above left = 0.5cm of g1_2] {$y_m$};
\node[cuadrado] (g1_6) [above right = 0.5cm of g1_3] {$\neg y_m$};
\node[cuadrado] (g1_8) [above right = 0.5cm of g1_2] {$[y_m^k]$};
\node[cuadrado] (g1_9) [above left = 0.5cm of g1_3] {$[\neg y_m^k]$};
\node[cuadrado] (g1_10) [above = 0.5cm of g1_8] {$[y_m^1]$};
\node[cuadrado] (g1_11) [above = 0.5cm of g1_9] {$[\neg y_m^1]$};

% G3
\node[cuadrado] (g3_1) [above = 8cm of g1_1] {$(x_n)$};
\node[circulo] (g3_2) [left = 1cm of g3_1] {$x_n$};
\node[circulo] (g3_3) [right = 1cm of g3_1] {$\neg x_n$};
\node[cuadrado] (g3_4) [above left = 0.5cm of g3_2] {$x_n$};
\node[cuadrado] (g3_5) [below left = 0.5cm of g3_2] {$\langle x_n\rangle$};
\node[cuadrado] (g3_6) [above right = 0.5cm of g3_3] {$\neg x_n$};
\node[cuadrado] (g3_7) [below right = 0.5cm of g3_3] {$\langle \neg x_n\rangle$};
\node[cuadrado] (g3_8) [above right = 0.5cm of g3_2] {$[x_m^k]$};
\node[cuadrado] (g3_9) [above left = 0.5cm of g3_3] {$[\neg x_m^k]$};
\node[cuadrado] (g3_10) [above = 0.5cm of g3_8] {$[x_m^1]$};
\node[cuadrado] (g3_11) [above = 0.5cm of g3_9] {$[\neg x_m^1]$};

% G10
\node[circulo] (g10_1) [below = 1.5cm of g1_1] {$u_0$};
\node[cuadrado] (g10_2) [below left = 0.6cm of g10_1] {$u_0$};
\node[cuadrado] (g10_3) [below right = 0.6cm of g10_1] {$u_0 \_ u_0^,$};
\node[circulo] (g10_4) [below = 1.2cm of g10_1] {$u_0^,$};
\node[cuadrado] (g10_5) [below left = 0.6cm of g10_4] {$u_0^,$};

%%%
\node[elipse, align=center] (g5_1) [below = 2cm of g3_1] {$C_1$ \\ $\thinspace x_1 \vee\neg x_n\vee y_1$};

\node[elipse2, align=center] (g5_1) [below = 3.5cm of g3_1] {$C_1$ \\ $\thinspace x_1 \vee\neg x_n\vee y_1$};

\path   
% G1
    (g1_2) 
        edge [below] node {k} (g1_1)
        edge [left, pos=0.3] node {n} (g1_4)
        edge [left, pos=0.5] node {1} (g1_8)
        edge [bend left, left, pos=0.5] node {1} (g1_10)
    (g1_3) 
        edge [below] node {k} (g1_1)
        edge [right, pos=0.3] node {n} (g1_6)
        edge [right, pos=0.5] node {1} (g1_9)
        edge [bend right, right, pos=0.5] node {1} (g1_11)
% G3
    (g3_2) 
        edge [below] node {k+1} (g3_1)
        edge [left, pos=0.3] node {n-1} (g3_4)
        edge [left, pos=0.2] node {1} (g3_5)
        edge [left, pos=0.5] node {1} (g3_8)
        edge [bend left, left, pos=0.5] node {1} (g3_10)
    (g3_3) 
        edge [below] node {k+1} (g3_1)
        edge [right, pos=0.3] node {n-1} (g3_6)
        edge [right, pos=0.2] node {1} (g3_7)
        edge [right, pos=0.5] node {1} (g3_9)
        edge [bend right, right, pos=0.5] node {1} (g3_11)
% G10
    (g10_1) 
        edge [above  left, pos=0.5] node {k+1} (g10_2)
        edge [above  right, pos=0.5] node {n} (g10_3)
    (g10_4) 
        edge [below right, pos=0.5] node {n+2} (g10_3)
        edge [below right, pos=0.5] node {k} (g10_5);

\draw[flecha] (g3_5) -- ++(-1,-1) |- (g10_1);
\draw[flecha] (g3_7) -- ++(1,-1) |- (g10_1);

\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容