TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In this 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=9em},
        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},
        link/.style={latex-latex}]
        % Place nodes
        \node [server, outer sep=8pt, align=center] (s1) at (5,8.3) {S1};
        \node [server, outer sep=8pt, align=center] (s2) at (7.65,8.3) {S2};
        \node [server, outer sep=8pt] (s3) at (10.3,8.3) {S3};
        \node [draw=black!50, fit={(s1) (s2) (s3)}] (back) {};
        \node [client] (c1) at (0,9.5) {C1};
        \node [client] (c2) at ($(c1) + (270:1.15)$) {C2};
        \node [client] (c3) at ($(c2) + (270:1.15)$) {C3};
        \node [dot] (c4) at ($(c3) + (270:1)$) {};
        \node [dot] (c5) at ($(c4) + (270:0.5)$) {};
        \node [dot] (c6) at ($(c5) + (270:0.5)$) {};
        \node [draw=black!50, fit={($(c1.north)+(0, 8pt)$) (c2) (c3) (c4) (c5) ($(c6.south)+(0, -7pt)$)}, inner sep=5.75pt] (front) {};
        % Place edges
    \end{tikzpicture}
    \caption{Schema}
\end{figure}

I want to have a separate horizontal edge to connect each of the C1, C2, and C3 with the rectangle node which contains S1, S2 and S3, i.e. the back node in the code above.

If I use \path, the edges are not horizontal, due to the coordinates of C1, C2 and C3 nodes do not line up with the back node.

How should I do it?

share|improve this question
up vote 12 down vote accepted

You can use the orthogonal coordinate system syntax for this. If you say

\draw (c1) -- (c1-|back.west)

you will get a line from node c1 to the point with the y coordinate of c1 and the x coordinate of back.west:

\documentclass[border=5mm]{standalone}

\usepackage{tikz}
\usetikzlibrary{positioning, fit, calc, shapes, arrows}

\begin{document}
    \begin{tikzpicture}
        [title/.style={font=\fontsize{18}{18}\color{black!45}},
        server/.style={rectangle, draw, fill=blue!23, rounded corners, minimum height=9em},
        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},
        link/.style={latex-latex}]
        % Place nodes
        \node [server, outer sep=8pt, align=center] (s1) at (5,8.3) {S1};
        \node [server, outer sep=8pt, align=center] (s2) at (7.65,8.3) {S2};
        \node [server, outer sep=8pt] (s3) at (10.3,8.3) {S3};
        \node [draw=black!50, fit={(s1) (s2) (s3)}] (back) {};
        \node [client] (c1) at (0,9.5) {C1};
        \node [client] (c2) at ($(c1) + (270:1.15)$) {C2};
        \node [client] (c3) at ($(c2) + (270:1.15)$) {C3};
        \node [dot] (c4) at ($(c3) + (270:1)$) {};
        \node [dot] (c5) at ($(c4) + (270:0.5)$) {};
        \node [dot] (c6) at ($(c5) + (270:0.5)$) {};
        \node [draw=red!50, fit={($(c1.north)+(0, 8pt)$) (c2) (c3) (c4) (c5) ($(c6.south)+(0, -7pt)$)}, inner sep=5.75pt] (front) {};
        \draw (c1) -- (c1-|back.west)
            (c2) -- (c2-|back.west)
            (c3) -- (c3-|back.west);
        % Place edges
    \end{tikzpicture}
\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.