我是 LaTeX 的初学者,尝试将其用于工业计量测试报告,其中我需要使用几何公差。我尝试使用 TikZ 制作第一个,但这是硬编码的,因此不灵活。在某些情况下,我需要将参考平面的数量从 1 更改为 3,例如示例中的 (A,B,C) 相反,需要在主公差中使用一位或两位数字,有时还需要使用符号(例如“DIA”)作为前缀。在我看来,使用链式方法会更有希望,但我无法使其工作,符号没有放在左侧,并且线条没有正确对齐。有人能提出解决方案吗?
\documentclass[11pt ]{article}
\usepackage{tikz}
\usetikzlibrary{chains}
\usetikzlibrary{positioning}
\renewcommand{\familydefault}{\sfdefault}
\begin{document}
\Large
\newcommand{\postol}[4]{%
\begin{tikzpicture}[scale=.7]
\draw (-1em,0) -- (1em,0);
\draw(0,-1em) -- (0,1em);
\draw (0,0) circle ( .6 em);
\draw (1em, -1em) --(1em, 1em);
\draw (2.5em, 0) node{#1};
\draw(4em,-1em) -- (4em,1em);
\draw (5em, 0) node{#2};
\draw(6em,-1em) -- (6em,1em);
\draw (7em, 0) node{#3};
\draw(8em,-1em) -- (8em,1em);
\draw (9em, 0) node{#4};
\draw (-1 em,-1em) rectangle (10 em, 1 em);
\end{tikzpicture}} %
\postol{0.32}{A}{B}{C}
\newcommand{\tolgeom}[1]{
\node[rectangle, draw, on chain=going right]{
#1}}%
\begin{tikzpicture}[scale=1,
start chain,
node distance=0pt]
\draw (-1em,0) -- (1em,0);
\draw(0,-1em) -- (0,1em);
\draw (0,0) circle ( .6 em);
\tolgeom{0.32};\tolgeom{A}; \tolgeom{B};\tolgeom{C};
\end{tikzpicture}
\end{document}
答案1
我已经为在http://en.wikipedia.org/wiki/Geometric_dimensioning_and_tolerancing#Symbols,加上一个用于创建以字母为参数的修饰符的符号。
该行将\tol{type=position,3,2,1,modifier=M}
打印
使用 访问符号type=<type>
。以下是所有可用类型的列表:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{chains}
\usetikzlibrary{positioning}
\renewcommand{\familydefault}{\sfdefault}
\usepackage{xstring}
\makeatletter
\pgfdeclareshape{tolposition}{
\inheritsavedanchors[from=rectangle]
\inheritanchorborder[from=rectangle]
\foreach \anchor in {center,north,south,west,east,north east,south east,north west, south west}{
\inheritanchor[from=rectangle]{\anchor}
}
\backgroundpath{%
\southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
%% The path
\pgfpathrectanglecorners
{\pgfpointadd{\southwest}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}
{\pgfpointadd{\northeast}{\pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}}
\pgfpathmoveto{\pgfpoint{-\pgf@xb}{0pt}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{0pt}}
\pgfpathmoveto{\pgfpointadd{\pgfpointorigin}{\pgfpoint{0pt}{-\pgf@yb}}}
\pgfpathlineto{\pgfpoint{0pt}{\pgf@yb}}
\pgfusepath{stroke}
\pgfpathcircle{\pgfpointorigin}{0.6\pgf@yb}
}
}
\pgfdeclareshape{tolstraightness}{
\inheritsavedanchors[from=rectangle]
\inheritanchorborder[from=rectangle]
\foreach \anchor in {center,north,south,west,east,north east,south east,north west, south west}{
\inheritanchor[from=rectangle]{\anchor}
}
\backgroundpath{%
\southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
%% The path
\pgfpathrectanglecorners
{\pgfpointadd{\southwest}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}
{\pgfpointadd{\northeast}{\pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}}
\pgfpathmoveto{\pgfpointadd{\pgfpointorigin}{\pgfpoint{-0.6\pgf@xb}{0pt}}}
\pgfpathlineto{\pgfpoint{0.6\pgf@xb}{0pt}}
}
}
\pgfdeclareshape{tolflatness}{
\inheritsavedanchors[from=rectangle]
\inheritanchorborder[from=rectangle]
\foreach \anchor in {center,north,south,west,east,north east,south east,north west, south west}{
\inheritanchor[from=rectangle]{\anchor}
}
\backgroundpath{%
\southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
%% The path
\pgfpathrectanglecorners
{\pgfpointadd{\southwest}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}
{\pgfpointadd{\northeast}{\pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}}
\pgfusepath{stroke}
\pgfpathmoveto{\pgfpoint{-0.6\pgf@xb}{-0.3\pgf@yb}}
\pgfpathlineto{\pgfpoint{0.3\pgf@xb}{-0.3\pgf@yb}}
\pgfpathlineto{\pgfpoint{0.6\pgf@xb}{0.3\pgf@yb}}
\pgfpathlineto{\pgfpoint{-0.3\pgf@xb}{0.3\pgf@yb}}
\pgfpathclose
}
}
\pgfdeclareshape{tolcircularity}{
\inheritsavedanchors[from=rectangle]
\inheritanchorborder[from=rectangle]
\foreach \anchor in {center,north,south,west,east,north east,south east,north west, south west}{
\inheritanchor[from=rectangle]{\anchor}
}
\backgroundpath{%
\southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
%% The path
\pgfpathrectanglecorners
{\pgfpointadd{\southwest}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}
{\pgfpointadd{\northeast}{\pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}}
\pgfusepath{stroke}
\pgfpathcircle{\pgfpointorigin}{0.6\pgf@yb}
}
}
\pgfdeclareshape{tolcylindricity}{
\inheritsavedanchors[from=rectangle]
\inheritanchorborder[from=rectangle]
\foreach \anchor in {center,north,south,west,east,north east,south east,north west, south west}{
\inheritanchor[from=rectangle]{\anchor}
}
\backgroundpath{
\southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
%% The path
\pgfpathrectanglecorners
{\pgfpointadd{\southwest}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}
{\pgfpointadd{\northeast}{\pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}}
\pgfusepath{stroke}
{
\pgftransformrotate{60}
\pgfpathmoveto{\pgfpoint{-\pgf@xb}{0.4\pgf@yb}}
\pgfpathlineto{\pgfpoint{0.6\pgf@xb}{0.4\pgf@yb}}
\pgfpathmoveto{\pgfpoint{-0.6\pgf@xb}{-0.4\pgf@yb}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{-0.4\pgf@yb}}
}
\pgfusepath{stroke}
\pgfpathcircle{\pgfpointorigin}{0.4\pgf@yb}
}
}
\pgfdeclareshape{tolprofile line}{
\inheritsavedanchors[from=rectangle]
\inheritanchorborder[from=rectangle]
\foreach \anchor in {center,north,south,west,east,north east,south east,north west, south west}{
\inheritanchor[from=rectangle]{\anchor}
}
\backgroundpath{%
\southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
%% The path
\pgfpathrectanglecorners
{\pgfpointadd{\southwest}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}
{\pgfpointadd{\northeast}{\pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}}
\pgfusepath{stroke}
\pgfpathmoveto{\pgfpoint{-0.6\pgf@yb}{-0.3\pgf@yb}}
\pgfpatharc{180}{0}{0.6\pgf@yb}
}
}
\pgfdeclareshape{tolprofile surface}{
\inheritsavedanchors[from=rectangle]
\inheritanchorborder[from=rectangle]
\foreach \anchor in {center,north,south,west,east,north east,south east,north west, south west}{
\inheritanchor[from=rectangle]{\anchor}
}
%% The path
\backgroundpath{
\southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgfpathrectanglecorners
{\pgfpointadd{\southwest}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}
{\pgfpointadd{\northeast}{\pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}}
\pgfusepath{stroke}
\pgfpathmoveto{\pgfpoint{-0.6\pgf@yb}{-0.3\pgf@yb}}
\pgfpatharc{180}{0}{0.6\pgf@yb}
\pgfpathclose
}
}
\pgfdeclareshape{tolperpendicularity}{
\inheritsavedanchors[from=rectangle]
\inheritanchorborder[from=rectangle]
\foreach \anchor in {center,north,south,west,east,north east,south east,north west, south west}{
\inheritanchor[from=rectangle]{\anchor}
}
%% The path
\backgroundpath{
\southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgfpathrectanglecorners
{\pgfpointadd{\southwest}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}
{\pgfpointadd{\northeast}{\pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}}
\pgfpathmoveto{\pgfpoint{-0.6\pgf@yb}{-0.6\pgf@yb}}
\pgfpathlineto{\pgfpoint{0.6\pgf@yb}{-0.6\pgf@yb}}
\pgfpathmoveto{\pgfpoint{0pt}{-0.6\pgf@yb}}
\pgfpathlineto{\pgfpoint{0pt}{0.6\pgf@yb}}
}
}
\pgfdeclareshape{tolangularity}{
\inheritsavedanchors[from=rectangle]
\inheritanchorborder[from=rectangle]
\foreach \anchor in {center,north,south,west,east,north east,south east,north west, south west}{
\inheritanchor[from=rectangle]{\anchor}
}
%% The path
\backgroundpath{
\southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgfpathrectanglecorners
{\pgfpointadd{\southwest}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}
{\pgfpointadd{\northeast}{\pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}}
\pgfusepath{stroke}
\pgfpathmoveto{\pgfpoint{0.6\pgf@yb}{0.6\pgf@yb}}
\pgfpathlineto{\pgfpoint{-0.6\pgf@yb}{-0.6\pgf@yb}}
\pgfpathlineto{\pgfpoint{0.6\pgf@yb}{-0.6\pgf@yb}}
}
}
\pgfdeclareshape{tolparallelism}{
\inheritsavedanchors[from=rectangle]
\inheritanchorborder[from=rectangle]
\foreach \anchor in {center,north,south,west,east,north east,south east,north west, south west}{
\inheritanchor[from=rectangle]{\anchor}
}
%% The path
\backgroundpath{
\southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgfpathrectanglecorners
{\pgfpointadd{\southwest}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}
{\pgfpointadd{\northeast}{\pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}}
\pgfusepath{stroke}
\pgfpathmoveto{\pgfpoint{-0.5\pgf@yb}{-0.6\pgf@yb}}
\pgfpathlineto{\pgfpoint{0pt}{0.6\pgf@yb}}
\pgfpathmoveto{\pgfpoint{0pt}{-0.6\pgf@yb}}
\pgfpathlineto{\pgfpoint{0.5\pgf@yb}{0.6\pgf@yb}}
}
}
\pgfdeclareshape{tolsymmetry}{
\inheritsavedanchors[from=rectangle]
\inheritanchorborder[from=rectangle]
\foreach \anchor in {center,north,south,west,east,north east,south east,north west, south west}{
\inheritanchor[from=rectangle]{\anchor}
}
%% The path
\backgroundpath{
\southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgfpathrectanglecorners
{\pgfpointadd{\southwest}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}
{\pgfpointadd{\northeast}{\pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}}
\pgfpathmoveto{\pgfpoint{-0.4\pgf@yb}{-0.4\pgf@yb}}
\pgfpathlineto{\pgfpoint{0.4\pgf@yb}{-0.4\pgf@yb}}
\pgfpathmoveto{\pgfpoint{-0.6\pgf@yb}{0pt}}
\pgfpathlineto{\pgfpoint{0.6\pgf@yb}{0pt}}
\pgfpathmoveto{\pgfpoint{-0.4\pgf@yb}{0.4\pgf@yb}}
\pgfpathlineto{\pgfpoint{0.4\pgf@yb}{0.4\pgf@yb}}
}
}
\pgfdeclareshape{tolconcentricity}{
\inheritsavedanchors[from=rectangle]
\inheritanchorborder[from=rectangle]
\foreach \anchor in {center,north,south,west,east,north east,south east,north west, south west}{
\inheritanchor[from=rectangle]{\anchor}
}
%% The path
\backgroundpath{
\southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgfpathrectanglecorners
{\pgfpointadd{\southwest}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}
{\pgfpointadd{\northeast}{\pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}}
\pgfusepath{stroke}
{\pgfpathcircle{\pgfpointorigin}{0.6\pgf@yb}}
\pgfpathcircle{\pgfpointorigin}{0.4\pgf@yb}
}
}
\pgfdeclareshape{tolcircular runout}{
\inheritsavedanchors[from=rectangle]
\inheritanchorborder[from=rectangle]
\foreach \anchor in {center,north,south,west,east,north east,south east,north west, south west}{
\inheritanchor[from=rectangle]{\anchor}
}
%% The path
\backgroundpath{
\southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgfpathrectanglecorners
{\pgfpointadd{\southwest}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}
{\pgfpointadd{\northeast}{\pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}}
\pgfusepath{stroke}
\pgfpathmoveto{\pgfpointadd
{\pgfpoint{0pt}{0pt}}
{\pgfpointpolar{50}{0.2\pgf@yb}}
}
\pgfpathlineto{\pgfpointadd
{\pgfpoint{0pt}{0pt}}
{\pgfpointpolar{50}{-0.7\pgf@yb}}
}
\pgfusepath{stroke}
{\pgftransformrotate{-40}
\pgfpathmoveto{\pgfpoint{-0.2\pgf@yb}{0.2\pgf@yb}}
\pgfpathlineto{\pgfpoint{0.2\pgf@yb}{0.2\pgf@yb}}
\pgfpathlineto{\pgfpoint{0pt}{0.7\pgf@yb}}
\pgfpathclose
\pgfusepath{fill}
}
}
}
\pgfdeclareshape{toltotal runout}{
\inheritsavedanchors[from=rectangle]
\inheritanchorborder[from=rectangle]
\foreach \anchor in {center,north,south,west,east,north east,south east,north west, south west}{
\inheritanchor[from=rectangle]{\anchor}
}
%% The path
\backgroundpath{
\southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgfpathrectanglecorners
{\pgfpointadd{\southwest}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}
{\pgfpointadd{\northeast}{\pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}}
\pgfusepath{stroke}
\pgfpathmoveto{\pgfpointadd
{\pgfpoint{-0.3\pgf@yb}{0pt}}
{\pgfpointpolar{50}{0.2\pgf@yb}}
}
\pgfpathlineto{\pgfpointadd
{\pgfpoint{-0.3\pgf@yb}{0pt}}
{\pgfpointpolar{50}{-0.7\pgf@yb}}
}
\pgfpathlineto{\pgfpointadd
{\pgfpoint{0.3\pgf@yb}{0pt}}
{\pgfpointpolar{50}{-0.7\pgf@yb}}
}
\pgfpathlineto{\pgfpointadd
{\pgfpoint{0.3\pgf@yb}{0pt}}
{\pgfpointpolar{50}{0.2\pgf@yb}}
}
\pgfusepath{stroke}
{
\pgftransformxshift{-0.3\pgf@yb}
\pgftransformrotate{-40}
\pgfpathmoveto{\pgfpoint{-0.2\pgf@yb}{0.2\pgf@yb}}
\pgfpathlineto{\pgfpoint{0.2\pgf@yb}{0.2\pgf@yb}}
\pgfpathlineto{\pgfpoint{0pt}{0.7\pgf@yb}}
\pgfpathclose
\pgfusepath{fill}
}
{
\pgftransformxshift{0.3\pgf@yb}
\pgftransformrotate{-40}
\pgfpathmoveto{\pgfpoint{-0.2\pgf@yb}{0.2\pgf@yb}}
\pgfpathlineto{\pgfpoint{0.2\pgf@yb}{0.2\pgf@yb}}
\pgfpathlineto{\pgfpoint{0pt}{0.7\pgf@yb}}
\pgfpathclose
\pgfusepath{fill}
}
}
}
\pgfdeclareshape{tolmodifier}{
\inheritsavedanchors[from=rectangle]
\inheritanchorborder[from=rectangle]
\foreach \anchor in {center,north,south,west,east,north east,south east,north west, south west}{
\inheritanchor[from=rectangle]{\anchor}
}
\backgroundpath{% this is new
% store lower right in xa/ya and upper right in xb/yb
\southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
% construct main path
\pgfpathrectanglecorners
{\pgfpointadd{\southwest}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}
{\pgfpointadd{\northeast}{\pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}}
\pgfusepath{stroke}
\pgfpathcircle{\pgfpointlineattime{0.5}{\southwest}{\northeast}}{0.55\pgf@yb}
}
}
\makeatother
\tikzset{
tolstyle/.style={
draw,
on chain=going right,
inner ysep=0pt,
minimum height=1.7em
},
type/.style={tol#1},
modifier/.style={tolmodifier,font=#1}
}
\newcommand{\tol}[1]{%
\begin{tikzpicture}[baseline=-0.3em,
start chain,
node distance=-\pgflinewidth
]
\foreach \content in {#1} {
\IfSubStr{\content}{type}{
\edef\donode{%
\noexpand\node[
tolstyle,
minimum width=\noexpand\pgfkeysvalueof{/pgf/minimum height},
\content
]{};
}
\donode
}{
\IfSubStr{\content}{modifier}{
\edef\donode{\noexpand\node[tolstyle,tolmodifier,minimum width=\noexpand\pgfkeysvalueof{/pgf/minimum height},\content]{};}
\donode
}
\node[tolstyle]{\content};
}
}
\end{tikzpicture}%
}
\begin{document}
\begin{minipage}{4.2cm}
\foreach \type in {straightness, flatness, circularity, cylindricity, profile line, profile surface, perpendicularity, angularity, parallelism, symmetry, position, concentricity, circular runout, total runout}{
\texttt{\type}:\hfill \tol{type=\type}\par
}
\end{minipage}
\vspace{1cm}
Example usage:
\verb|\tol{type=position,3,2,1,modifier=M}|
\tol{type=position,3,2,1,modifier=M}
\end{document}