在当前虚线框旁边添加一个新的虚线框

在当前虚线框旁边添加一个新的虚线框

在此处输入图片描述

我需要添加第二个虚线框和中间的“updateRate”框以及转换框。我尝试添加第二个框,但失败了。我确实添加了以下两行代码:

\node[fit=(tAmount)(convert)(subFromrOwned)(subFromrTotal), dotted, draw=black, inner sep=1em] (dottedbox2) {};
\node[anchor=northwest, xshift=-1em] (TX2) at (dottedbox1.north west) {TX1};
\end{tikzpicture}

但它没有起到作用:(

在此处输入图片描述

梅威瑟:

\documentclass{standalone}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage{amsmath, amssymb}

\usetikzlibrary{positioning, fit, arrows.meta, calc}

\begin{document}

\tikzset{
  basic/.style={
    draw,
    rectangle,
    minimum width=9em,
    text centered
  },
  placeholder/.style={
    basic,
    draw=white
  },
  arrsty/.style={
    draw=black,
    -latex
  }
}

% use sans serif font by default
\begin{tikzpicture}[every node/.style={font=\sffamily}]
\node[basic] (tAmount) {tAmount};
\node[basic, below=of tAmount] (tTransferAmount) {tTransferAmount};
\node[basic, right=of tTransferAmount] (tFee) {tFee};

\node[below=of tTransferAmount] (anchor1) {};
% compute the center point of tTransferAmount and tFee
\coordinate (point1) at ($0.5*(tTransferAmount.east)+0.5*(tFee.west)$);
\node[basic, minimum width=7em, text width=7em] (addTotOwned) at (anchor1.center-|point1) {Add to\\tOwned[receipt]};


\node[placeholder, left=of tTransferAmount] (anchor2) {};
% place the other node symmetricly
\coordinate (point2) at ($0.5*(anchor2.east)+0.5*(tTransferAmount.west)$);
\node[basic, minimum width=7em, text width=7em, text centered] (subFromtOwned) at (anchor1.center-|point2) {Subtract from\\tOwned[receipt]};


\node (anchor3) at ($0.5*(addTotOwned.east)+0.5*(subFromtOwned.west)$) {};
\node[basic, below=of anchor3, minimum width=32.8em] (convert) {convert(r$=$rate$\times$t)};

% draw some arrows and put the text in
\path[arrsty] (tAmount)-|(anchor2.center)--(convert.north-|anchor2.center);
\path[arrsty] (tAmount)--node[midway, xshift=1.2em, font=\sffamily\bfseries\small] (ninety-perct) {90\%} (tTransferAmount);
\path[arrsty] (tAmount)-|(tFee);
\path[arrsty] (tFee)--(convert.north-|tFee.center);
\node[xshift=1.2em, font=\sffamily\bfseries\small] at (ninety-perct-|tFee.center) {10\%};
\path[arrsty] (anchor2.center)-| node[pos=0.8, left] {(1)} (subFromtOwned);
\path[arrsty] (tTransferAmount)-| node[pos=0.8, left] {(2)} (addTotOwned);


\node[basic, below=of convert] (rTransferAmount) {rTransferAmount};
\node[basic] (rAmount) at (rTransferAmount-|anchor2.center) (rAmount) {rAmount};
\node[basic] (rFee) at (rTransferAmount-|tFee.center) {rFee};
\node[basic, below=of rAmount, text width=8em] (subFromrOwned) {Subtract from\\rOwned[sender]};
\node[basic, below=of rTransferAmount, text width=8em] (addTorOwned) {Add to\\rOwned[recipent]};
\node[basic, below=of rFee, text width=8em] (subFromrTotal) {Subtract from\\rTotal};

% draw arrows
\path[arrsty] (convert.south-|rAmount)--(rAmount);
\path[arrsty] (convert.south-|rTransferAmount)--(rTransferAmount);
\path[arrsty] (convert.south-|rFee)--(rFee);
\path[arrsty] (rAmount)--(subFromrOwned);
\path[arrsty] (rTransferAmount)--(addTorOwned);
\path[arrsty] (rFee)--(subFromrTotal);

% outer dotted box
\node[fit=(tAmount)(convert)(subFromrOwned)(subFromrTotal), dotted, draw=black, inner sep=1em] (dottedbox1) {};
\node[anchor=north east, xshift=-1em] (TX1) at (dottedbox1.north west) {TX1};
\end{tikzpicture}

\node[fit=(tAmount)(convert)(subFromrOwned)(subFromrTotal), dotted, draw=black, inner sep=1em] (dottedbox2) {};
\node[anchor=northwest, xshift=-1em] (TX2) at (dottedbox1.north west) {TX1};
\end{tikzpicture}

\end{document}

答案1

我确实将字体大小减小到tiny

 \tikzset{every node}=[font=\tiny]

以及带有圆角和红色/绿色的拟合线

 \node[fit=(tAmount)(convert)(subFromrOwned)(subFromrTotal), dotted, draw=red, inner sep=1em, ultra thick, rounded corners] (dottedbox1) {};

对于中间的框

\node[basic, right=2em of subFromrTotal ] (ttAmount) {tAmount};

对于左侧的箭头使用

\path[arrsty] (subFromrTotal)--(ttAmount);

对于右侧的箭头使用

\path[arrsty] (ttAmount.east)--++(1em,0em)|-(convert);

在此处输入图片描述

完成 MWE

\documentclass{standalone}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage{amsmath, amssymb}

\usetikzlibrary{positioning, fit, arrows.meta, calc}

\begin{document}

\tikzset{
  basic/.style={
    draw,
    rectangle,
    minimum width=9em,
    text centered
  },
  placeholder/.style={
    basic,
    draw=white
  },
  arrsty/.style={
    draw=black,
    -latex
  }
}

% use sans serif font by default
\begin{tikzpicture}[every node/.style={font=\sffamily}]
 \tikzset{every node}=[font=\tiny]

\begin{scope}[local bounding box=left,]

[every node/.style={font=\sffamily}]
\node[basic] (tAmount) {tAmount};
\node[basic, below=of tAmount] (tTransferAmount) {tTransferAmount};
\node[basic, right=of tTransferAmount] (tFee) {tFee};

\node[below=of tTransferAmount] (anchor1) {};
% compute the center point of tTransferAmount and tFee
\coordinate (point1) at ($0.5*(tTransferAmount.east)+0.5*(tFee.west)$);
\node[basic, minimum width=7em, text width=7em] (addTotOwned) at (anchor1.center-|point1) {Add to\\tOwned[receipt]};


\node[placeholder, left=of tTransferAmount] (anchor2) {};
% place the other node symmetricly
\coordinate (point2) at ($0.5*(anchor2.east)+0.5*(tTransferAmount.west)$);
\node[basic, minimum width=7em, text width=7em, text centered] (subFromtOwned) at (anchor1.center-|point2) {Subtract from\\tOwned[receipt]};


\node (anchor3) at ($0.5*(addTotOwned.east)+0.5*(subFromtOwned.west)$) {};
\node[basic, below=of anchor3, minimum width=32.8em] (convert) {convert(r$=$rate$\times$t)};

% draw some arrows and put the text in
\path[arrsty] (tAmount)-|(anchor2.center)--(convert.north-|anchor2.center);
\path[arrsty] (tAmount)--node[midway, xshift=1.2em, font=\sffamily\bfseries\small] (ninety-perct) {90\%} (tTransferAmount);
\path[arrsty] (tAmount)-|(tFee);
\path[arrsty] (tFee)--(convert.north-|tFee.center);
\node[xshift=1.2em, font=\sffamily\bfseries\small] at (ninety-perct-|tFee.center) {10\%};
\path[arrsty] (anchor2.center)-| node[pos=0.8, left] {(1)} (subFromtOwned);
\path[arrsty] (tTransferAmount)-| node[pos=0.8, left] {(2)} (addTotOwned);


\node[basic, below=of convert] (rTransferAmount) {rTransferAmount};
\node[basic] (rAmount) at (rTransferAmount-|anchor2.center) (rAmount) {rAmount};
\node[basic] (rFee) at (rTransferAmount-|tFee.center) {rFee};
\node[basic, below=of rAmount, text width=8em] (subFromrOwned) {Subtract from\\rOwned[sender]};
\node[basic, below=of rTransferAmount, text width=8em] (addTorOwned) {Add to\\rOwned[recipent]};
\node[basic, below=of rFee, text width=8em] (subFromrTotal) {Subtract from\\rTotal};

% draw arrows
\path[arrsty] (convert.south-|rAmount)--(rAmount);
\path[arrsty] (convert.south-|rTransferAmount)--(rTransferAmount);
\path[arrsty] (convert.south-|rFee)--(rFee);
\path[arrsty] (rAmount)--(subFromrOwned);
\path[arrsty] (rTransferAmount)--(addTorOwned);
\path[arrsty] (rFee)--(subFromrTotal);

% outer dotted box
\node[fit=(tAmount)(convert)(subFromrOwned)(subFromrTotal), dotted, draw=red, inner sep=1em, ultra thick, rounded corners] (dottedbox1) {};
\node[anchor=north east, xshift=-1em] (TX1) at (dottedbox1.north west) {TX1};
 \node[basic, right=2em of subFromrTotal ] (ttAmount) {tAmount};

\path[arrsty] (subFromrTotal)--(ttAmount);

 \end{scope} 


% \node[fit=(tAmount)(convert)(subFromrOwned)(subFromrTotal), dotted, draw=black, inner sep=1em] (dottedbox2) {};
% \node[anchor=northwest, xshift=-1em] (TX2) at (dottedbox1.north west) {TX1};
% \end{tikzpicture}
 \begin{scope}[local bounding box=right, xshift=12cm] 

 \node[basic] (tAmount) {tAmount};
\node[basic, below=of tAmount] (tTransferAmount) {tTransferAmount};
\node[basic, right=of tTransferAmount] (tFee) {tFee};

\node[below=of tTransferAmount] (anchor1) {};
% compute the center point of tTransferAmount and tFee
\coordinate (point1) at ($0.5*(tTransferAmount.east)+0.5*(tFee.west)$);
\node[basic, minimum width=7em, text width=7em] (addTotOwned) at (anchor1.center-|point1) {Add to\\tOwned[receipt]};


\node[placeholder, left=of tTransferAmount] (anchor2) {};
% place the other node symmetricly
\coordinate (point2) at ($0.5*(anchor2.east)+0.5*(tTransferAmount.west)$);
\node[basic, minimum width=7em, text width=7em, text centered] (subFromtOwned) at (anchor1.center-|point2) {Subtract from\\tOwned[receipt]};


\node (anchor3) at ($0.5*(addTotOwned.east)+0.5*(subFromtOwned.west)$) {};
\node[basic, below=of anchor3, minimum width=32.8em] (convert) {convert(r$=$rate$\times$t)};

% draw some arrows and put the text in
\path[arrsty] (tAmount)-|(anchor2.center)--(convert.north-|anchor2.center);
\path[arrsty] (tAmount)--node[midway, xshift=1.2em, font=\sffamily\bfseries\small] (ninety-perct) {90\%} (tTransferAmount);
\path[arrsty] (tAmount)-|(tFee);
\path[arrsty] (tFee)--(convert.north-|tFee.center);
\node[xshift=1.2em, font=\sffamily\bfseries\small] at (ninety-perct-|tFee.center) {10\%};
\path[arrsty] (anchor2.center)-| node[pos=0.8, left] {(1)} (subFromtOwned);
\path[arrsty] (tTransferAmount)-| node[pos=0.8, left] {(2)} (addTotOwned);


\node[basic, below=of convert] (rTransferAmount) {rTransferAmount};
\node[basic] (rAmount) at (rTransferAmount-|anchor2.center) (rAmount) {rAmount};
\node[basic] (rFee) at (rTransferAmount-|tFee.center) {rFee};
\node[basic, below=of rAmount, text width=8em] (subFromrOwned) {Subtract from\\rOwned[sender]};
\node[basic, below=of rTransferAmount, text width=8em] (addTorOwned) {Add to\\rOwned[recipent]};
\node[basic, below=of rFee, text width=8em] (subFromrTotal) {Subtract from\\rTotal};

% draw arrows
\path[arrsty] (convert.south-|rAmount)--(rAmount);
\path[arrsty] (convert.south-|rTransferAmount)--(rTransferAmount);
\path[arrsty] (convert.south-|rFee)--(rFee);
\path[arrsty] (rAmount)--(subFromrOwned);
\path[arrsty] (rTransferAmount)--(addTorOwned);
\path[arrsty] (rFee)--(subFromrTotal);

% outer dotted box
\node[fit=(tAmount)(convert)(subFromrOwned)(subFromrTotal), dotted, draw=green, inner sep=1em, ultra thick, rounded corners] (dottedbox1) {};
\node[anchor=north east, xshift=-1em] (TX1) at (dottedbox1.north west) {TX1};
 \end{scope} 
 \path[arrsty] (ttAmount.east)--++(1em,0em)|-(convert);

\end{tikzpicture}
\end{document}

相关内容