在以下示例中,是否可以在绘制的框中设置文本?
这是我的代码,我希望它会有所帮助。
\documentclass[12pt,a4paper]{article}
\usepackage{tikz}
\begin{document}
\begin{center}
\begin{tikzpicture}[scale=0.33]
\draw[black, fill=blue,fill opacity=0.5, line width=2pt] (0,0) -- (0,20) -- (42.5,20) -- (42.5,15) -- (5,15) -- (5,0) -- (0,0) -- cycle; %Vendor Specific Extensions
\draw[black, fill=green,fill opacity=0.5, line width=2pt] (7.5,0) -- (7.5, 12.5) -- (42.5, 12.5) -- (42.5, 7.5) -- (12.5, 7.5) -- (12.5, 0) -- (7.5,0) -- cycle; %Collaboration Models
\draw[line width=2pt] (15,0) -- (15,5) -- (20,5) -- (20,0) -- (15,0); %DA
\draw[line width=2pt] (22.5,0) -- (22.5,5) -- (27.5,5) -- (27.5,0) -- (22.5,0); %AC
\draw[line width=2pt] (30,0) -- (30,5) -- (35,5) -- (35,0) -- (30,0); % HA
\draw[line width=2pt] (37.5,0) -- (37.5,5) -- (42.5,5) -- (42.5,0) -- (37.5,0); %Prg
\draw[line width=2pt] (0,-2.5) -- (42.5,-2.5) -- (42.5,-7.5) -- (0,-7.5) -- (0,-2.5); %Base Services
\draw[line width=2pt] (0,-10) -- (18.75,-10) -- (18.75,-15) -- (0,-15) -- (0,-10); %Transport
\draw[line width=2pt] (23.75,-10) -- (42.5,-10) -- (42.5,-15) -- (23.75,-15) -- (23.75,-10); %Meta Model
\end{tikzpicture}
\end{center}
\end{document}
答案1
像这样:
\documentclass[12pt, tikz, margin=5mm]{standalone}
\begin{document}
\begin{tikzpicture}[scale = 0.33,
every node/.style = {font=\Large, text=black, text opacity=1},
line width = 2pt
]
\draw[fill=blue,fill opacity=0.5]
(0,0) -- (0,20) -- node[below=5mm] {Vendor Specific Extensions} (42.5,20) --
(42.5,15) -- (5,15) -- (5,0) -- cycle; %Vendor Specific Extensions
\draw[fill=green,fill opacity=0.5]
(7.5,0) -- (7.5, 12.5) -- node[below=5mm] {Collaboration Models} (42.5, 12.5) --
(42.5, 7.5) -- (12.5, 7.5) -- (12.5, 0) -- cycle; %Collaboration Models
%
\draw (15,0) rectangle (20,5) node[midway] {DA}; %DA
\draw (22.5,0) rectangle (27.5,5) node[midway] {AC}; %AC
\draw (30,0) rectangle (35,5) node[midway] {HA}; % HA
\draw (37.5,0) rectangle (42.5,5) node[midway] {Prg}; %Prg
%
\draw (0,-2.5) rectangle (42.5,-7.5) node[midway] {Base Services}; %Base Services
\draw (0,-10) rectangle (18.75,-15) node[midway] {Transport}; %Transport
\draw (23.75,-10) rectangle (42.75,-15) node[midway] {Meta Model}; %Meta Model
\end{tikzpicture}
\end{document}
当然,使用矩形形状的节点而不是绘制添加带有文本的节点的矩形,可以提供更简洁的代码:)
答案2
在 TikZ 中,有一些对象被称为节点。简而言之,这些对象是具有不同形状(矩形、圆形等)的文本框。它们的大小可以调整,颜色、线条类型等可以通过向它们提供选项来更改。目前尚不支持 L 形,但您仍然可以将节点放置在它们上面以放置文本。
我稍微修改了一下你的例子,把所有数字粗略地除以 3,去掉了 0.333 的缩放比例
\documentclass[12pt,a4paper]{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[black, fill=blue,fill opacity=0.5, line width=2pt] (0,0) -- (0,6) -- (14,6) -- (14,5) -- (1.5,5) -- (1.5,0) -- (0,0) -- cycle; %Vendor Specific Extensions
\draw[black, fill=green,fill opacity=0.5, line width=2pt] (2.5,0) -- (2.5, 4.5) -- (14, 4.5) -- (14, 2.5) -- (4.5, 2.5) -- (4.5, 0) -- (2.5,0) -- cycle; %Collaboration Models
\node[minimum size=1cm,draw,scale=2,line width=2pt] (da) at (6.5, 1) {DA}; %DA
\node[minimum size=1cm,draw,scale=2,line width=2pt] (da) at (9.5, 1) {AC}; %DA
\end{tikzpicture}
\end{document}
在这里您可以看到我只是用命令描述框内容并通过一堆相关选项{}
给出(框中心)的位置。at (.,.)
\node