9

I'm using the fit package to wrap nodes inside a rectangle, as the code shown below. Is there any way to make some extra space between the node client 3 and the bottom edge of the box?

Code:

\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}
Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036
Skyork
  • 1,147
  • 3
    @GonzaloMedina's answers your question, but if you don't mind having additional spacing all around you could just add inner sep=<amount> to the fit node, or an outer sep=<amount> to one of the client nodes. – Peter Grill Sep 19 '12 at 01:15
  • 1
    Surely it's simpler to set a value for the innner/outer sep values for the fitted node. \node [draw=black!50, inner sep = 1em, fit={(frontend) (client1) (client2) (client3)}] {}; (I couldn't comment for some reason so posted an answer instead) – Carel Nov 05 '13 at 13:18

1 Answers1

14

Using the calc library you can add some value to the y component of the node.

\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}

enter image description here

Gonzalo Medina
  • 505,128
  • thanks for your answer. I am playing with your code, and just wonder how I should apply the same principle to the case where client 1, client 2, and client 3 are placed horizontally in a box. Only increasing their y components does not seem to work, as the width of the outer box shrinks. – Skyork Sep 19 '12 at 01:36
  • 1
    @Skyork sure it works: try `\documentclass{article} \usepackage{tikz} \usetikzlibrary{positioning, fit, calc}

    \begin{document}

    \begin{tikzpicture} [client/.style={rectangle, draw, fill=green!23, rounded corners, minimum height=2em}]
        \node [client] (client1) at (0, 9.25) {Client 1};
        \node [client,right=of client1] (client2) {Client 2};
        \node [client,right=of client2] (client3) {Client 3};
        \node [draw=black!50, fit={(client1) (client2) ($(client3.east)+(0,-20pt)$)}] {};
    \end{tikzpicture}
    
    

    \end{document}`.

    – Gonzalo Medina Sep 19 '12 at 01:42
  • 1
    @Skyork better to use the south east anchor in my previous code; the last node in the fit option should be ($(client3.south east)+(0,-3pt)$). – Gonzalo Medina Sep 19 '12 at 01:49