答案1
由于您似乎正在尝试绘制数据字段规范,因此可以使用字节字段图书馆。
答案2
使用链中的节点。对于括号,使用 Ti钾Z 库书法˙˙(它们更加花哨):
\documentclass[border=3.141502]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc, chains,
decorations.pathreplacing,%
calligraphy,% had to be after decorations.pathreplacing
}
\begin{document}
\begin{tikzpicture}[
node distance = 0pt,
start chain = A going right,
BC/.style args = {#1/#2/#3}{
decorate,
decoration={calligraphic brace, amplitude=2mm,
pre =moveto, pre length=1pt,
post=moveto, post length=1pt,
raise=#1,
#2},% for mirroring of brace
very thick,
pen colour={#3}
},
box/.style = {draw, minimum width=#1, minimum height=7mm,
outer sep=0pt, font=\ttfamily,
on chain=A}
]
\node[box=40mm] {op code}; % A-1
\node[box=8mm] {\dots};
\node[box=32mm] {};
\node[box=8mm] {\dots};
\node[box=48mm] {\dots}; % A-5
\draw [BC=2mm/mirror/red]
(A-1.south west) -- node[below=4mm] {5} (A-1.south east);
\draw [BC=2mm/mirror/red]
(A-2.south west) -- node[below=4mm] {1} (A-2.south east);
\draw [BC=2mm/mirror/red]
(A-3.south west) -- node[below=4mm] {4} (A-3.south east);
\draw [BC=2mm/mirror/red]
(A-4.south west) -- node[below=4mm] {\dots} (A-4.south east);
\draw [BC=2mm/mirror/red]
(A-5.south west) -- node[below=4mm] {} (A-5.south east);
\end{tikzpicture}
\end{document}
答案3
这是一个小例子,以便您理解如何进行:
- 使用
calc
,我可以通过计算它们的位置来定义彼此相对的坐标$(nodeA) + (nodeB)$
。 - 然后我可以
rectangle
在节点A
和B
通过之间画一个\draw (A) rectangle (B);
- 我可以通过添加来向这个矩形添加一些内容
node {some text}
后rectangle
。 - 该选项
midway
将此节点置于A
和之间B
,中间...... - 使用
\decorations.pathreplacing
,我可以添加我定义的装饰。 decorate
给 tikz 命令应用装饰。decoration={...}
是你放在A -- B
- 我想要一个
brace
然后我摆弄它。 - 请注意,我重复使用了此列表中的第 3 点,并在
node
之后--
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.pathreplacing}
\begin{document}
\begin{tikzpicture}
\coordinate (a) at (0,0);
\coordinate (b) at ($(a) + (5,1)$);
\coordinate (c) at ($(b) + (1,-1)$);
\coordinate (d) at ($(c) + (4,1)$);
\coordinate (e) at ($(d) + (1,-1)$);
\draw (a)rectangle node [midway]{Op code}
(b)rectangle node [midway]{...}
(c)rectangle node [midway]{any text I want }
(d) rectangle (e) ;
\draw [decorate,decoration={brace,amplitude=10pt}] ($(b)- (0,1)$) -- node [midway,yshift=-20] {5}(a);
\draw [decorate,decoration={brace,amplitude=10pt, mirror}] ($(b)- (0,1)$) -- (c);
\draw [decorate,decoration={brace,amplitude=10pt, aspect=00.1}] ($(d)- (0,1)$) -- (c);
\end{tikzpicture}
\end{document}