我正在尝试创建带有尺寸的磁写头的技术图纸。我正在使用一些宏,这对我很有帮助:标注技术图纸尺寸。
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{positioning,arrows,shapes.arrows,shapes.geometric,calc,decorations.markings}
\usepackage{color}
\pgfarrowsdeclarecombine{|<}{>|}{|}{|}{latex}{latex}
\def\Dimline[#1][#2][#3]{
\begin{scope}[>=latex] % redef arrow for dimension lines
\draw let \p1=#1, \p2=#2, \n0={round(veclen(\x2-\x1,\y2-\y1))} in [|<->|,
decoration={markings, % switch on markings
mark=at position .5 with {\node[#3,scale=0.6] at (0,0) {\DimScale{\n0}};},
},
postaction=decorate] #1 -- #2;
\end{scope}
}
%% The following macro is used to scale a dimension from points to the
%% display scale. The following code divides the number of points by
%% 28.4 to roughly get the width in centimeters (rounding to the
%% nearest millimeter):
\def\DimScale#1{\pgfmathparse{round(#1/28.4*100)/10}\pgfmathresult nm}
\newcommand{\headDesignOne}[3]{
\draw[step=1cm,gray!50,very thin] (-10.5,-10.5) grid (10.5,10.5);
\draw[->,thin](-10,0)--(10,0);\draw[->,thin](0,-10)--(0,10);
\coordinate (yOffset) at (0,0);
\coordinate (O) at (0,0);
\draw[very thin,blue!30] (yOffset) circle (#3);
% coordinates of the main pole
\draw[fill=gray, fill opacity=0.5]
($(270-#1:#3)+(yOffset)$) coordinate (A) --
($(90+#2:#3)+(yOffset)$) coordinate (B) --
($(90-#2:#3)+(yOffset)$) coordinate (C) --
($(270+#1:#3)+(yOffset)$) coordinate (D)-- cycle;
\Dimline[($(B)+(0,-0.5)$)][($(C)+(0,-0.5)$)][below];
\Dimline[($(A)+(0,0.5)$)][($(D)+(0,0.5)$)][above];
\Dimline[($(D)+(3.5,0)$)][($(D|-C)+(3.5,0)$)][right];\draw(D)--+(3.5,0);\draw(D|-C)--+(3.5,0);
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Begin document %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\begin{frame}{Conventional writer design 1}
\begin{tikzpicture}[scale=0.4]
\path[use as bounding box](-10,-10) rectangle (10,10); % Set the BB
\headDesignOne{20}{40}{5}
\end{tikzpicture}
\end{frame}
\end{document}
不幸的是,我无法粘贴结果,因为我是新手,但是当我排版上面的内容时,出现的尺寸之一是 85.59999
我有两个问题:
- 我怎样才能将 85.59999 改为 85.6?
- 我如何获取函数中计算出的 85.6 或 64.4
\Dimline
并重新使用该数字?例如,我想将该数字放入一个表中,列出此设计的一些关键参数。
答案1
问题在于舍入操作后的除法步骤不准确,这是必要的,因为您无法指定舍入操作的小数位数。一种解决方案是使用\pgfmathprintnumber[precision=1]{\pgfmathresult}
舍入并输出数字。如果您想在其他地方使用舍入后的数字,您可以使用\pgfmathprintnumberto{\pgfmathresult}{\roundednumber}
将舍入后的数字存储到宏中。
将缩放函数更改为
\def\DimScale#1{\pgfmathparse{#1/2.84}\pgfmathprintnumberto[precision=1]{\pgfmathresult}{\roundednumber} \roundednumber nm}
产量