3

I would like to draw a path of grey along the tiks nodes of my lattices. I tried with drawing double line and filling them, but it didn't look right. Then I found this:

How do I draw a path of grey background through elements of a matrix?

It seem cleaner than what I did, but the problem of look stay the same. I'll post what I have now.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{url}
\usepackage{enumitem}
\usepackage{xcolor}
\usepackage{color}
\usepackage{hyperref}
\usepackage{fancyhdr}
\usepackage{titlesec}
\usepackage{tikz}
\usetikzlibrary{shapes}
\usepackage[margin=1.3in]{geometry}
\setlength{\skip\footins}{1cm}

\begin{document}

\begin{center}
\begin{tikzpicture}[node distance=2cm, strip/.style={draw=gray, rounded corners=1mm, line width=1.5cm, opacity=0.5, line cap=round }]

    \tikzset{
    every node/.style={
        draw=black, circle, circle,minimum size=1cm, fill=orange, fill opacity=0.8, text opacity=1
    }}

    % First, locate each of the nodes and name them
    \node [] (void) at (0,0) {$\varnothing$};

    \node [above  of=void] (y)  {$y$};
    \node [left  of=y] (x) {$x$};
    \node [right of=y] (z) {$z$};

    \node [above of=x] (xy) {$xy$};
    \node [above of=y] (xz) {$xz$};
    \node [above of=z] (yz) {$yz$};

    \node [above of=xz] (xyz) {$xyz$};

    %Testfield
    \draw [double distance = 1.3cm, thin, opacity=0.5, line cap=round] (void) -- (x) -- (xy) -- (xyz);

    % First, locate each of the nodes and name them
    \node [] (void) at (0,0) {$\varnothing$};

    \node [above  of=void] (y)  {$y$};
    \node [left  of=y] (x) {$x$};
    \node [right of=y] (z) {$z$};

    \node [above of=x] (xy) {$xy$};
    \node [above of=y] (xz) {$xz$};
    \node [above of=z] (yz) {$yz$};

    \node [above of=xz] (xyz) {$xyz$};

    % Now draw the lines:
    \draw [black, thick] (void) -- (x);
    \draw [black, thick] (void) -- (y);
    \draw [black, thick] (void) -- (z);

    \draw [black, thick] (x) -- (xy);
    \draw [black, thick] (y) -- (xy);

    \draw [black, thick] (x) -- (xz);
    \draw [black, thick] (z) -- (xz);

    \draw [black, thick] (y) -- (yz);
    \draw [black, thick] (z) -- (yz);

    \draw [black, thick] (xy) -- (xyz);
    \draw [black, thick] (xz) -- (xyz);
    \draw [black, thick] (yz) -- (xyz);

\end{tikzpicture}
\end{center}

\end{document}

I also used some shenanigans so that the grey is in the background, but I was planning on cleaning that up when I had what I wanted.

  • 1
    Welcome to new site of TeX.SE. Please, can you add your complete code starting from \documentclass? – Sebastiano Aug 9 '18 at 20:41
  • 2
    Try \draw[strip,transform canvas={xshift=-0.5mm}] (void.south east) -- (x.south) -- (xy.north) -- (xyz.north east); – user121799 Aug 9 '18 at 20:48
  • It's a lot better! But they still aren't quite aligned. – ZelteHonor Aug 9 '18 at 20:52
6

The correct answer is the one by J. Leon V., who does what Zarko did in his nice answer, namely used the centers. Here are some additional suggestions:

  • Put the contour on the background.
  • Blur the boundary a bit.
  • Simplify the connections.

Here is the result.

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{backgrounds}
\usepackage{amssymb}
\begin{document}
\begin{tikzpicture}[node distance=2cm] 
\tikzset{strip/.style={draw=gray!40, rounded corners=1mm, line width=1.5cm,opacity=0.5, 
line cap=round,on background layer,
postaction={draw=gray!50,opacity=0.5,rounded corners=1mm, line width=1.46cm,line
cap=round},
postaction={draw=gray!60,opacity=0.5,rounded corners=1mm, line width=1.42cm,line
cap=round},
postaction={draw=gray!70,opacity=0.5,rounded corners=1mm, line width=1.38cm,line
cap=round},
postaction={draw=gray!80,opacity=0.5,rounded corners=1mm, line width=1.34cm,line
cap=round}}}

    \tikzset{
    every node/.style={
        draw=black, circle, circle,minimum size=1cm, fill=orange, fill opacity=0.8, text opacity=1
    }}


    % First, locate each of the nodes and name them
    \node [] (void) at (0,0) {$\varnothing$};

    \node [above  of=void] (y)  {$y$};
    \node [left  of=y] (x) {$x$};
    \node [right of=y] (z) {$z$};

    \node [above of=x] (xy) {$xy$};
    \node [above of=y] (xz) {$xz$};
    \node [above of=z] (yz) {$yz$};

    \node [above of=xz] (xyz) {$xyz$};

    %Testfield

    % I guess in Zarko's nice answer ,transform canvas={xshift=-0.5mm}
    % was for the bounding box. It would actually have been easier to use
    % overlay, which just interrupts the bounding box
    \draw[strip] (void.center) 
    -- (x.center) -- (xy.center) --
    (xyz.center);

    % First, locate each of the nodes and name them
    \node [] (void) at (0,0) {$\varnothing$};

    \node [above  of=void] (y)  {$y$};
    \node [left  of=y] (x) {$x$};
    \node [right of=y] (z) {$z$};

    \node [above of=x] (xy) {$xy$};
    \node [above of=y] (xz) {$xz$};
    \node [above of=z] (yz) {$yz$};

    \node [above of=xz] (xyz) {$xyz$};

    % Now draw the lines:
    \begin{scope}[black, thick]
    \draw  (void) edge (x) edge (y) edge (z);
    \draw  (x) -- (xy) -- (y);
    \draw  (x) -- (xz) -- (z);
    \draw  (y) -- (yz) -- (z);
    \draw  (xyz) edge (xy) edge (xz) edge (yz);
    \end{scope}

\end{tikzpicture}
\end{document}

enter image description here

5

The error you make is that you draw lines between nodes instead of coordinates.

RESULT:

enter image description here

MWE:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\usepackage{amssymb}
\begin{document}
    \begin{tikzpicture}[
        %Environment config
        node distance=2cm,
        %Environment Styles
        strip/.style={
            draw=gray,
            rounded corners=1mm,
            line width=1.3cm,
            opacity=0.5, line cap=round
        },
        every node/.style={
            draw=black,
            circle,
            minimum size=1cm,
            fill=orange,
            fill opacity=0.8,
            text opacity=1
        }
    ]
    % First, locate each of the nodes and name them
    \node [] (void) at (0,0) {$\varnothing$};
    \node [above  of=void] (y)  {$y$};
    \node [left  of=y] (x) {$x$};
    \node [right of=y] (z) {$z$};
    \node [above of=x] (xy) {$xy$};
    \node [above of=y] (xz) {$xz$};
    \node [above of=z] (yz) {$yz$};
    \node [above of=xz] (xyz) {$xyz$};
    % Now draw the lines:
    \draw [black, thick] % Here you draw a line between nodes, each line start and end in the shape
    (xz)
        edge (xyz)
        edge (x)
        edge (z)
    (y)
        edge (xy)
        edge (yz)
        edge (void)
    (void)
        -- (x)
        -- (xy)
        -- (xyz)
        -- (yz)
        -- (z)
        -- (void)   ;

    \draw[strip] % (nodename.center) gives a coordinate from the center of the node, and the line is continuous
    (void.center) 
        -- (x.center)
        -- (xy.center)
        -- (xyz.center);

    \end{tikzpicture}
\end{document}

UPDATE

To not shade the nodes the line is drawn in the background layer (as I observed in @marmot's answer, and then in the rest to not stay behind.):

RESULT: enter image description here

MWE:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\usepackage{amssymb}
\begin{document}
    \begin{tikzpicture}[
        %Environment config
        node distance=2cm,
        %Environment Styles
        strip/.style={
            draw=gray,
            rounded corners=1mm,
            line width=1.3cm,
            opacity=0.5, line cap=round
        },
        every node/.style={
            draw=black,
            circle,
            minimum size=1cm,
            fill=orange,
            fill opacity=0.8,
            text opacity=1
        }
    ]
    % First, locate each of the nodes and name them
    \node [] (void) at (0,0) {$\varnothing$};
    \node [above  of=void] (y)  {$y$};
    \node [left  of=y] (x) {$x$};
    \node [right of=y] (z) {$z$};
    \node [above of=x] (xy) {$xy$};
    \node [above of=y] (xz) {$xz$};
    \node [above of=z] (yz) {$yz$};
    \node [above of=xz] (xyz) {$xyz$};
    % Now draw the lines:
    \draw [black, thick] % Here you draw a line between nodes, each line start and end in the shape
    (xz)
        edge (xyz)
        edge (x)
        edge (z)
    (y)
        edge (xy)
        edge (yz)
        edge (void)
    (void)
        -- (x)
        -- (xy)
        -- (xyz)
        -- (yz)
        -- (z)
        -- (void)   ;
    \begin{scope}[on background layer]  
    \draw[strip] % (nodename.center) gives a coordinate from the center of the node, and the line is continuous
    (void.center) 
        -- (x.center)
        -- (xy.center)
        -- (xyz.center);
    \end{scope}
    \end{tikzpicture}
\end{document}
  • 1
    Done, and nice 3d marmot... – J Leon V. Aug 10 '18 at 2:56
4

Just for comparison, here is a Metapost alternative. Compile with lualatex for the luamplib support.

enter image description here

\documentclass[border=5mm]{standalone}
\usepackage{luatex85}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);

    path s, ss;
    s = unitsquare scaled 70.71 rotated 45;
    ss = s shifted 50 up;   

    draw point 0 of s -- point 3 of s -- point 3 of ss -- point 2 of ss
        withpen pencircle scaled 32 
        withcolor 3/4 white;

    draw s; draw ss; 
    for i=0 upto 3: 
        draw point i of s -- point i of ss; 
    endfor

    vardef node(expr t, p) = 
        fill fullcircle scaled 24 shifted p withcolor red + 1/2 green;
        draw fullcircle scaled 24 shifted p;
        label(t, p);
    enddef;

    node("$\emptyset$", point 0 of s);
    node("$x$",   point 3 of s);
    node("$z$",   point 1 of s);
    node("$xz$",  point 2 of s);
    node("$y$",   point 0 of ss);
    node("$xy$",  point 3 of ss);
    node("$yz$",  point 1 of ss);
    node("$xyz$", point 2 of ss);

endfig;
\end{mplibcode}
\end{document}

Note that this one is quite hard to adapt to plain old mpost; the \mplibtextextlabel{enable} setting makes it much simpler to create the node function, as the strings get compiled as TeX automatically.

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.