如何在 Tikz 绘图中显示某个物体的尺寸?

如何在 Tikz 绘图中显示某个物体的尺寸?

到目前为止我有以下代码:

\documentclass[tikz,border=10pt]{standalone}
\begin{document}

\tikzstyle{dim}    = [latex-latex]

\begin{tikzpicture}
\fill[blue!60!white] (0,0) rectangle (29,2);
\fill[blue!60!white] (4,2) rectangle (5,25);
\fill[blue!60!white] (8,2) rectangle (9,25);
\fill[blue!60!white] (14,2) rectangle (15,25);
\fill[blue!60!white] (18,2) rectangle (19,25);
\fill[blue!60!white] (24,2) rectangle (25,25);
\fill[blue!60!white] (28,2) rectangle (29,25);

\draw[black, ultra thick] (0,0) -- (29,0);
\draw[black, ultra thick] (0,0) -- (0,2);
\draw[black, ultra thick] (0,2) -- (4,2);
\draw[black, ultra thick](4,2) -- (4,25);
\draw[black, ultra thick](4,25) -- (5,25);
\draw[black, ultra thick](5,25) -- (5,2);
\draw[black, ultra thick](5,2) -- (8,2);
\draw[black, ultra thick](8,2) -- (8,25);
\draw[black, ultra thick](8,25) -- (9,25);
\draw[black, ultra thick](9,25) -- (9,2);
\draw[black, ultra thick](9,2) -- (14,2);
\draw[black, ultra thick](14,2) -- (14,25);
\draw[black, ultra thick](14,25) -- (15,25);
\draw[black, ultra thick](15,25) -- (15,2);
\draw[black, ultra thick](15,2) -- (18,2);
\draw[black, ultra thick](18,2) -- (18,25);
\draw[black, ultra thick](18,25) -- (19,25);
\draw[black, ultra thick](19,25) -- (19,2);
\draw[black, ultra thick](19,2) -- (24,2);
\draw[black, ultra thick](24,2) -- (24,25);
\draw[black, ultra thick](24,25) -- (25,25);
\draw[black, ultra thick](25,25) -- (25,2);
\draw[black, ultra thick](25,2) -- (28,2);
\draw[black, ultra thick](28,2) -- (28,25);
\draw[black, ultra thick](28,25) -- (29,25);
\draw[black, ultra thick](29,25) -- (29,0);

\fill[black!40!white] (6,3.5) rectangle (7,25);
\fill[black!40!white] (16,3.5) rectangle (17,25);
\fill[black!40!white] (26,3.5) rectangle (27,25);
\draw[black, ultra thick] (6,3.5) rectangle (7,25);
\draw[black, ultra thick] (16,3.5) rectangle (17,25);
\draw[black, ultra thick] (26,3.5) rectangle (27,25);

\fill[red!60!white] (0,26.5) rectangle (29,28.5);
\fill[red!60!white] (0,3.5) rectangle (1,26.5);
\fill[red!60!white] (2,3.5) rectangle (3,26.5);
\fill[red!60!white] (10,3.5) rectangle (11,26.5);
\fill[red!60!white] (12,3.5) rectangle (13,26.5);
\fill[red!60!white] (22,3.5) rectangle (23,26.5);

\draw[black, ultra thick](0,3.5) -- (0,28.5);
\draw[black, ultra thick](0,28.5) -- (29,28.5);
\draw[black, ultra thick](29,28.5) -- (29,26.5);
\draw[black, ultra thick](23,26.5) -- (29,26.5);
\draw[black, ultra thick](23,26.5) -- (23,3.5);
\draw[black, ultra thick](22,3.5) -- (23,3.5);
\draw[black, ultra thick](22,3.5) -- (22,26.5);
\draw[black, ultra thick](22,26.5) -- (21,26.5);
\draw[black, ultra thick](21,26.5) -- (21,3.5);
\draw[black, ultra thick](20,3.5) -- (21,3.5);
\draw[black, ultra thick](20,26.5) -- (20,3.5);
\draw[black, ultra thick](20,26.5) -- (13,26.5);
\draw[black, ultra thick](13,26.5) -- (13,3.5);
\draw[black, ultra thick](12,3.5) -- (13,3.5);
\draw[black, ultra thick](12,3.5) -- (12,26.5);
\draw[black, ultra thick](12,26.5) -- (11,26.5);
\draw[black, ultra thick](11,26.5) -- (11,3.5);
\draw[black, ultra thick](10,3.5) -- (11,3.5);
\draw[black, ultra thick](10,26.5) -- (10,3.5);
\draw[black, ultra thick](10,26.5) -- (3,26.5);
\draw[black, ultra thick](3,26.5) -- (3,3.5);
\draw[black, ultra thick](2,3.5) -- (3,3.5);
\draw[black, ultra thick](2,3.5) -- (2,26.5);
\draw[black, ultra thick](2,26.5) -- (1,26.5);
\draw[black, ultra thick](1,26.5) -- (1,3.5);
\draw[black, ultra thick](1,3.5) -- (0,3.5);


\fill[red!60!white] (20,3.5) rectangle (21,26.5);

\draw[dim] (1.5,32) -- ++(12.5,32) node[midway,above] {$d_o$}; 

\end{tikzpicture}
\end{document}


\draw[dim] (1.5,32) -- ++(12.5,32) node[midway,above] {$d_o$};命令来自https://texample.net/tikz/examples/signpost/但我不太明白。我想显示从第一对红色手指的中间到第二对红色手指的尺寸,以便双箭头位于图纸上方,标记线显示距离。标题也应该大得多。

我如何显示尺寸以使其看起来像上面 texample 中的 d_o?

答案1

++表示相对于前一点的相对坐标。因此,使用 时(1.5,32)--++(12.5,32),笔从移动到远离该(1.5,32)位置的新位置,而使用 时,笔从 移动到。(12.5,32)(1.5,32)--(12.5,32)(1.5,32)(12.5,32)

包装tikz-dimline设计为显示尺寸。您可以使用它或手绘所有内容。

以下代码显示了绘图的简单版本。不是使用由线段绘制的带有边框线的彩色矩形。代码显示了如何像填充和绘制的封闭路径一样绘制它们。相对坐标用于绘制垂直线段(-||-)。

完整方案的原始尺寸约为 29x25 厘米。我将其缩放了 0.5 倍并使用了字体Huge

\documentclass[tikz,border=10pt]{standalone}
\usepackage{tikz-dimline}
\begin{document}

\begin{tikzpicture}[scale=0.5]
\draw[fill=blue!60!white] (0,0) -| ++(29,25) -| ++(-1,-23) -| ++(-3,23) -| ++(-1,-23) -| ++(-5,23) -| ++(-1,-23) -| ++(-3,23) -| ++(-1,-23) -| ++(-5,23) -| ++(-1,-23) -| ++(-3,23) -| ++(-1,-23) -| cycle;

\begin{scope}[yshift=3.5cm]

\draw[fill=black!40!white] (6,0) rectangle ++(1,21.5);
\draw[fill=black!40!white] (16,0) rectangle ++(1,21.5);
\draw[fill=black!40!white] (26,0) rectangle ++(1,21.5);

\draw[fill=red!60!white] (0,0) |- ++(29,25) |- ++(-6,-2) |- ++(-1,-23) |- ++(-1,23) |- ++(-1,-23) |- ++(-7,23) |- ++(-1,-23) |- ++(-1,23) |- ++(-1,-23) |- ++(-7,23) |- ++(-1,-23) |- ++(-1,23) |- cycle;
\end{scope}

\dimline[label style={above, font=\Huge}] {(1.5,29)}{(11.5,29)}{$d_o$}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容