5

I would like the rectangle surrounding the nodes C_{32} and C_{23} to just encompass these nodes like C_{12} and C_{22}

My code is as follows: I have managed to rotate the rectangle but the rectangle overfits

\documentclass{article}
\pagestyle{empty}
\usepackage{tikz}
\usetikzlibrary{fit}
\usetikzlibrary{patterns}
\tikzset{
    vertex/.style={
        fill,
        shape=circle,
        node distance=80pt},
    edge/.style={
        fill,
        opacity=.2,
        fill opacity=.5,
        line cap=round,
        line join=round,
        line width=20pt},
    elabel/.style={
        fill,
        shape=circle,
        node distance=30pt,
        opacity = .2}
}

\pgfdeclarelayer{background}
\pgfsetlayers{background,main}

\begin{document}

    \begin{tikzpicture}
    \begin{pgfonlayer}{background}

    %Task T1

    \node[vertex,label={[font = \Large]above:\(C_{11}, \$30\)}] (v1) {};

    \node[vertex,right of=v1,label={[font = \Large]above:\(C_{12}, \$10\)}] (v2) {};

    \node[vertex,right of=v2,label={[font = \Large]above:\(C_{13}, \$25\)}] (v3) {};

    \node[vertex,right of=v3,label={[font = \Large]above:\(C_{14}, \$15\)}] (v4) {};

    \node[vertex,right of=v4,label={[font = \Large]above:\(C_{15}, \$15\)}] (v5) {};


    %Task T2

    \node[vertex,below of=v1,label={[font = \Large]above:\(C_{21}\)}] (v6) {};

    \node[vertex,right of=v6,label={[font = \Large]above:\(C_{22}, \$10\)}] (v7) {};

    \node[vertex,right of=v7,label={[font = \Large]above:\(C_{23}, \$15\)}] (v8) {};

    \node[vertex,right of=v8,label={[font = \Large]above:\(C_{24}, \$20\)}] (v9) {};

    \node[vertex,right of=v9,label={[font = \Large]above:\(C_{25}, \$15\)}] (v10) {};

    %Task T3

    \node[vertex,below of=v6,label={[font = \Large]above:\(C_{31}\)}] (v11) {};

    \node[vertex,right of=v11,label={[font = \Large]above:\(C_{32}, \$15\)}] (v12) {};

    \node[vertex,right of=v12,label={[font = \Large]above:\(C_{33}, \$15\)}] (v13) {};

    \node[vertex,right of=v13,label={[font = \Large]above:\(C_{34}, \$15\)}] (v14) {};



    %Edges

    \draw[edge,color=green] (v6) -- (v11);

    \draw[edge,color=blue] (v2) -- (v7);

    \draw[edge,color=violet] (v8) -- (v12);

    \draw[edge,color=cyan] (v4) -- (v9) -- (v13);

    \draw[edge,color=orange] (v5) -- (v10) -- (v14);



    \end{pgfonlayer}

    %Labels

    \node[elabel,color=green,label=right:\(\$50\)]  (e1) at (0,-7) {};
    \node[elabel, color=blue,label=right:\(\$15\)]  (e2) at (1.5, -7) {};
    \node[elabel,color=violet,label=right:\(\$15\)]  (e3) at (3,-7) {};
    \node[elabel,color=cyan,label=right:\(\$40\)]  (e4) at (4.5, -7) {};
    \node[elabel,color=orange, label=right:\(\$30\)]  (e5) at (6.0,-7) {};


    %Task nodes

    \node[left of=v1,label={[font = \Large]above:Task \( T_1\)}, rotate = 90] (t1) {};

    \node[left of=v6,label={[font = \Large]above:Task \(T_2\)}, rotate = 90] (t2) {};

    \node[left of=v11,label={[font = \Large]above:Task \(T_3\)}, rotate = 90] (t3) {};


    %\draw (-1,1.2) rectangle (1,-9.8);

    \node [draw, fit=(v1)(v5), inner sep=28pt] {};
    \node [draw, fit=(v6)(v10), inner sep=28pt] {};
    \node [draw, fit=(v11)(v14), inner sep=28pt] {};

    %Edge Composition Constraint

    \node [draw, fit=(v2)(v7), inner sep=20pt] {};
    \node [draw, fit=(v8)(v12), rotate fit=45, inner sep = 12pt] {};    

    \end{tikzpicture}
\end{document}

Rendered Image

7

The order matters. You have to mention rotate fit=<angle> before fit=<coordinates>.

\node [draw, rotate fit=45, fit=(v8)(v12),  inner sep = 12pt] {};    

enter image description here

The complete code:

\documentclass{article}
\pagestyle{empty}
\usepackage{tikz}
\usetikzlibrary{fit}
\usetikzlibrary{patterns}
\tikzset{
    vertex/.style={
        fill,
        shape=circle,
        node distance=80pt},
    edge/.style={
        fill,
        opacity=.2,
        fill opacity=.5,
        line cap=round,
        line join=round,
        line width=20pt},
    elabel/.style={
        fill,
        shape=circle,
        node distance=30pt,
        opacity = .2}
}

\pgfdeclarelayer{background}
\pgfsetlayers{background,main}

\begin{document}

    \begin{tikzpicture}
    \begin{pgfonlayer}{background}

    %Task T1

    \node[vertex,label={[font = \Large]above:\(C_{11}, \$30\)}] (v1) {};

    \node[vertex,right of=v1,label={[font = \Large]above:\(C_{12}, \$10\)}] (v2) {};

    \node[vertex,right of=v2,label={[font = \Large]above:\(C_{13}, \$25\)}] (v3) {};

    \node[vertex,right of=v3,label={[font = \Large]above:\(C_{14}, \$15\)}] (v4) {};

    \node[vertex,right of=v4,label={[font = \Large]above:\(C_{15}, \$15\)}] (v5) {};


    %Task T2

    \node[vertex,below of=v1,label={[font = \Large]above:\(C_{21}\)}] (v6) {};

    \node[vertex,right of=v6,label={[font = \Large]above:\(C_{22}, \$10\)}] (v7) {};

    \node[vertex,right of=v7,label={[font = \Large]above:\(C_{23}, \$15\)}] (v8) {};

    \node[vertex,right of=v8,label={[font = \Large]above:\(C_{24}, \$20\)}] (v9) {};

    \node[vertex,right of=v9,label={[font = \Large]above:\(C_{25}, \$15\)}] (v10) {};

    %Task T3

    \node[vertex,below of=v6,label={[font = \Large]above:\(C_{31}\)}] (v11) {};

    \node[vertex,right of=v11,label={[font = \Large]above:\(C_{32}, \$15\)}] (v12) {};

    \node[vertex,right of=v12,label={[font = \Large]above:\(C_{33}, \$15\)}] (v13) {};

    \node[vertex,right of=v13,label={[font = \Large]above:\(C_{34}, \$15\)}] (v14) {};



    %Edges

    \draw[edge,color=green] (v6) -- (v11);

    \draw[edge,color=blue] (v2) -- (v7);

    \draw[edge,color=violet] (v8) -- (v12);

    \draw[edge,color=cyan] (v4) -- (v9) -- (v13);

    \draw[edge,color=orange] (v5) -- (v10) -- (v14);



    \end{pgfonlayer}

    %Labels

    \node[elabel,color=green,label=right:\(\$50\)]  (e1) at (0,-7) {};
    \node[elabel, color=blue,label=right:\(\$15\)]  (e2) at (1.5, -7) {};
    \node[elabel,color=violet,label=right:\(\$15\)]  (e3) at (3,-7) {};
    \node[elabel,color=cyan,label=right:\(\$40\)]  (e4) at (4.5, -7) {};
    \node[elabel,color=orange, label=right:\(\$30\)]  (e5) at (6.0,-7) {};


    %Task nodes

    \node[left of=v1,label={[font = \Large]above:Task \( T_1\)}, rotate = 90] (t1) {};

    \node[left of=v6,label={[font = \Large]above:Task \(T_2\)}, rotate = 90] (t2) {};

    \node[left of=v11,label={[font = \Large]above:Task \(T_3\)}, rotate = 90] (t3) {};


    %\draw (-1,1.2) rectangle (1,-9.8);

    \node [draw, fit=(v1)(v5), inner sep=28pt] {};
    \node [draw, fit=(v6)(v10), inner sep=28pt] {};
    \node [draw, fit=(v11)(v14), inner sep=28pt] {};

    %Edge Composition Constraint

    \node [draw, fit=(v2)(v7), inner sep=20pt] {};
    \node [draw, rotate fit=45, fit=(v8)(v12),  inner sep = 12pt] {};    

    \end{tikzpicture}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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