Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am a beginner in LaTeX, trying to use it for an industrial metrology test report, where I need to use geometry tolerances. I have tentatively made a first one with TikZ, but this is hard coded and therefore not flexible. I need in some cases to change the number of reference planes from only 1 to 3 such as in the example (A,B,C) Conversely there is a need to use one or two digits in the main tolerance, and sometimes a symbol (such as "DIA") as prefix. It seemed to me that using chains would be a much more promising route, but I cannot make it work, the symbol is not placed at the left side, and the lines do not align properly. Would someone suggest a solution?

\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}
share|improve this question

1 Answer 1

up vote 12 down vote accepted

I've defined node shapes for all the symbols found on http://en.wikipedia.org/wiki/Geometric_dimensioning_and_tolerancing#Symbols, plus one symbol for creating modifiers that takes a letter as its argument.

The line \tol{type=position,3,2,1,modifier=M} will print

The symbols are accessed using type=<type>. Here's a list of all the types that are available:

\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}
share|improve this answer
    
Thanks.This is beautiful. Is there a way to combine the commands, ie something that would be more like \tol{\target}{0.32}{A}{B}{C} ? –  Yves Apr 26 '12 at 18:34
    
I found myself the solution: \newcommand{\tol}[5]{% \begin{tikzpicture}[ start chain, node distance=-\pgflinewidth ] #1;\tolgeom{#2}; \tolgeom{#3}; \tolgeom{#4}; \tolgeom{#5}; \end{tikzpicture} }% \tol{\target}{0,32}{A}{B}{C} –  Yves Apr 26 '12 at 18:50
    
@Yves: Will you always need five segments in your diagrams? –  Jake Apr 26 '12 at 18:51
    
No there are cases where there are only 3 ie only one reference plane, such as "A". I am not sure there is an easy way (except of course dedicating one command to every case..) to take care of this situation, since the number of arguments define the number of "cells"... –  Yves Apr 26 '12 at 20:01
1  
@Yves: I've turned the whole thing into a macro that takes a comma separated list of cells as an argument. If you need a cell to contain a comma, you'll have to enclose it in {...} (so for example \tol{target,A,{B,C}}). –  Jake Apr 26 '12 at 20:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.