Tikz 无向边和有向边的混合

Tikz 无向边和有向边的混合

我想要一个混合了无向边和有向边的图。我使用以下代码。

\begin{tikzpicture}[main_node/.style={shape          = rectangle,
                                         rounded corners,
                                         draw,                    %% here
                                         double=red,              %% here
                                         double distance =1pt,    %% here
                                         fill           = black!30!white,
                                         minimum width  = 0.1cm,
                                         minimum height = 0.1cm,
                                         align          = center,                                         
                                         text           = black}
                                         ]


    \node[main_node] (affect) at (0,0) {affect};
    \node[main_node] (alert) at (-1, -1.5)  {alert};
    \node[main_node] (track) at (1, -1.5) {track};
    \node[main_node] (advice) at (3, -1) {advice};
    \node[main_node] (pain ) at (5, -1) {pain};
    \draw (affect) -- (alert) -- (track) -- (affect);  (advice) to (pain);


\end{tikzpicture}

但它并没有将建议引向痛苦。

答案1

发现两个小语法错误。节点名称描述符中不要包含空格。其次,分号终止绘制命令,因此需要额外的绘制命令。下面是修订后的代码。

\documentclass[10pt,letterpaper]{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[main_node/.style={shape          = rectangle,
                                         rounded corners,
                                         draw,                    %% here
                                         double=red,              %% here
                                         double distance =1pt,    %% here
                                         fill           = black!30!white,
                                         minimum width  = 0.1cm,
                                         minimum height = 0.1cm,
                                         align          = center,                                         
                                         text           = black}
                                         ]

    \node[main_node] (affect) at (0,0) {affect};
    \node[main_node] (alert) at (-1, -1.5)  {alert};
    \node[main_node] (track) at (1, -1.5) {track};
    \node[main_node] (advice) at (3, -1) {advice};
    \node[main_node] (pain) at (5, -1) {pain};  % REMOVED SPACE FROM NODE NAME
    \draw (affect) -- (alert) -- (track) -- (affect);  
    \draw (advice) to (pain);  % A semicolon ends the command so a second was needed

\end{tikzpicture}
\end{document}

在此处输入图片描述

编辑#1

修改代码,添加有向箭头边并加载正确的库。

\documentclass[10pt,letterpaper]{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{decorations.pathreplacing}
\usepackage{environ}
\usepackage{tikz-cd}
\begin{document}
\begin{tikzpicture}[main_node/.style={shape          = rectangle,
                                         rounded corners,
                                         draw,                    %% here
                                         double=red,              %% here
                                         double distance =1pt,    %% here
                                         fill           = black!30!white,
                                         minimum width  = 0.1cm,
                                         minimum height = 0.1cm,
                                         align          = center,                                         
                                         text           = black}
                                         ]
\tikzset{edge/.style = {->,> = latex'}}

    \node[main_node] (affect) at (0,0) {affect};
    \node[main_node] (alert) at (-1, -1.5)  {alert};
    \node[main_node] (track) at (1, -1.5) {track};
    \node[main_node] (advice) at (3, -1) {advice};
    \node[main_node] (pain) at (5, -1) {pain};
    \draw (affect) -- (alert) -- (track) -- (affect);  
    \draw[edge] (advice) to (pain);


\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容