3

enter image description hereI have the following code, but the node is always hidden by the vertical line. How can I solve this (world and first are hidden by the vertical line)?

       \documentclass[]{article}
    \usepackage{tikz}
    \usetikzlibrary{calc}
    %opening
    \title{}
    \author{}

    \begin{document}

    \maketitle

    \begin{abstract}

    \end{abstract}

    \section{}




\pgfdeclarelayer{-1}
\pgfsetlayers{-1,main}
\tikzset{zlevel/.style={%
        execute at begin scope={\pgfonlayer{#1}},
        execute at end scope={\endpgfonlayer}
}}

\tikzset{every picture/.style=thick}
\begin{figure}[h]
    \begin{tikzpicture}[
    scale=0.6, every node/.style={scale=0.6}
    ,every node/.append style={very thick,rounded corners=0.1mm}
    ]
    %\begin{pgfonlayer}{tp}    % select the background layer

    \node[draw,rectangle] (Server) at (9,0) {Remote};

    \begin{scope}[zlevel=main]
    \node[draw=blue!50,rectangle,thick] (Network) at (0,-1) {first};
    \end{scope}

    \node[draw,rectangle] (User) at (0,0) {brocken};
    \begin{scope}[zlevel=-1]
\draw [] (User)  --  (Network)--(0,-10);
\end{scope}

    %obj1
    \begin{scope}[zlevel=main]
    \node[draw=blue!50,rectangle,thick] (Network) at (0,-2.5) {world};
    \end{scope}
    %\end{pgfonlayer}

    \node[draw=blue!60, rectangle,thick] (Network) at (0,-4.5) {hallo};

    \begin{scope}[zlevel=-1]
    \draw [very thick] (Server)--++(0,-10);
    \end{scope}
    \end{tikzpicture}
\end{figure}
\end{document}
4
  • 3
    Your code is not compileable. Give a complete and compileable code that starts with \documentclass{} and ends with \end{document}
    – AndréC
    Dec 10, 2018 at 4:21
  • 1
    This doesn't need anything fancy (apart from compilable code:). If you draw the line before you draw the nodes then the nodes will be on top.
    – user30471
    Dec 10, 2018 at 6:22
  • As @Andrew mentions, you only need to draw things in the right order. If you do not want to do that, or your example is very complex and you cannot do it, you might be interested in this answer in which a way to prevent drawing over a given node is presented.
    – user121799
    Dec 10, 2018 at 6:42
  • I have updated the code that is compilable. now i have changed the order, i put the drawing line first, but still it hide the text i wrote.
    – sunxd
    Dec 10, 2018 at 12:59

2 Answers 2

3

I'm sure there are better solutions for this problem, but you can just draw your line first (as suggested in the comments) and then fill the rectangle with white.

\documentclass[]{article}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}
\pgfdeclarelayer{-1}
\pgfsetlayers{-1,main}
\tikzset{zlevel/.style={%
        execute at begin scope={\pgfonlayer{#1}},
        execute at end scope={\endpgfonlayer}
}}

\tikzset{every picture/.style=thick}
\begin{figure}[h]
    \begin{tikzpicture}[
    scale=0.6, every node/.style={scale=0.6},every node/.append style={very thick,rounded corners=0.1mm}]
    \draw (0,-1)  --  (0,0)--(0,-10);
    \node[draw,rectangle, fill=white] (Server) at (9,0) {Remote};
    \begin{scope}[zlevel=main]
        \node[draw=blue!50,rectangle,thick, fill=white] (Network) at (0,-1) {first};
    \end{scope}
    \node[draw,rectangle,fill=white] (User) at (0,0) {brocken};

    %obj1
    \begin{scope}[zlevel=main, fill=white]
        \node[draw=blue!50,rectangle,thick, fill=white] (Network) at (0,-2.5) {world};
    \end{scope}
    \node[draw=blue!60, rectangle,thick, fill=white] (Network) at (0,-4.5) {hallo};
    \begin{scope}[zlevel=-1]
        \draw [very thick, fill=white] (Server)--++(0,-10);
    \end{scope}
    \end{tikzpicture}
\end{figure}
\end{document}

enter image description here

3

By default, nodes (as well as figures) do not have a background.

I quote from page 126 of the manual:

12.2.4 Adding a Background

By default, pictures do not have any background, that is, they are transparent on all parts on which you do not draw anything.

I quote from page 214 of the manual:

17.2 Nodes and Their Shapes

In the simplest case, a node is just some text that is placed at some coordinate. However, a node can also have a border drawn around it or have a more complex background and foreground. Indeed, some nodes do not have a text at all, but consist solely of the background.

Here is an illustrated example copied from page 1081 of the manual to which I added two nodes.

It has a node placed on the foreground layer called foreground. I added two nodes

  1. main placed on the main layer
  2. and back placed on the background layer.

backgrounds

You can see that all the nodes show everything that is drawn below because their background is transparent.

So you must, as @Sito said, add a background to the nodes so that nothing can show through below.

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.