如何在框的每个子部分中写入文字?

如何在框的每个子部分中写入文字?

我想在下面提到的每个框中写一个字母。我还想在矩形顶部写一段文字。

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}


\begin{document}
      
  \begin{tikzpicture}
  \draw (0,0) -- (5,0);
  \draw (5,0) -- (5,5);
  \draw (0,0) -- (0,5);
  \draw (0,5) -- (5,5);
  \draw (2.5,0) -- (2.5,5);
  \draw (0,2.5) -- (5,2.5);
  \draw (1.25,0) -- (1.25,2.5);
  \draw (0,1.25) -- (2.5,1.25);
  \end{tikzpicture}

\end{document}

答案1

这是一种方法。

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}

\begin{document}
      
\begin{tikzpicture}
  \draw (0,0) -- (5,0);
  \draw (5,0) -- (5,5);
  \draw (0,0) -- (0,5);
  \draw (0,5) -- (5,5);
  \draw (2.5,0) -- (2.5,5);
  \draw (0,2.5) -- (5,2.5);
  \draw (1.25,0) -- (1.25,2.5);
  \draw (0,1.25) -- (2.5,1.25);
  \node (A) at (0.625,0.625) {A};
  \node (B) at (1.85,0.625) {B};
  \node (C) at (0.625,1.85) {C};
  \node (D) at (1.85,1.85) {D};
  \node (E) at (3.75,1.25) {E};
  \node (F) at (1.25,3.75) {F};
  \node (G) at (3.75,3.75) {G};
  \node (text) at (2.5,5.25) {Some Text...};
\end{tikzpicture}

\end{document}

在此处输入图片描述

答案2

带有节点,彼此相对定位,大小是节点参数:

\documentclass[border=3.141592]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}


\begin{document}
    \begin{tikzpicture}[
node distance = 0pt,
box/.style = {draw, minimum size=#1, outer sep=0pt}
                        ]
\node (a) [box=10mm] {A};
\node (b) [box=10mm, right=of a] {B};
\node (c) [box=5mm,  below right=of a.south west] {C};
\node (d) [box=5mm,  right=of c] {D};
\node (e) [box=5mm,  below=of c] {E};
\node (f) [box=5mm,  right=of e] {F};
\node (G) [box=10mm, right=of d.south east] {G};
%
\node[above=of a.north east] {image title};
    \end{tikzpicture}

在此处输入图片描述

**附录:具有通用定义的节点大小。现在您可以通过选择\w节点的宽度和高度来简单地更改节点大小。

\documentclass[border=3.141592]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}


\begin{document}
    \begin{tikzpicture}[
node distance = 0pt,
box/.style = {draw, minimum size=#1, inner sep=0pt, outer sep=0pt}
                        ]
\def\w{12.5mm}
\node (a) [box=2*\w] {A};
\node (b) [box=2*\w,    right=of a] {B};
\node (c) [box=\w,  below right=of a.south west] {C};
\node (d) [box=\w,  right=of c] {D};
\node (e) [box=\w,  below=of c] {E};
\node (f) [box=\w,  right=of e] {F};
\node (G) [box=2*\w,    right=of d.south east] {G};
%
\node[above=of a.north east] {image title};
    \end{tikzpicture}

\end{document}

结果与以前类似。

相关内容