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}
2
  • 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. Commented Sep 19, 2012 at 1: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
    Commented Nov 5, 2013 at 13:18

1 Answer 1

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

3
  • 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
    Commented Sep 19, 2012 at 1: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}. Commented Sep 19, 2012 at 1: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)$). Commented Sep 19, 2012 at 1:49

You must log in to answer this question.

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