[Tex/LaTex] How to draw engineer dimensioning diagrams

diagramsengineering

How can I draw engineer dimensioning diagrams in LaTeX? For instance,

enter image description here

What I currently do is drawing the diagram in MS Visio, save as a pdf file and then embed it into LaTeX. (It is not easy to type mathematical formulas in Visio.)

Best Answer

Using the tikz-dimline package will get you:

\documentclass[tikz,border=2mm]{standalone}
\usepackage{tikz-dimline}\pgfplotsset{compat=newest}

\begin{document}
\begin{tikzpicture}[]
    \path   (0,0) coordinate (A)
            (4,0) coordinate (B)
            (12,0) coordinate (C)
            (16,0) coordinate (D)
            (0,2) coordinate (E)
            (4,2) coordinate (F)
            (16,2) coordinate (G);

    \draw[gray!10,fill=yellow] (E) rectangle (B) node[black] at ($(E)!.5!(B)$){bus1};
    \draw[gray!10,fill=red] (F) rectangle (C) node[black] at ($(F)!.5!(C)$){overlapping};
    \draw[gray!10,fill=green] (C) rectangle (G) node[black] at ($(C)!.5!(G)$){bus2};

    \dimline    [color=blue,
                line style={thick},
                extension start style={blue,thin},
                extension end style={blue,thin}
                ]{($(E)+(0,.5)$)}{($(G)+(0,.5)$)}{$t_c$};
    \dimline    [color=blue,
                line style={thick},
                extension start style={blue,thin},
                extension end style={blue,thin},
                extension start length=-1cm,
                extension end length=-1cm
                ]{($(A)-(0,.5)$)}{($(B)-(0,.5)$)}{$(t_c-t_{12})/2$};
    \dimline    [color=blue,
                line style={thick},
                extension start style={blue,thin},
                extension end style={blue,thin},
                extension start length=-1cm,
                extension end length=-1cm
                ]{($(B)-(0,.5)$)}{($(C)-(0,.5)$)}{$t_{12}$};
    \dimline    [color=blue,
                line style={thick},
                extension start style={blue,thin},
                extension end style={blue,thin},
                extension start length=-1cm,
                extension end length=-1cm
                ]{($(C)-(0,.5)$)}{($(D)-(0,.5)$)}{$(t_c-t_{12})/2$};
\end{tikzpicture}
\end{document}

enter image description here

Using Tarass's excellent solution from Dimensioning of a technical drawing in TikZ will get you:

\documentclass[tikz,border=2mm]{standalone}
\usepackage{xparse}
\usetikzlibrary{calc}

\tikzset{%
    Cote node/.style={%
        midway,
        sloped,
        fill=white,
        inner sep=1.5pt,
        outer sep=2pt
    },
    Cote arrow/.style={%
        <->,
        >=latex,
        very thin
    }
}

\makeatletter
\NewDocumentCommand{\Cote}{%
    s               % cotation avec les flèches à l'extérieur
    D<>{1.5pt}      % offset des traits
    O{.75cm}        % offset de cotation
    m               % premier point
    m               % second point
    m               % étiquette
    D<>{o}          % () coordonnées -> angle
                    % h -> horizontal,
                    % v -> vertical
                    % o or what ever -> oblique
    O{}             % parametre du tikzset
}{%
    {%
        \tikzset{#8}

        \coordinate (@1) at #4 ;
        \coordinate (@2) at #5 ;

        \if #7v % Cotation verticale
            \coordinate (@0) at ($($#4!.5!#5$) + (#3,0)$) ; 
            \coordinate (@4) at (@0|-@1) ;
            \coordinate (@5) at (@0|-@2) ;
        \else
            \if #7h % Cotation horizontale
                \coordinate (@0) at ($($#4!.5!#5$) + (0,#3)$) ; 
                \coordinate (@4) at (@0-|@1) ;
                \coordinate (@5) at (@0-|@2) ;
            \else % cotation encoche
                \ifnum\pdfstrcmp{\unexpanded\expandafter{\@car#7\@nil}}{(}=\z@
                    \coordinate (@5) at ($#7!#3!#5$) ;
                    \coordinate (@4) at ($#7!#3!#4$) ;
                \else % cotation oblique    
                    \coordinate (@5) at ($#5!#3!90:#4$) ;
                    \coordinate (@4) at ($#4!#3!-90:#5$) ;
                \fi
            \fi
        \fi

        \draw[very thin,shorten >= #2,shorten <= -2*#2] (@4) -- #4 ;
        \draw[very thin,shorten >= #2,shorten <= -2*#2] (@5) -- #5 ;

        \IfBooleanTF #1 {% avec étoile
            \draw[Cote arrow,-] (@4) -- (@5) node[Cote node] {#6\strut};
            \draw[Cote arrow,<-] (@4) -- ($(@4)!-6pt!(@5)$) ;   
            \draw[Cote arrow,<-] (@5) -- ($(@5)!-6pt!(@4)$) ;   
        }{% sans étoile
            \ifnum\pdfstrcmp{\unexpanded\expandafter{\@car#7\@nil}}{(}=\z@
                \draw[Cote arrow] (@5) to[bend right] node[Cote node] {#6\strut} (@4) ;
            \else
                \draw[Cote arrow] (@4) -- (@5) node[Cote node] {#6\strut};
            \fi
        }
    }
}
\makeatother

\begin{document}
\begin{tikzpicture}
    \path   (0,0) coordinate (A)
            (4,0) coordinate (B)
            (12,0) coordinate (C)
            (16,0) coordinate (D)
            (0,2) coordinate (E)
            (4,2) coordinate (F)
            (16,2) coordinate (G);

    \draw[gray!10,fill=yellow] (E) rectangle (B) node[black] at ($(E)!.5!(B)$){bus1};
    \draw[gray!10,fill=red] (F) rectangle (C) node[black] at ($(F)!.5!(C)$){overlapping};
    \draw[gray!10,fill=green] (C) rectangle (G) node[black] at ($(C)!.5!(G)$){bus2};

    \Cote{(E)}{(G)}{$t_c$}<h>
    \Cote{(A)}{(B)}{$(t_c-t_{12})/2$}
    \Cote{(B)}{(C)}{$t_{12}$}
    \Cote{(C)}{(D)}{$(t_c-t_{12})/2$}

\end{tikzpicture}
\end{document}

enter image description here