如何連接兩個矩形,或如何使節點比文字更寬和更長

如何連接兩個矩形,或如何使節點比文字更寬和更長

我正在嘗試翻譯書中的圖形,我需要連接一些矩形才能完成此操作。這是我到目前為止所擁有的:

在此輸入影像描述

正如您所看到的,箭頭的位置看起來不太好,因為箭頭沒有連接到矩形的邊緣。產生此圖形的程式碼:

\begin{tikzpicture}
\draw [rounded corners, fill=lightgray] (3,0) rectangle (6,-1) node (1) [pos=.5] {\textit{Output} gráfico} ;

\draw [rounded corners, fill=lightgray] (3,-2.5) rectangle (6,-3.5) node (2) [pos=.5] {\textit{Game Manager}};

\draw [rounded corners, fill=lightgray] (3,-5) rectangle (6,-6) node (3) [pos=.5] {Jogador};

\draw (-0.5,-1) rectangle (2,-2.5) node (4) [pos=.5, align=center] {Descrições de \\ jogos};

\draw (-0.5,-3) rectangle (2,-4.5) node (5) [pos=.5, align=center] {Registro de \\ partidas};

\draw (7,-2.5) rectangle (9,-3.5) node (6) [pos=.5, align=center] {Registro de \\ partidas};

 \draw[black, thick, ->]  (2) --  (1.south);

\end{tikzpicture}

我認為最好用節點來做到這一點,因為節點連接到邊界,但我無法讓節點看起來像上圖中的矩形。它們很小而且沒有邊界。這是一個例子:

在此輸入影像描述

以及產生上面圖形的程式碼:

\begin{tikzpicture}

\node [ rounded corners, fill=lightgray] at (4.5,0) (1) {\textit{Output} gráfico};

\end{tikzpicture}

所以我的問題是:如何用從邊緣開始和結束的箭頭連接兩個矩形?如果這是不可能的,我如何產生具有可見邊框的更大節點(但字體大小保持不變)?

答案1

我現在沒有時間重做整個 MWE,但第一個矩形可以替換為:

\node (1) [rounded corners, draw, fill=lightgray,minimum width=3cm,minimum height=1cm]
   at (4.5,-.5) {\textit{Output} gr\'afico} ;

答案2

使用鍵minimum heightminimum width作為節點的大小,並使用庫positioning來放置它們。然後為每種類型的節點使用樣式。

在此輸入影像描述

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{positioning}


\begin{document}

\begin{tikzpicture}[node distance=15 mm and 15 mm,
                    every node/.style={draw},
                    central/.style={fill=lightgray,rounded corners,minimum           
                                    width=3cm,minimum height=1cm},
                    other/.style={text width=2.2 cm,text centered,minimum 
                                  width=2.5cm,,minimum height=1.5cm}]  
\node[central] (output){\textit{Output} gr\'afico};
\node[central] (manager) [below=of output] {\textit{Game Manager}};
\node[central] (jogador) [below=of manager] {Jogador};
\node[text width= 2cm,text centered] [right=of manager] {Registro de \\ partidas};
\node[other,yshift=-1cm] [left=of manager]{Registro de \\ partidas};
\node[other,yshift=1.2cm] [left=of manager]{Descri\c c\=oes de \\ jogos};
\draw[->] (manager)--(output);
\end{tikzpicture}

\end{document}

相關內容