5

In the following example, I want the line segments to be connected at each vertex. For example, I want E1 and E2 to have a common end point and label V2 should be used to label that end point. How should I modify the code? Thanks.

\documentclass[]{article}

\usepackage{tikz}

\begin{document}

    \begin{tikzpicture}

    \node at (0,0) (nodeA) {$V_1$};
    \node at (2,2) (nodeB) {$V_2$};
    \node at (3,0) (nodeC) {$V_3$};
    \node at (5,1) (nodeD) {$V_4$};

    \draw (nodeA) -- (nodeB) -- (nodeC) -- (nodeD);

    \draw (nodeA) -- (nodeB) node [midway, above, sloped] (EdgeAB) {$E_1$};
    \draw (nodeB) -- (nodeC) node [midway, above, sloped] (EdgeBC) {$E_2$};
    \draw (nodeC) -- (nodeD) node [midway, above, sloped] (EdgeCD) {$E_3$};
    \end{tikzpicture}

\end{document}

enter image description here

1
  • Nodes have various anchors that you can use. You could replace (nodeB) by (nodeB.south) and (nodeC) by (nodeC.north). Nov 23, 2015 at 8:18

1 Answer 1

7

If you set the nodes above and below points on the path, then they will not interfere with the continuity of the path. For example:

\documentclass[tikz,border=10pt]{standalone}
\begin{document}
\begin{tikzpicture}
  \draw (0,0) node (nodeA) [below]  {$V_1$} -- (2,2) node (nodeB) [above] {$V_2$} node [midway, above, sloped] (EdgeAB) {$E_1$} -- (3,0) node [below] (nodeC) {$V_3$} node [midway, above, sloped] (EdgeBC) {$E_2$} -- (5,1) node [above] (nodeD) {$V_4$} node [midway, above, sloped] (EdgeCD) {$E_3$};
\end{tikzpicture}
\end{document}

continuous path

You must log in to answer this question.

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