我使用fit
包将节点包裹在矩形内,如下面的代码所示。有没有办法在节点client 3
和框的底边之间留出一些额外的空间?
代码:
\usetikzlibrary{positioning, fit, calc, shapes, arrows}
\renewcommand{\figurename}{Figure}
\begin{figure}[!htb]
\centering
\begin{tikzpicture} [title/.style={font=\fontsize{18}{18}\color{black!45}},
server/.style={rectangle, draw, fill=blue!23, rounded corners, minimum height=8em},
client/.style={rectangle, draw, fill=green!23, rounded corners, minimum height=2em},
dot/.style={circle, fill=black, minimum size=2pt, inner sep=0pt, outer sep=2pt}]
% Place nodes
\node [title] (frontend) at (0, 10) {Clients};
\node [client] (client1) at (0, 9.25) {Client 1};
\node [client] (client2) at ($(client1) + (270:1.15)$) {Client 2};
\node [client] (client3) at ($(client2) + (270:1.15)$) {Client 3};
\node [draw=black!50, fit={(frontend) (client1) (client2) (client3)}] {};
\end{tikzpicture}
\caption{Clients graph}
\end{figure}
答案1
使用该calc
库,您可以为节点的 y 组件添加一些值。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning, fit, calc, shapes, arrows}
\renewcommand{\figurename}{Figure}
\begin{document}
\begin{figure}[!htb]
\centering
\begin{tikzpicture} [title/.style={font=\fontsize{18}{18}\color{black!45}},
server/.style={rectangle, draw, fill=blue!23, rounded corners, minimum height=8em},
client/.style={rectangle, draw, fill=green!23, rounded corners, minimum height=2em},
dot/.style={circle, fill=black, minimum size=2pt, inner sep=0pt, outer sep=2pt}]
% Place nodes
\node [title] (frontend) at (0, 10) {Clients};
\node [client] (client1) at (0, 9.25) {Client 1};
\node [client] (client2) at ($(client1) + (270:1.15)$) {Client 2};
\node [client] (client3) at ($(client2) + (270:1.15)$) {Client 3};
\node [draw=black!50, fit={(frontend) (client1) (client2) ($(client3.south)+(0,-3pt)$)}] {};
\end{tikzpicture}
\caption{Clients graph}
\end{figure}
\end{document}