LaTeX 中的技术绘图

LaTeX 中的技术绘图

我知道一些关于 LaTeX 技术图纸的问题,例如,

这些仅解决了我的问题的部分内容,而非全部内容。

我申请技术非常基础技术制图相当简单。考虑 MWE

\documentclass[a4paper, landscape]{article}

\usepackage{tikz}
\usepackage{geometry}

\usetikzlibrary{arrows.meta}
\usetikzlibrary{patterns}

\geometry{margin=0mm}
\pagestyle{empty}

\makeatletter

\newlength{\td@FullWidth}
\newlength{\td@HalfWidth}
\newlength{\td@TextSizeL}
\newlength{\td@TextSizeM}

\setlength{\td@FullWidth}{0.50mm}
\setlength{\td@HalfWidth}{0.25mm}
\setlength{\td@TextSizeL}{3.50mm}
\setlength{\td@TextSizeM}{2.50mm}
\def\td@RuleDist{5.00mm}
\def\td@ArrowLength{2.50mm}
\def\td@ArrowWidth{0.669873mm}

\tikzstyle{tdEdge}   = [line width=\td@FullWidth]
\tikzstyle{tdHidden} = [line width=\td@HalfWidth, dash pattern=on 2.50mm off 1.00mm]
\tikzstyle{tdSym}    = [line width=\td@HalfWidth, dash pattern=on 2.50mm off 0.50mm on 0.25mm off 0.50mm]
\tikzstyle{tdHelp}   = [line width=\td@HalfWidth]
\tikzstyle{tdDim}    = [line width=\td@HalfWidth, <->, >={Triangle[length=\td@ArrowLength, width=\td@ArrowWidth]}]

\pgfdeclarepatternformonly{tdRuled}
  {\pgfqpoint{-1pt}{-1pt}}
  {\pgfqpoint{\td@RuleDist}{\td@RuleDist}}
  {\pgfqpoint{\td@RuleDist}{\td@RuleDist}}
  {
    \pgfsetlinewidth{\td@HalfWidth}
    \pgfsys@rectcap
    \pgfpathmoveto{\pgfqpoint{0mm}{0mm}}
    \pgfpathlineto{\pgfqpoint{\td@RuleDist}{\td@RuleDist}}
    \pgfusepath{stroke}
  }

\makeatother

\begin{document}

\begin{center}
\begin{tikzpicture}[x=1mm, y=1mm]
\sffamily
\draw[color=white] (0, 0) -- (296.8, 0) -- (296.8, 209.8);

\begin{scope}[shift={(5, 5)}]

  \draw[tdEdge] (0, 0) -- (287, 0) -- (287, 200) -- (0, 200) -- (0, 0);
  \draw[tdEdge] (112, 0) -- (112, 15) -- (287, 15);
  \node[anchor=west] at (117, 7.5) {\textbf{Description}};

  \small

  \begin{scope}[shift={(40, 180)}]
    \draw[tdEdge] (0, 0) -- (20, 0) -- (20, -40) -- (40, -40) -- (40, -60) -- (0, -60) -- (0, -50) -- (10, -50) -- (10, -15) -- (0, -15) -- (0, 0);
    \draw[tdHelp] (0, 0) -- (-12, 0);
    \draw[tdHelp] (0, -60) -- (-12,-60);
    \draw[tdDim] (-10, 0) -- (-10, -60); \node[anchor=east] at (-10, -30) {\rotatebox{90}{60}};
  \end{scope}

  \begin{scope}[shift={(120, 180)}]
    \draw[tdEdge] (0, 0) -- (30, 0) -- (30, -60) -- (0, -60) -- (0, 0);
    \draw[tdHidden] (0, -15) -- (30, -15);
    \draw[tdEdge] (0, -40) -- (30, -40);
    \draw[tdHidden] (0, -50) -- (30, -50);
    \draw[tdHelp] (30, 0) -- (42, 0);
    \draw[tdHelp] (30, -15) -- (42, -15);
    \draw[tdHelp] (30, -40) -- (42, -40);
    \draw[tdHelp] (30, -50) -- (42, -50);
    \draw[tdHelp] (30, -60) -- (42, -60);
    \draw[tdDim] (40, 0) -- (40, -15); \node[anchor=east] at (40, -7.5) {\rotatebox{90}{15}};
    \draw[tdDim] (40, -40) -- (40, -50); \node[anchor=east] at (40, -45) {\rotatebox{90}{10}};
    \draw[tdDim] (40, -50) -- (40, -60); \node[anchor=east] at (40, -55) {\rotatebox{90}{10}};
  \end{scope}

  \begin{scope}[shift={(40, 80)}]
    \draw[tdEdge] (0, 0) -- (40, 0) -- (40, -30) -- (0, -30) -- (0, 0);
    \draw[tdHidden] (10, 0) -- (10, -30);
    \draw[tdEdge] (20, 0) -- (20, -30);
    \draw[tdHelp] (0, -30) -- (0, -42);
    \draw[tdHelp] (10, -30) -- (10, -42);
    \draw[tdHelp] (20, -30) -- (20, -42);
    \draw[tdHelp] (40, -30) -- (40, -42);
    \draw[tdDim] (0, -40) -- (10, -40); \node[anchor=south] at (5, -40) {10};
    \draw[tdDim] (10, -40) -- (20, -40); \node[anchor=south] at (15, -40) {10};
    \draw[tdDim] (20, -40) -- (40, -40); \node[anchor=south] at (30, -40) {20}; 
    \draw[tdHelp] (0, 0) -- (-12, 0);
    \draw[tdHelp] (0, -30) -- (-12, -30);
    \draw[tdDim] (-10, 0) -- (-10, -30); \node[anchor=east] at (-10, -15) {\rotatebox{90}{30}};
  \end{scope}

\end{scope}

\end{tikzpicture}
\end{center}

\end{document}

这导致以下输出。

MWE 的输出

一般来说,最好的方法可能是使用外部 CAD 工具来创建此类技术图纸,并将它们作为 PDF 文件嵌入到要使用 LaTeX 创建的文档中。但是,当处理大量非常小而简单的图纸时(例如,在学生的工作表中),我更愿意将所有内容放在一个 LaTeX 文件中,而不是在应用程序之间切换。

因此我想问以下几个问题:

  1. 是否有符合 EN ISO 3098 并且可以在 LaTeX 中使用的免费字体?
  2. 是否有任何软件包可以通过定义更强大的命令(例如引入尺寸标注)来帮助根据适用的 DIN / EN ISO 标准创建简单的技术图纸?
  3. 您是否看到一种或另一种方法可以用最小的努力来改进和/或简化上述代码?

答案1

从评论中获取一些信息并添加更多信息:

有一种类似于 EN ISO 3098 的开放字体可从https://github.com/hikikomori82/osifont使用 XeTeX 或 LuaTeX 就很简单了

\usepackage{fontspec}
\setmainfont{osifont-lgpl3fe.ttf}

要使用它,可以使用 lcdf-tools 或 autoinst 转换为 pdfLaTeX。


@Ross 提到的 dimline 包可能会有所帮助https://ctan.org/pkg/tikz-dimline?lang=en但除此之外,我不知道有任何具体的帮助者


我建议的简化方法包括使用|--|以及使用语法++()cycle。定义尺寸线距离的参数,例如\def\tdHelp{12}\def\tdDim{10}也可能有帮助。您还可以更多地使用将坐标保存到名称中,就像我在下面的完整示例中所做的那样,只需检查您喜欢的内容即可。


结果如下: 在此处输入图片描述

代码如下:

\documentclass[a4paper, landscape]{article}
\usepackage{fontspec}
\setmainfont{osifont-lgpl3fe.ttf}

\usepackage{tikz}
\usepackage{geometry}

\usetikzlibrary{arrows.meta}
\usetikzlibrary{patterns,calc}

\geometry{margin=0mm}
\pagestyle{empty}

\makeatletter

\newlength{\td@FullWidth}
\newlength{\td@HalfWidth}
\newlength{\td@TextSizeL}
\newlength{\td@TextSizeM}

\setlength{\td@FullWidth}{0.50mm}
\setlength{\td@HalfWidth}{0.25mm}
\setlength{\td@TextSizeL}{3.50mm}
\setlength{\td@TextSizeM}{2.50mm}
\def\td@RuleDist{5.00mm}
\def\td@ArrowLength{2.50mm}
\def\td@ArrowWidth{0.669873mm}

\tikzstyle{tdEdge}   = [line width=\td@FullWidth]
\tikzstyle{tdHidden} = [line width=\td@HalfWidth, dash pattern=on 2.50mm off 1.00mm]
\tikzstyle{tdSym}    = [line width=\td@HalfWidth, dash pattern=on 2.50mm off 0.50mm on 0.25mm off 0.50mm]
\tikzstyle{tdHelp}   = [line width=\td@HalfWidth]
\tikzstyle{tdDim}    = [line width=\td@HalfWidth, <->, >={Triangle[length=\td@ArrowLength, width=\td@ArrowWidth]}]
\tikzstyle{tdDimNode}    = [midway,sloped,above,font=\small]

\pgfdeclarepatternformonly{tdRuled}
{\pgfqpoint{-1pt}{-1pt}}
{\pgfqpoint{\td@RuleDist}{\td@RuleDist}}
{\pgfqpoint{\td@RuleDist}{\td@RuleDist}}
{
    \pgfsetlinewidth{\td@HalfWidth}
    \pgfsys@rectcap
    \pgfpathmoveto{\pgfqpoint{0mm}{0mm}}
    \pgfpathlineto{\pgfqpoint{\td@RuleDist}{\td@RuleDist}}
    \pgfusepath{stroke}
}

\def\tdHelp{12}
\def\tdDim{10}

\makeatother

\begin{document}
    \begin{center}
        \begin{tikzpicture}[x=1mm, y=1mm]
        \useasboundingbox (0, 0) rectangle (297, 210);
        
        \draw[tdEdge] (5, 205) rectangle (292, 5)node(lower_right){};
        \node[text width=175mm,anchor=south east,tdEdge,draw,minimum height=15mm,outer sep=0pt] at (lower_right) {Description};
        
        \begin{scope}[shift={(40, 180)}]
            \draw[tdEdge] (0, 0)coordinate(A) -| (20, -40) -| (40, -60) -- (0, -60)coordinate(B) |- (10, -50) |- (0, -15) -- cycle;
            \draw[tdHelp] (A) -- ++(-\tdHelp,0);
            \draw[tdHelp] (B) -- ++(-\tdHelp,0);
            \draw[tdDim] ($(B)-(\tdDim,0)$) -- ($(A)-(\tdDim,0)$)node[tdDimNode]{60};
        \end{scope}
        
        \begin{scope}[shift={(120, 180)}]
            \draw[tdEdge] (0, 0) -- ++(30,0)coordinate(A) -- (30, -15)coordinate(B) -- (30, -40)coordinate(C) -- ++(0,-10)coordinate(D) -- (30, -60)coordinate(E) -| cycle;
            \draw[tdHidden] (B) -- ++(-30, 0);
            \draw[tdEdge] (C) -- ++(-30, 0);
            \draw[tdHidden] (D) -- ++(-30, 0);
            \draw[tdHelp] (A) -- ++(\tdHelp,0);
            \draw[tdHelp] (B) -- ++(\tdHelp,0);
            \draw[tdHelp] (C) -- ++(\tdHelp,0);
            \draw[tdHelp] (D) -- ++(\tdHelp,0);
            \draw[tdHelp] (E) -- ++(\tdHelp,0);
            \draw[tdDim] ($(B)+(\tdDim,0)$) -- ($(A)+(\tdDim,0)$)node[tdDimNode]{15};
            \draw[tdDim] ($(D)+(\tdDim,0)$) -- ($(C)+(\tdDim,0)$)node[tdDimNode]{10};
            \draw[tdDim] ($(E)+(\tdDim,0)$) -- ($(D)+(\tdDim,0)$)node[tdDimNode]{10};
        \end{scope}
            
        \begin{scope}[shift={(40, 80)}]
            \draw[tdEdge] (0, 0)coordinate(E) -| (40, -30)coordinate(A) -- ++(-20,0)coordinate(B) -- ++(-10,0)coordinate(C) -- ++(-10,0)coordinate(D) -- cycle;
            \draw[tdHidden] (C) -- ++(0, 30);
            \draw[tdEdge] (B) -- ++(0, 30);
            \draw[tdHelp] (A) -- ++(0,-\tdHelp);
            \draw[tdHelp] (B) -- ++(0,-\tdHelp);
            \draw[tdHelp] (C) -- ++(0,-\tdHelp);
            \draw[tdHelp] (D) -- ++(0,-\tdHelp);
            \draw[tdDim] ($(D)+(0,-\tdDim)$) -- ($(C)+(0,-\tdDim)$)node[tdDimNode]{10};
            \draw[tdDim] ($(C)+(0,-\tdDim)$) -- ($(B)+(0,-\tdDim)$)node[tdDimNode]{10};
            \draw[tdDim] ($(B)+(0,-\tdDim)$) -- ($(A)+(0,-\tdDim)$)node[tdDimNode]{20};
            \draw[tdHelp] (D) -- ++(-\tdHelp,0);
            \draw[tdHelp] (E) -- ++(-\tdHelp,0);
            \draw[tdDim] ($(D)+(-\tdDim,0)$) -- ($(E)+(-\tdDim,0)$)node[tdDimNode]{30};
        \end{scope}
        
        \end{tikzpicture}
    \end{center}
    
\end{document}

相关内容