3
\documentclass[10pt,journal,compsoc]{IEEEtran}

\usepackage{tikz,pgfplots,pgfplotstable}  

\usetikzlibrary{fit,matrix,positioning,decorations.pathreplacing,calc,shapes,arrows,shadows,patterns}

% correct bad hyphenation here
\hyphenation{op-tical net-works semi-conduc-tor}
\newdimen\zerolinewidth

\begin{document}    
\tikzstyle{redRectangle} = [
rectangle,
draw,
fill=red!20,
node distance=0.65 cm,
text width=7 em,
text centered,
rounded corners,
minimum height=4 em,
minimum width=3 cm,
thick
]

\tikzstyle{blueRectangle} = [
rectangle,
draw,
fill=blue!20,
node distance=1.5 cm,
text width=7 em,
text centered,
rounded corners,
minimum height=4 em,
minimum width=3 cm,
thick
]

\tikzstyle{yellowRectangle} = [
rectangle,
draw,
fill=yellow!20,
node distance=1.5 cm,
text width=7 em,
text centered,
rounded corners,
minimum height=4 em,
minimum width=3 cm,
thick
]

\tikzstyle{greenRectangle} = [
rectangle,
draw,
fill=green!20,
node distance=1.5 cm,
text width=7 em,
text centered,
rounded corners,
minimum height=4 em,
minimum width=3 cm,
thick
]

\tikzstyle{blueDiamond} = [
diamond,
draw,
fill=blue!20,
node distance=1.5 cm,
text width=7 em,
text badly centered,
inner sep=0pt,
thick
]

\tikzstyle{blueEllipse} = [
ellipse,
draw,
fill=blue!20,
node distance=1.5 cm,
text width=7 em,
thick
]

\tikzstyle{container} = [
rectangle,
draw,
inner sep=0.5 cm,
rounded corners 
]

\tikzstyle{empty} = [
]

\tikzstyle{line} = [
draw,
-latex',
thick
]

\begin{tikzpicture}[auto]

\node [empty](origin){};
\node [redRectangle, right=of origin] (aa) {aa};
\node [redRectangle, left=of origin] (bb) {bb};
\node [redRectangle, below=of bb] (cc) {cc};
\node [redRectangle, below=of aa] (dd) {dd};
\path [line] (bb) -- (aa);
\path [line] (bb) -- (cc);
\path [line] (aa) -- (dd);

\node [redRectangle, right=of aa] (pp) {pp};
\node [redRectangle, right=of pp] (rr) {rr};
\node [redRectangle, below right=of pp] (qq) {qq};

\node [container, fit=(aa)(origin)(bb)(cc)(dd)](container1){};
\node [container, fit=(pp)(rr)(qq)](container2){};

\end{tikzpicture}

\end{document}
  1. Wants to increase distance between container1 and containder2 while keeping them next to each other horizontally.
  2. Wants to place node qq below and in the middle of pp and rr.
  3. Wants to place an another container above and in the middle of container1 and containder2.
  4. Wants to draw an another container around all the containers

Any help will be highly appreciable. I am using the given Reference code

  • You are actually loading all the relevant libraries, but you do not use them. With positioning you can say right=2cm of. And the big container can simply be done by \node [container, fit=(container1)(container2)](big container){};. And you may want to replace \tikzstyle by the correspondign \tikzset syntax. – user121799 Jun 10 '18 at 19:36
4

Adaptations:

Short answers to questions:

  1. Use right=15mm of aa to increase the distance.
  2. To draw below in the middle use ($(pp)!.5!(rr) + (0,-2)$).
  3. Create node above and shift it (above=15mm of aa, xshift=20mm) or use notation above (at ($(aa)!.5!(pp) + (0,3)$)).
  4. Just draw container around all others.

Code:

\documentclass[10pt,journal,compsoc]{IEEEtran}

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

\tikzset{
    myRectangle/.style={
        rectangle,
        draw,
        node distance=0.65 cm,
        text width=7 em,
        text centered,
        rounded corners,
        minimum height=4 em,
        minimum width=3 cm,
        thick
    },
    redRectangle/.style={
        myRectangle,
        fill=red!20,
    },
    container/.style={
        rectangle,
        draw,
        inner sep=0.5 cm,
        rounded corners 
    },
    line/.style={
        draw,
        -latex',
        thick
    }
}

\begin{document}

\begin{tikzpicture}[auto]
    \node [](origin){};
    \node [redRectangle, right=of origin] (aa) {aa};
    \node [redRectangle, left=of origin] (bb) {bb};
    \node [redRectangle, below=of bb] (cc) {cc};
    \node [redRectangle, below=of aa] (dd) {dd};
    \path [line] (bb) -- (aa);
    \path [line] (bb) -- (cc);
    \path [line] (aa) -- (dd);

    \node [redRectangle, right=15mm of aa] (pp) {pp}; % question 1
    \node [redRectangle, right=of pp] (rr) {rr};
    \node [redRectangle] (qq) at ($(pp)!.5!(rr) + (0,-2)$) {qq}; % question 2

    \node [container, fit=(aa)(origin)(bb)(cc)(dd)] (container1) {};
    \node [container, fit=(pp)(rr)(qq)] (container2) {};

    % question 3
    \node [redRectangle] (xx) at ($(aa)!.5!(pp) + (0,3)$) {xx};
    \node [container, fit=(xx)] (container3) {};

    % question 4
    \node [container, fit=(container1)(container2)(container3)] (containerAll) {};
\end{tikzpicture}

\end{document}

Result:

enter image description here

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.