各ノードのラベルを考慮してノードを囲むボックス tikzpicture

各ノードのラベルを考慮してノードを囲むボックス tikzpicture

問題

ラベル付きノードの外側にボックスを描画していますが、そのボックスは内部ノードの上にあるラベルを考慮していません。

私の文書の MWE は次のとおりです。

\documentclass[10pt]{article}
\ExpandArgs{c}\newcommand{new@fontshape}{anything}

\usepackage[russian,indonesian]{babel}
\usepackage{newtx}

\usepackage{linguex}
\usepackage[none]{hyphenat}
\usepackage{geometry}
\usepackage{setspace}
\usepackage{booktabs}
\usepackage{tikz}
\usepackage{tikz-qtree}
\usepackage{gb4e}
\usepackage{adjustbox}

\usetikzlibrary{shapes.geometric, arrows, chains, decorations.pathreplacing, positioning, fit}

\AtBeginDocument{%
  \DeclareFontFamilySubstitution{T2A}{\familydefault}{Tempora-TLF}%
}

\primebars
\let\emptyset\varnothing

\geometry{
 a4paper,
 margin=3cm
 }

\newcommand{\?}[1]{\foreignlanguage{russian}{#1}}
\noautomath


\begin{document}

\vspace{5mm}
\section*{Hubungan sintaksis}
\vspace{5mm}

\tikzstyle{startstop} = [rectangle, rounded corners, minimum width=3cm, minimum height=2.5cm, text centered, draw=black, text width=3cm]
\tikzstyle{io} = [trapezium, trapezium left angle=70, trapezium right angle=110, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=blue!30]
\tikzstyle{process} = [rectangle, minimum width=1cm, minimum height=1cm, text centered, draw=black, text width=2.5cm]
\tikzstyle{decision} = [diamond, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=green!30]
\tikzstyle{arrow} = [thick,->,>=stealth]
\tikzstyle{line} = [draw, -latex']

\def\layersep{2.5cm}
\begin{adjustbox}{width=\textwidth}
\begin{tikzpicture}[node distance=4cm, box/.style = {draw,black,inner sep=10pt,rounded corners=5pt}]
  \node (kr) [process, label=above:{Agen}] {Kerusiaan};
  \node (bn) [process, right of=kr, label=above:{Sasaran}] {Binan};

  \path [line] (kr) -- node [text width=2.5cm,midway,above,align=center ] {Aksi} (bn);

  \node[box,fit=(kr)(bn)] {};

\end{tikzpicture}\hspace{1cm}%
\begin{tikzpicture}[node distance=4cm, box/.style = {draw,black,inner sep=10pt,rounded corners=5pt}]
  \node (kr) [process, label=above:{Agen}] {Binan};
  \node (bn) [process, right of=kr, label=above:{Sasaran}] {Non-kerusiaan};

  \path [line] (kr) -- node [text width=2.5cm,midway,above,align=center ] {Aksi} (bn);

  \node[box,fit=(kr)(bn)] {};

\end{tikzpicture}\hspace{1cm}%
\begin{tikzpicture}[node distance=4cm, box/.style = {draw,black,inner sep=10pt,rounded corners=5pt}]
  \node (kr) [process, label=above:{Agen}] {Binan};
  \node (bn) [process, right of=kr, label=above:{Sasaran}] {Kerusiaan};

  \path [line] (kr) -- node [text width=2.5cm,midway,above,align=center ] {Aksi} (bn);

  \node[box,fit=(kr)(bn)] {};

\end{tikzpicture}
\end{adjustbox}

\end{document}

コードのタイプセットは次のとおりです。 ここに画像の説明を入力してください

ボックスは、ラベルが各ノードの一部であることを無視します。つまり、ラベルを通過するだけで、ラベルの上にスペースを残しません。

ボックスがラベルを通り抜けないようにし、その上にテキストを追加したいです。おおよそ次のようになります。

ここに画像の説明を入力してください

コードを改善するにはどうすればいいでしょうか?


これまでやってきたこと

sepin を変更するだけで済むことはわかっています{draw,black,inner sep=10pt,rounded corners=5pt}が、ボックスの上部と下部のスペースの間に不均等なスペースが作成されます。

\documentclass[10pt]{article}
\ExpandArgs{c}\newcommand{new@fontshape}{anything}

\usepackage[russian,indonesian]{babel}
\usepackage{newtx}

\usepackage{linguex}
\usepackage[none]{hyphenat}
\usepackage{geometry}
\usepackage{setspace}
\usepackage{booktabs}
\usepackage{tikz}
\usepackage{tikz-qtree}
\usepackage{gb4e}
\usepackage{adjustbox}

\usetikzlibrary{shapes.geometric, arrows, chains, decorations.pathreplacing, positioning, fit}

\AtBeginDocument{%
  \DeclareFontFamilySubstitution{T2A}{\familydefault}{Tempora-TLF}%
}

\primebars
\let\emptyset\varnothing

\geometry{
 a4paper,
 margin=3cm
 }

\newcommand{\?}[1]{\foreignlanguage{russian}{#1}}
\noautomath


\begin{document}

\vspace{5mm}
\section*{Hubungan sintaksis}
\vspace{5mm}

\tikzstyle{startstop} = [rectangle, rounded corners, minimum width=3cm, minimum height=2.5cm, text centered, draw=black, text width=3cm]
\tikzstyle{io} = [trapezium, trapezium left angle=70, trapezium right angle=110, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=blue!30]
\tikzstyle{process} = [rectangle, minimum width=1cm, minimum height=1cm, text centered, draw=black, text width=2.5cm]
\tikzstyle{decision} = [diamond, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=green!30]
\tikzstyle{arrow} = [thick,->,>=stealth]
\tikzstyle{line} = [draw, -latex']

\def\layersep{2.5cm}
\begin{adjustbox}{width=\textwidth}
\begin{tikzpicture}[node distance=4cm, box/.style = {draw,black,inner sep=18pt,rounded corners=5pt}]
  \node (kr) [process, label=above:{Agen}] {Kerusiaan};
  \node (bn) [process, right of=kr, label=above:{Sasaran}] {Binan};

  \path [line] (kr) -- node [text width=2.5cm,midway,above,align=center ] {Aksi} (bn);

  \node[box,fit=(kr)(bn)] {};

\end{tikzpicture}\hspace{1cm}%
\begin{tikzpicture}[node distance=4cm, box/.style = {draw,black,inner sep=18pt,rounded corners=5pt}]
  \node (kr) [process, label=above:{Agen}] {Binan};
  \node (bn) [process, right of=kr, label=above:{Sasaran}] {Non-kerusiaan};

  \path [line] (kr) -- node [text width=2.5cm,midway,above,align=center ] {Aksi} (bn);

  \node[box,fit=(kr)(bn)] {};

\end{tikzpicture}\hspace{1cm}%
\begin{tikzpicture}[node distance=4cm, box/.style = {draw,black,inner sep=18pt,rounded corners=5pt}]
  \node (kr) [process, label=above:{Agen}] {Binan};
  \node (bn) [process, right of=kr, label=above:{Sasaran}] {Kerusiaan};

  \path [line] (kr) -- node [text width=2.5cm,midway,above,align=center ] {Aksi} (bn);

  \node[box,fit=(kr)(bn)] {};

\end{tikzpicture}
\end{adjustbox}

\end{document}

ここに画像の説明を入力してください

ラベルの上部のボックスとノードの下部のボックスの間のスペースが等しくなるようにしたいです。外側のボックスの上にテキストを追加します。どうすればいいですか?

答え1

次のコードで動作させました:

\documentclass[10pt]{article}
\ExpandArgs{c}\newcommand{new@fontshape}{anything}

\usepackage[russian,indonesian]{babel}
\usepackage{newtx}

\usepackage{linguex}
\usepackage[none]{hyphenat}
\usepackage{geometry}
\usepackage{setspace}
\usepackage{booktabs}
\usepackage{tikz}
\usepackage{tikz-qtree}
\usepackage{gb4e}
\usepackage{adjustbox}

\usetikzlibrary{shapes.geometric, arrows, chains, decorations.pathreplacing, positioning, fit}

\AtBeginDocument{%
  \DeclareFontFamilySubstitution{T2A}{\familydefault}{Tempora-TLF}%
}

\primebars
\let\emptyset\varnothing

\geometry{
 a4paper,
 margin=3cm
 }

\newcommand{\?}[1]{\foreignlanguage{russian}{#1}}
\noautomath


\begin{document}

\vspace{5mm}
\section*{Hubungan sintaksis}
\vspace{5mm}

\tikzstyle{startstop} = [rectangle, rounded corners, minimum width=3cm, minimum height=2.5cm, text centered, draw=black, text width=3cm]
\tikzstyle{io} = [trapezium, trapezium left angle=70, trapezium right angle=110, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=blue!30]
\tikzstyle{process} = [rectangle, minimum width=1cm, minimum height=1cm, text centered, draw=black, text width=2.5cm]
\tikzstyle{decision} = [diamond, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=green!30]
\tikzstyle{arrow} = [thick,->,>=stealth]
\tikzstyle{line} = [draw, -latex']

\def\layersep{2.5cm}
\begin{adjustbox}{width=\textwidth}
\begin{tikzpicture}[node distance=4cm, box/.style = {draw,black,inner sep=5pt,rounded corners=5pt}]
  \node (kr) [process, fill=gray!15,thin,rounded corners] {Kerusiaan};
  \node (bn) [process, fill=gray!60,thin,rounded corners, right of=kr] {Binan};
  \node (n1) [inner sep=0pt,draw=none,above=2pt of kr] {Agen};
  \node (n2) [inner sep=0pt,draw=none,above=3.5pt of bn] {Sasaran};

  \path [line] (kr) -- node [text width=2.5cm,midway,above,align=center] {Aksi} (bn);
  \path (kr) -- node[midway,draw=none,inner sep=2pt, above=12.5mm] {teks} (bn);

  \node[box,fit=(kr)(bn)(n1)(n2)] {};

\end{tikzpicture}\hspace{1cm}%
\begin{tikzpicture}[node distance=4cm, box/.style = {draw,black,inner sep=5pt,rounded corners=5pt}]
  \node (kr) [process, fill=gray!60,thin,rounded corners] {Binan};
  \node (bn) [process, fill=gray!5,draw,dashed, right of=kr] {Non-kerusiaan};
  \node (n1) [inner sep=0pt,draw=none,above=2pt of kr] {Agen};
  \node (n2) [inner sep=0pt,draw=none,above=3.5pt of bn] {Sasaran};

  \path [line] (kr) -- node [text width=2.5cm,midway,above,align=center ] {Aksi} (bn);
  \path (kr) -- node[midway,draw=none,inner sep=2pt, above=12.5mm] {teks} (bn);

  \node[box,fit=(kr)(bn)(n1)(n2)] {};

\end{tikzpicture}\hspace{1cm}%
\begin{tikzpicture}[node distance=4cm, box/.style = {draw,black,inner sep=5pt,rounded corners=5pt}]
  \node (kr) [process, fill=gray!60,thin,rounded corners] {Binan};
  \node (bn) [process, fill=gray!15,thin,rounded corners, right of=kr] {Kerusiaan};
  \node (n1) [inner sep=0pt,draw=none,above=2pt of kr] {Agen};
  \node (n2) [inner sep=0pt,draw=none,above=3.5pt of bn] {Sasaran};

  \path [line] (kr) -- node [text width=2.5cm,midway,above,align=center ] {Aksi} (bn);
  \path (kr) -- node[midway,draw=none,inner sep=2pt, above=12.5mm] {teks} (bn);

  \node[box,fit=(kr)(bn)(n1)(n2)] {};

\end{tikzpicture}
\end{adjustbox}

\end{document}

その結果、次のようになります。 ここに画像の説明を入力してください

他の提案も歓迎します!

答え2

3 つの環境を作成する代わりにtikzpicture、3 つの人物がそれぞれ 1 つの環境内にある 1 つの環境だけを作成しscope、人物同士の関係を正確に配置できるようにします。

Agen定義したらすぐに各ラベルに名前を付けます。

\documentclass[10pt]{article}
\ExpandArgs{c}\newcommand{new@fontshape}{anything}

\usepackage[russian,indonesian]{babel}
\usepackage{newtx}

\usepackage{linguex}
\usepackage[none]{hyphenat}
\usepackage{geometry}
\usepackage{setspace}
\usepackage{booktabs}
\usepackage{tikz}
\usepackage{tikz-qtree}
\usepackage{gb4e}
\usepackage{adjustbox}

\usetikzlibrary{shapes.geometric, arrows, chains, decorations.pathreplacing, positioning, fit}

\AtBeginDocument{%
  \DeclareFontFamilySubstitution{T2A}{\familydefault}{Tempora-TLF}%
}

\primebars
\let\emptyset\varnothing

\geometry{
 a4paper,
 margin=3cm
 }

\newcommand{\?}[1]{\foreignlanguage{russian}{#1}}
\noautomath


\begin{document}

\vspace{5mm}
\section*{Hubungan sintaksis}
\vspace{5mm}

\tikzstyle{startstop} = [rectangle, rounded corners, minimum width=3cm, minimum height=2.5cm, text centered, draw=black, text width=3cm]
\tikzstyle{io} = [trapezium, trapezium left angle=70, trapezium right angle=110, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=blue!30]
\tikzstyle{process} = [rectangle, minimum width=1cm, minimum height=1cm, text centered, draw=black, text width=2.5cm]
\tikzstyle{decision} = [diamond, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=green!30]
\tikzstyle{arrow} = [thick,->,>=stealth]
\tikzstyle{line} = [draw, -latex']

\def\layersep{2.5cm}
\begin{adjustbox}{width=\textwidth}
\begin{tikzpicture}[node distance=4cm, box/.style = {draw,black,inner sep=5pt,rounded corners=5pt}]
  \node (kr) [process, label={[name=label 1]above:Agen}] {Kerusiaan};
  \node (bn) [process, right of=kr, label=above:Sasaran] {Binan};

  \path [line] (kr) -- node [text width=2.5cm,midway,above,align=center ] {Aksi} (bn);

  \node[fit=(bn)(label 1),inner sep=0pt] (fit 1){};
  \node[box,fit=(kr)(fit 1)] {};
    
\begin{scope}[xshift=8cm]
  \node (kr) [process, label={[name=label 2]above:Agen}] {Binan};
  \node (bn) [process, right of=kr, label=above:{Sasaran}] {Non-kerusiaan};

  \path [line] (kr) -- node [text width=2.5cm,midway,above,align=center ] {Aksi} (bn);
  \node[fit=(bn)(label 2),inner sep=0pt] (fit 2){};
  \node[box,fit=(kr)(fit 2)] {};
\end{scope}

\begin{scope}[xshift=16cm]
  \node (kr) [process, label={[name=label 3]above:Agen}] {Binan};
  \node (bn) [process, right of=kr, label=above:{Sasaran}] {Kerusiaan};

  \path [line] (kr) -- node [text width=2.5cm,midway,above,align=center ] {Aksi} (bn);
  \node[fit=(bn)(label 3),inner sep=0pt] (fit 3){};
  \node[box,fit=(kr)(fit 3)] {};
\end{scope}
\end{tikzpicture}
\end{adjustbox}

\end{document}

ここに画像の説明を入力してください

関連情報