1

I'm having trouble, as the first row does not align very well both horizontally and vertically with the rest of my diagram.

enter image description here

I've tried playing around with left/right but it didn't seem to be of much help. If I just add the add the arrow (\node (b) [right=0.1pt of a] {};), the row's height seems fine:

enter image description here

but the moment I add the label(\node (b) [right=0.1pt of a,label=right:Request] {};), all hell breaks loose.

MVE:

\documentclass[class=minimal,border=0.5cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,arrows,fit}

\begin{document}
\begin{tikzpicture}[
  process_style/.append style={
    rectangle,
    fill=blue!15,
    draw=black,
    thick
  },
  host_style/.append style={
    rectangle,
    draw=black,
    dashed
  }
]

% legend
\matrix [draw,below left] at (20.35, -1.5) {
  \node (a) {};
  \node (c) [left=0.1pt of a] {};
  \node (b) [right=0.1pt of a,label=right:Request] {};
  \draw[stealth-, thick] (b) -- (c);
  \\
  \node [process_style, label=right:Process] {}; \\
  \node [host_style, label=right:Machine] {}; \\
};

\end{tikzpicture}
\end{document}

2 Answers 2

2

One of possible solution is playing around the label notation.

\documentclass[class=minimal,border=0.5cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,arrows,fit}

\begin{document}
\begin{tikzpicture}[
  process_style/.append style={
    rectangle,
    fill=blue!15,
    draw=black,
    thick
  },
  host_style/.append style={
    rectangle,
    draw=black,
    dashed
  }
]

% legend
\matrix [draw,below left] at (20.35, -1.5) {
  \node (a) {};
  \node (c) [left=0.1pt of a] {};
  \node (b) [right=0.1pt of a] {Request};
  \draw[stealth-, thick] (b) -- (c);
  \\[-2.5pt]
  \node [process_style, label=right:Process] {}; \\
  \node [host_style, label=right:Machine] {}; \\
};

\end{tikzpicture}
\end{document}

enter image description here

1

I wrote this part of the code differently:

  \node (a) {};
  \node (c)[left=0.1pt of a] {};
  \node (b)[right=0.1pt of a,label=right:Request] {};
  \draw[stealth-, thick] (b) -- (c);

Indeed, a node that contains nothing has a minimum width of 0.3333em. As your node styles (process_style and host_style) do not specify a width, their width is by default 0.3333em. Instead of starting the arrow at 0.1 pt from node (a), it is easier to start it at (a.west) and end it at (a.east).

That's what gives:

  \node[] (a) {};
  \draw[-stealth, thick] (a.west) -- (a.east) node[right=0.3333em of a,inner sep=0pt]{Request};

Translated with www.DeepL.com/Translator

screenshot

\documentclass[class=minimal,border=0.5cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,arrows,fit}

\begin{document}
\begin{tikzpicture}[
  process_style/.append style={
    rectangle,
    fill=blue!15,
    draw=black,
    thick
  },
  host_style/.append style={
    rectangle,
    draw=black,
    dashed
  }
]

% legend
\matrix [draw,below left] at (20.35, -1.5) {
  \node[] (a) {};
  \draw[-stealth, thick] (a.west) -- (a.east) node[right=0.3333em of a,inner sep=0pt]{Request};
  \\
  \node [process_style, label=right:Process] {};\\
  \node [host_style, label=right:Machine] {};\\
};

\end{tikzpicture}
\end{document}

You must log in to answer this question.

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