用方框包围节点来说明每个节点的标签 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}

以下是代码的排版: 在此处输入图片描述

该盒子只是忽略了标签是每个节点的一部分;它只是穿过它并且不会在标签上方留下空间。

我希望盒子不穿过标签,并在其上方添加文本。大致如下:

在此处输入图片描述

我怎样才能改进我的代码?


我目前所做的

我知道我可以改变sep{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

我没有创建三个环境,而是tikzpicture只创建一个环境,其中 3 个人物各自位于一个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}

在此处输入图片描述

相关内容