1

I want to have a graph with mixed of undirected and directed edges. I am using the following code.

\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}

But it doesn't draw the edge from advice to pain.

1 Answer 1

1

Found two small syntax errors. Do not include spaces in node name descriptors. Second, a semicolon terminates the draw command so an additional draw commmand was needed. Revised Code below.

\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}

enter image description here

EDIT #1

Revised Code with addition of a directed arrow edge and loading the correct library.

\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}

enter image description here

2
  • Thanks so much! But this doesn't draw a directed edge from advice to pain. I need this edge to be directed.
    – Erin
    Jul 13, 2016 at 15:28
  • @Erin Revised Code for you, see the Edit #1 version Jul 13, 2016 at 18:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .