4

Here is my code. I want to label edges between SYMPTOMS ASSOCIATED WITH PH CHANGES ? and HYPERSENSIVE ESOPHAGUS with "+ve" and between SYMPTOMS ASSOCIATED WITH PH CHANGES ? and acid unrelated heart burn as "-ve" . How can I do so?

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\tikzset{
  invisible/.style={opacity=0},
  visible on/.style={alt=#1{}{invisible}},
  alt/.code args={<#1>#2#3}{%
    \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
  },
}
\tikzset{
block/.style = {
  rectangle,
  thick,
  text width=6em,
  align=center,
  rounded corners,
  draw=cyan!40!black,
  fill=cyan!20,
  inner ysep=10pt
  }
}
\node [block] at (0,6) (GERD){GERD};
\node [block] at (-3,4) (Esophagitis){Reflux esophagitis};
\node [block] at (0,4) (NERD){NERD};
\node [block] at (3,4) (Barret){Barret's esophagitis};
\node [block] at (0,2) (Ph){Ph testing};
\node [block] at (-3,0) (positive) {Ph +ve NERD};
\node [block] at (3,0) (Negative){Functional heart burn};
\node[] at (3,-2)(Symptoms) {\footnotesize {Symptoms associated with P\textsuperscript{H} changes?}};
\node [block] at (5, -4)(hypersensitive) {hypersensitive esophagus};
\node[block] at (1,-4)(unrelated){Acid unrelated heart burn};
\begin{scope}[cyan!40!black]
\draw[->] (GERD) -- (Esophagitis);
\draw[->] (GERD) -- (NERD);
\draw[->] (GERD) -- (Barret);
\draw[->] (NERD)--(Ph);
\draw[->](Ph)--(positive);
\draw[->](Ph)--(Negative);
\draw[->](Negative)--(Symptoms);
\draw[->](Symptoms)--(unrelated);
\draw[->](Symptoms)--(hypersensitive);
\end{scope} 
\end{tikzpicture}
\end{document}
1

For labelling edges, the new TikZ 3.0 provides a shorter syntax. Load the quotes library for this:

\usetikzlibrary{quotes}

Now you can easily label your edges like this:

\draw[->](Symptoms) edge ["-ve" left] (unrelated);

It also works with to:

\draw[->](Symptoms) to ["+ve" right] (hypersensitive);

Bot lines changed this way gives, taken out the relevant part of the picture:

edges with labels

3

You can use, for example,

\draw[->](Symptoms)--node[anchor=east]{-ve}(unrelated);
\draw[->](Symptoms)--node[anchor=west]{+ve}(hypersensitive);

screenshot

The anchor command controls the relative placement of the text; you can also add the pos=<value> key, where <value> takes any number between 0 and 1.

% arara: pdflatex
% !arara: indent: {overwrite: yes}
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[
        block/.style = {
            rectangle,
            thick,
            text width=6em,
            align=center,
            rounded corners,
            draw=cyan!40!black,
            fill=cyan!20,
            inner ysep=10pt
        }
    ]
    \node [block] at (0,6) (GERD){GERD};
    \node [block] at (-3,4) (Esophagitis){Reflux esophagitis};
    \node [block] at (0,4) (NERD){NERD};
    \node [block] at (3,4) (Barret){Barret's esophagitis};
    \node [block] at (0,2) (Ph){Ph testing};
    \node [block] at (-3,0) (positive) {Ph +ve NERD};
    \node [block] at (3,0) (Negative){Functional heart burn};
    \node[] at (3,-2)(Symptoms) {\footnotesize {Symptoms associated with P\textsuperscript{H} changes?}};
    \node [block] at (5, -4)(hypersensitive) {hypersensitive esophagus};
    \node[block] at (1,-4)(unrelated){Acid unrelated heart burn};
    \begin{scope}[cyan!40!black]
        \draw[->] (GERD) -- (Esophagitis);
        \draw[->] (GERD) -- (NERD);
        \draw[->] (GERD) -- (Barret);
        \draw[->] (NERD)--(Ph);
        \draw[->](Ph)--(positive);
        \draw[->](Ph)--(Negative);
        \draw[->](Negative)--(Symptoms);
        \draw[->](Symptoms)--node[anchor=east]{-ve}(unrelated);
        \draw[->](Symptoms)--node[anchor=west]{+ve}(hypersensitive);
    \end{scope}
\end{tikzpicture}
\end{document}

As a comment, you can use the positioning library to construct diagrams like these, which allows you to specify the position of nodes using instructions such as below=of... which saves you having to specify the absolute position using coordinates (as you have done); of course, the output is ultimately what matters, and that wouldn't change very much, but it's good to know that there are alternatives :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.