3

the following code turns out well

\documentclass{minimal}

\usepackage{tikz}
\usepackage{tkz-graph}

\usetikzlibrary{backgrounds}

\begin{document}
    \begin{tikzpicture}[yscale=-.75,xscale=1]
        \GraphInit[vstyle=Empty]
        \Vertex[L=$1$]{1}
        \SOEA[L=$2$](1){2}
        \SOEA[L=$3$](2){3}

        \SOWE[L=$0$](3){14}
        \SOEA[L=$4$](3){24}

        \SOWE[L=$3$](24){15}
        \SOEA[L=$5$](24){25}

        \SOWE[L=$2$](15){16}
        \SOEA[L=$4$](15){26}

        \SOWE[L=$1$](16){17}
        \SOEA[L=$3$](16){27}

        \SOWE[L=$2$](27){18}
        \SOEA[L=$0$](27){28}

        \SOEA[L=$3$](18){19}
        \SOEA[L=$4$](19){110}
        \SOEA[L=$5$](110){111}

        \Edges(1,2,3,24,25,26,27,28,19,110,111)
        \Edges(3,14,15,24)
        \Edges(26,15,16,27)
        \Edges(19,18,17,16,27,18)

        \draw[rounded corners=1em,line width=1.5em,black,opacity=0.2,cap=round]
        (1.center) -- (2.center) -- (3.center) -- (24.center) -- (25.center) (3.center) -- (14.center);
    \end{tikzpicture}
\end{document}

Like so:

have

Now I would like to add some more backgrounds: I tried to depict that with... Paint:

desired

It shall look like the grey background grew further to 3 and then 4. I'd like to have it the same color and same style (with rounding aso.) like the "initial" one, except that it has a small rounded gap. Hope my mouse-drawing skills suffice to make my desire clear.

Thanks in advance.

3
  • Please make sure that your code compiles without errors. The first node is called l instead of 1, which causes errors later on. It also always nice if you make examples into complete documents so that it can be copy-pasted into an editor and compiled without any modification. Aug 3 '16 at 15:22
  • there you go. any solutions?
    – milkpirate
    Aug 3 '16 at 15:40
  • Was more a general comment, but I did think of one possible approach, see below. Aug 3 '16 at 19:01
3

Here's a brute force approach. I draw the shading in the same way as you have done already, then draw a white ellipse over the lower left vertex to simulate the line ending. For the lower of the two new segments I drew a line instead of a circle, to get an even gap all the way.

I also set the VertexStyle explicitly instead of using \GraphInit[vstyle=Empty] to remove the white fill that is used by default.

enter image description here

\documentclass[border=5mm]{standalone}

\usepackage{tikz}
\usepackage{tkz-graph}

\usetikzlibrary{backgrounds}

\begin{document}
    \begin{tikzpicture}[
      yscale=-.75, 
      VertexStyle/.style={} % removes white fill from vertices
    ]

        \Vertex[L=$1$]{1}
        \SOEA[L=$2$](1){2}
        \SOEA[L=$3$](2){3}

        \SOWE[L=$0$](3){14}
        \SOEA[L=$4$](3){24}

        \SOWE[L=$3$](24){15}
        \SOEA[L=$5$](24){25}

        \SOWE[L=$2$](15){16}
        \SOEA[L=$4$](15){26}

        \SOWE[L=$1$](16){17}
        \SOEA[L=$3$](16){27}

        \SOWE[L=$2$](27){18}
        \SOEA[L=$0$](27){28}

        \SOEA[L=$3$](18){19}
        \SOEA[L=$4$](19){110}
        \SOEA[L=$5$](110){111}

        \Edges(1,2,3,24,25,26,27,28,19,110,111)
        \Edges(3,14,15,24)
        \Edges(26,15,16,27)
        \Edges(19,18,17,16,27,18)

    \begin{scope}[
       on background layer, % everything in the environment is drawn behind the vertices
       highlight/.style={rounded corners=1em,line width=1.5em,black,opacity=0.2,cap=round} % same settings you had, in a style for easier reuse
     ]

        \draw [highlight] (15.center) -- (26.center); % draw top shading
        \fill [white] (15.center) circle[x radius=1.em,y radius=1.em/0.75]; % draw white circle on top of the lower left vertex
        \draw [highlight] (15.center) -- (14.center); % repeat for next segment
        \draw [white,cap=round,line width=2em] (14.center) -- (3.center); % 
 %       \fill [white] (14.center) circle[x radius=1.1em,y radius=1.33*1.1em];
        \draw[highlight] % what you had
        (1.center) -- (2.center) -- (3.center) -- (24.center) -- (25.center) (3.center) -- (14.center);
    \end{scope}
    \end{tikzpicture}
\end{document}
3
  • Thats already pretty close to what I'd like to have. Thanks. But is it possible to get the gap evenly spaced? I really would like to stick to the yscale=-.75 but even with yscale=-1 the spacing next to 0 doesnt look that good.
    – milkpirate
    Aug 3 '16 at 19:24
  • @zivimo Better? Aug 3 '16 at 19:40
  • Thats perfect !
    – milkpirate
    Aug 3 '16 at 22:11

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.