tikz 中的节点放置

tikz 中的节点放置
\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. 想要增加容器 1 和容器 2 之间的距离,同时保持它们在水平方向上彼此相邻。
  2. 想要将节点 qq 放置在 pp 和 rr 的中间下方。
  3. 想要在容器 1 和容器 2 的上方和中间放置另一个容器。
  4. 想要在所有容器周围绘制另一个容器

任何帮助都将不胜感激。我正在使用给定的参考代码

答案1

改编:

问题简短回答:

  1. 用于right=15mm of aa增加距离。
  2. 要在中间下方绘制,请使用($(pp)!.5!(rr) + (0,-2)$)
  3. 创建上面的节点并将其移动(above=15mm of aa, xshift=20mm)或使用上面的符号(at ($(aa)!.5!(pp) + (0,3)$))。
  4. 只需在所有其他容器周围绘制容器即可。

代码:

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

结果:

在此处输入图片描述

相关内容