每一厘米都做一条线标记

每一厘米都做一条线标记

我正在为一系列家具(例如一张桌子)构建 TikZ 图。

因为确切的长度很重要,我希望构成矩形边界的四条线中的每一条线都为它们跨越的每一厘米都有一个小标记,这样我就可以用眼睛轻松地识别长度。

我认为装饰可能是一种方法,但我在 TikZ 文档中没有找到任何合适的方法。绘图区域中的轴也可能是一种方法?

我目前的解决方法是一种稍微不同的方法,但也许有人知道在 TikZ 中处理它的好方法?

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{backgrounds}

\begin{document}

\begin{tikzpicture}
    \node[%
        rectangle,
        draw,
        gray,
        line width=.5mm,
        minimum width=2.2cm, minimum height=1.6cm,
        inner sep=0.2mm] (box) {%
            Table%
        };

    % measure lines
    \draw[line width=.5mm, dash pattern=on 1cm off 0.01cm on 1cm, xshift=5mm, yshift=.25mm] (box.north west) -- (box.north east);
    \draw[line width=.5mm, dash pattern=on 1cm off 0.01cm on 1cm, xshift=5mm, yshift=.25mm] (box.north west) -- (box.south west);
    \draw[line width=.5mm, dash pattern=on 1cm off 0.01cm on 1cm, xshift=5mm, yshift=.25mm] (box.south east) -- (box.south west);
    \draw[line width=.5mm, dash pattern=on 1cm off 0.01cm on 1cm, xshift=5mm, yshift=.25mm] (box.south east) -- (box.north east);

    \begin{scope}[on background layer]
        \node[circle,draw=black,fill=darkgray,minimum size=0.25cm] at (box.north east) {};
        \draw[gray] (box.north east) -- (box.south west) ;
        \draw[gray] (box.north west) -- (box.south east) ;
    \end{scope}

    \end{tikzpicture}

\end{document}

感谢您的想法和意见!

答案1

这几乎逐字逐句地取自 pgfmanual 第 585 页的第二个例子。

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{backgrounds,decorations.markings}

\begin{document}

\begin{tikzpicture}[cm mark/.style={postaction=decorate,
decoration={markings,% switch on markings mark=% actually add a mark
      mark=between positions 0 and 1 step 1cm
      with
      {
        \draw[#1] (0pt,-2pt) -- (0pt,2pt);
      }
}}]
    \node[%
        rectangle,
        draw,
        gray,
        line width=.5mm,
        minimum width=2.2cm, minimum height=1.6cm,
        inner sep=0.2mm] (box) {%
            Table%
        };

    % measure lines
    \draw[line width=.5mm, dash pattern=on 1cm off 0.01cm on 1cm, xshift=5mm,
    yshift=.25mm,cm mark={blue,thin}] (box.north west) -- (box.north east);
    \draw[line width=.5mm, dash pattern=on 1cm off 0.01cm on 1cm, xshift=5mm,
    yshift=.25mm,,cm mark={red,line width=0.4pt}] (box.north west) -- (box.south west);
    \draw[line width=.5mm, dash pattern=on 1cm off 0.01cm on 1cm, xshift=5mm,
    yshift=.25mm,cm mark] (box.south east) -- (box.south west);
    \draw[line width=.5mm, dash pattern=on 1cm off 0.01cm on 1cm, xshift=5mm, yshift=.25mm] (box.south east) -- (box.north east);

    \begin{scope}[on background layer]
        \node[circle,draw=black,fill=darkgray,minimum size=0.25cm] at (box.north east) {};
        \draw[gray] (box.north east) -- (box.south west) ;
        \draw[gray] (box.north west) -- (box.south east) ;
    \end{scope}

    \end{tikzpicture}

\end{document}

在此处输入图片描述

这是另一个打印距离的版本。

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{backgrounds,decorations.markings}

\begin{document}

\begin{tikzpicture}[cm mark/.style args={#1 with labels #2}{postaction=decorate,
decoration={markings,% switch on markings mark=% actually add a mark
      mark=between positions 0 and 1 step 1cm
      with
      {
      \pgfmathtruncatemacro{\mydist}{\pgfkeysvalueof{/pgf/decoration/mark
      info/sequence number}-1}
        \draw[#1] (0pt,-2pt) -- (0pt,2pt);
        \coordinate (Xmark) at (0,0);
        \pgftransformreset
        \path (Xmark) node[#1,outer sep=3pt,#2]  {$\mydist$cm};
      }
}}]
    \node[%
        rectangle,
        draw,
        gray,
        line width=.5mm,
        minimum width=2.2cm, minimum height=1.6cm,
        inner sep=0.2mm] (box) {%
            Table%
        };

    % measure lines
    \draw[line width=.5mm, dash pattern=on 1cm off 0.01cm on 1cm, xshift=5mm,
    yshift=.25mm,cm mark={{blue,thin} with labels above}] (box.north west) -- (box.north east);
    \draw[line width=.5mm, dash pattern=on 1cm off 0.01cm on 1cm, xshift=5mm,
    yshift=.25mm,cm mark={{line width=0.4pt,green!60!black} with labels left}] (box.north west) -- (box.south west);
    \draw[line width=.5mm, dash pattern=on 1cm off 0.01cm on 1cm, xshift=5mm,
    yshift=.25mm,cm mark={{line width=0.4pt,red} with labels below}] (box.south east) -- (box.south west);
    \draw[line width=.5mm, dash pattern=on 1cm off 0.01cm on 1cm, xshift=5mm, yshift=.25mm] (box.south east) -- (box.north east);

    \begin{scope}[on background layer]
        \node[circle,draw=black,fill=darkgray,minimum size=0.25cm] at (box.north east) {};
        \draw[gray] (box.north east) -- (box.south west) ;
        \draw[gray] (box.north west) -- (box.south east) ;
    \end{scope}

    \end{tikzpicture}
\end{document}

在此处输入图片描述

我认为有很多方法可以定制这一点,例如删除 0 等等。然而,我的水晶球被盗了,我不知道您是否对这样的选择感兴趣。

相关内容