TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to create a technical drawing of a magnetic write head with dimensions on it. I'm using some macros which help a lot from here: Dimensioning a technical drawing.



    \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;
%% 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}

    \draw[step=1cm,gray!50,very thin] (-10.5,-10.5) grid (10.5,10.5);
    \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;

% Begin document           %
\begin{frame}{Conventional writer design 1}
    \path[use as bounding box](-10,-10) rectangle (10,10);     % Set the BB

Unfortunately I can't paste the result as I'm new, but when I typeset the above, one of the dimensions that comes out is 85.59999

output of code

I have 2 questions:

  1. How do I make the 85.59999 to be 85.6?
  2. How do i take the 85.6 or the 64.4 that was computed in the \Dimline function and re-use that number? For example I want to put that number in a table listing some of the key parameters for this design.
share|improve this question

The problem is the inaccurate division step after the rounding operation, which is necessary because you can't specify the number of decimal digits for the rounding operation. A solution would be to use \pgfmathprintnumber[precision=1]{\pgfmathresult} to round and output the number. If you want to use the rounded number elsewhere, you can use \pgfmathprintnumberto{\pgfmathresult}{\roundednumber} to store the rounded number to a macro.

Changing the scaling function to

\def\DimScale#1{\pgfmathparse{#1/2.84}\pgfmathprintnumberto[precision=1]{\pgfmathresult}{\roundednumber} \roundednumber nm}


number rounded with pgfprintnumberto

share|improve this answer
Many thanks Jake. I've upgraded pgf to 2.10 and this works fine now. – Chah Jun 3 '11 at 8:02

siunitx has a \num function that you can use to round numbers. Some details here. For example, \num[round-mode=places,round-precision=1]{85.99999} should give you 85.9.

Or you can use \pgfmathprintnumber although this requires pgf 2.10. (Or at least, I can't get it to work with 2.00)

share|improve this answer

Your Answer


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.