1

I need to draw some idea of "infinite" or "continues on and on" in my graphs (not graphics). Often I use tkz-graph for graph drawing, but I haven't found a way to add a node without the "circle". As a workaround I used regular \node from tikz, but I'm looking for a more "integrated" solution using only a single tikz "library" for sake of simplicity. The following MWE shows my workaround

\documentclass{article}
\usepackage{tkz-graph}
\begin{document}
\begin{tikzpicture}
    \GraphInit[vstyle=Classic]
    \SetGraphUnit{1.5}
    \tikzset{VertexStyle/.style = {shape = circle,fill = black,minimum size = 7,inner sep=0}}
    \SetUpEdge[lw=1.0pt]

    \draw[dashed,red,thick] (2,0) -- (3,0); % u_0
    \draw[dashed,blue,thick] (1,1) -- (2,2); % u_1
    \draw[dashed,brown,thick] (0,1) -- (0,3); % u_2
    \draw[dashed,purple,thick] (-1,1) -- (-2,2); % u_3
    \draw[dashed,green,thick] (-1.5,0) -- (-2.5,0); % u_{i-1}
    \draw[dashed,thick,cyan] (-1,-1) -- (-2,-2); % u_i
    \draw[dotted,thick] (-1,.5) -- (-1.1,.3); % ...

    \Vertex[Lpos=270,L=$v$]{v}

    \EA[Lpos=270,L=$u_0$,unit=2](v){u0}
    \Edge[color=black!50](v)(u0)

    \NOEA[L=$u_1$,unit=1.14](v){u1}
    \Edge[color=red](v)(u1)

    \NO[L=$u_2$](v){u2}
    \Edge[color=blue](v)(u2)

    \NOWE[L=$u_3$,unit=1.14](v){u3}
    \Edge[color=brown](v)(u3)

    \WE[Lpos=270,L=$u_{i-1}$](v){uim}
    \Edge[color=purple](v)(uim)

    \SOWE[Lpos=180,L=$u_i$,unit=1.14](v){ui}
    \Edge[color=green](v)(ui)
\end{tikzpicture}
\end{document}

Is there a way to not use the \draw but instead I would like to create "ghost" vertices and put \Edge between them.

enter image description here

0

1 Answer 1

2

You can set the tkz-graph node properties such that the nodes are not visible, i.e., zero minimum size and zero line width. This somehow disables the ability to set edge colors afterwards, this can be restored by \SetUpEdge or fixing the color with \tikzstyle{EdgeStyle}. If you want dashed edges in different colors it becomes a bit more complicated, because \tikzstyle disables the color setting in \Edge[color=some color], which can be restored by \SetUpEdge, but this in turn disables \tikzstyle{dashed}. So either you settle on a single color and set that in \tikzstyle, or don't use dashed, or combine the two in a new command as in the MWE below.

\documentclass{article}
\usepackage{tkz-graph}
\usetikzlibrary{calc}
% new macro to set both color and dashed style for individual edges
\def\DashedEdge[#1](#2)(#3){%
\tikzstyle{EdgeStyle}=[dashed,#1]%
\Edge(#2)(#3)%
}
\begin{document}
\begin{tikzpicture}
    \GraphInit[vstyle=Classic]
    \SetGraphUnit{1.5}
    \tikzset{VertexStyle/.style = {shape = circle,fill = black,minimum size = 7,inner sep=0}}
    \SetUpEdge[lw=1.0pt]

    \Vertex[Lpos=270,L=$v$]{v}

    \EA[Lpos=270,L=$u_0$,unit=2](v){u0}
    \Edge[color=black!50](v)(u0)

    \NOEA[L=$u_1$,unit=1.14](v){u1}
    \Edge[color=red](v)(u1)

    \NO[L=$u_2$](v){u2}
    \Edge[color=blue](v)(u2)
    \NOWE[L=$u_3$,unit=1.14](v){u3}
    \Edge[color=brown](v)(u3)

    \WE[Lpos=270,L=$u_{i-1}$](v){uim}
    \Edge[color=purple](v)(uim)

    \SOWE[Lpos=180,L=$u_i$,unit=1.14](v){ui}
    \Edge[color=green](v)(ui)
    \SetVertexSimple[MinSize=0pt,LineWidth=0pt,LineColor=white,FillColor=white]
    \SetGraphUnit{1}
    %\tikzstyle{EdgeStyle}=[dashed,color=green]% \Edge[color=X] will not work
    %\SetUpEdge[color=black] % \Edge[color=X] will work again but not dashed
    \SOWE(ui){uigh}
    \DashedEdge[color=cyan](ui)(uigh)
    \WE(uim){uimgh}
    \DashedEdge[color=green](uim)(uimgh)
    \NOWE(u3){u3gh}
    \DashedEdge[color=purple](u3)(u3gh)
    \NO(u2){u2gh}
    \DashedEdge[color=brown](u2)(u2gh)
    \NOEA(u1){u1gh}
    \DashedEdge[color=blue](u1)(u1gh)
    \EA(u0){u0gh}
    \DashedEdge[color=red](u0)(u0gh)

    \draw[dotted,thick] ($(uim)+(0.4,0.3)$) -- ($(u3)+(0.2,-0.4)$);
\end{tikzpicture}
\end{document}

Result:

enter image description here

Note that the calc library is used to position the small black dotted line based on the ui-1 and u3 nodes with a small offset horizontally and vertically.

However, this can also be done with regular \node and \draw commands using node names as start and end point for \draw. The advantage is that it is easier to draw empty nodes, and the syntax in general does not affect the tkz-graph settings. The positioning relative to other nodes can be done with the positioning library.

Code:

\documentclass{article}
\usepackage{tkz-graph}
\usetikzlibrary{calc,positioning}
\begin{document}
\begin{tikzpicture}
    \GraphInit[vstyle=Classic]
    \SetGraphUnit{1.5}
    \tikzset{VertexStyle/.style = {shape = circle,fill = black,minimum size = 7,inner sep=0}}
    \SetUpEdge[lw=1.0pt]

    \Vertex[Lpos=270,L=$v$]{v}

    \EA[Lpos=270,L=$u_0$,unit=2](v){u0}
    \Edge[color=black!50](v)(u0)

    \NOEA[L=$u_1$,unit=1.14](v){u1}
    \Edge[color=red](v)(u1)

    \NO[L=$u_2$](v){u2}
    \Edge[color=blue](v)(u2)
    \NOWE[L=$u_3$,unit=1.14](v){u3}
    \Edge[color=brown](v)(u3)

    \WE[Lpos=270,L=$u_{i-1}$](v){uim}
    \Edge[color=purple](v)(uim)

    \SOWE[Lpos=180,L=$u_i$,unit=1.14](v){ui}
    \Edge[color=green](v)(ui)

    \node[right=of u0] (u0ghost) {};
    \node[above right=of u1] (u1ghost) {};
    \node[above=of u2] (u2ghost) {};
    \node[above left=of u3] (u3ghost) {};
    \node[left=of uim] (uimghost) {};
    \node[below left=of ui] (uighost) {};

    \draw[dashed,red,thick] (u0) -- (u0ghost); % u_0
    \draw[dashed,blue,thick] (u1) -- (u1ghost); % u_1
    \draw[dashed,brown,thick] (u2) -- (u2ghost); % u_2
    \draw[dashed,purple,thick] (u3) -- (u3ghost); % u_3
    \draw[dashed,green,thick] (uim) -- (uimghost); % u_{i-1}
    \draw[dashed,thick,cyan] (ui) -- (uighost); % u_i
    \draw[dotted,thick] ($(uim)+(0.4,0.3)$) -- ($(u3)+(0.2,-0.4)$);
\end{tikzpicture}
\end{document}

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.