TikZ - 如何绘制中断线?

TikZ - 如何绘制中断线?

请告诉我一个(尽可能简单的)绘制中断线的解决方案。我不知道这在技术上应该如何称呼;中断线、交错线、断线、不连续线?

这是我想要的图像。它不必是波浪形的(但如果是波浪形就更好了)。

在此处输入图片描述

答案1

这是一个装饰,它将在路径第一段的中点放置一个波浪形不连续符号。您可以使用 键控制两个波浪之间的距离segment length,使用 控制波浪的宽度amplitude,使用 控制波浪的程度meta-segment length

不连续符号

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations}

\begin{document}

\pgfdeclaredecoration{discontinuity}{start}{
  \state{start}[width=0.5\pgfdecoratedinputsegmentremainingdistance-0.5\pgfdecorationsegmentlength,next state=first wave]
  {}
  \state{first wave}[width=\pgfdecorationsegmentlength, next state=second wave]
  {
    \pgfpathlineto{\pgfpointorigin}
    \pgfpathmoveto{\pgfqpoint{0pt}{\pgfdecorationsegmentamplitude}}
    \pgfpathcurveto
        {\pgfpoint{-0.25*\pgfmetadecorationsegmentlength}{0.75\pgfdecorationsegmentamplitude}}
        {\pgfpoint{-0.25*\pgfmetadecorationsegmentlength}{0.25\pgfdecorationsegmentamplitude}}
        {\pgfpoint{0pt}{0pt}}
    \pgfpathcurveto
        {\pgfpoint{0.25*\pgfmetadecorationsegmentlength}{-0.25\pgfdecorationsegmentamplitude}}
        {\pgfpoint{0.25*\pgfmetadecorationsegmentlength}{-0.75\pgfdecorationsegmentamplitude}}
        {\pgfpoint{0pt}{-\pgfdecorationsegmentamplitude}}
}
\state{second wave}[width=0pt, next state=do nothing]
  {
    \pgfpathmoveto{\pgfqpoint{0pt}{\pgfdecorationsegmentamplitude}}
    \pgfpathcurveto
        {\pgfpoint{-0.25*\pgfmetadecorationsegmentlength}{0.75\pgfdecorationsegmentamplitude}}
        {\pgfpoint{-0.25*\pgfmetadecorationsegmentlength}{0.25\pgfdecorationsegmentamplitude}}
        {\pgfpoint{0pt}{0pt}}
    \pgfpathcurveto
        {\pgfpoint{0.25*\pgfmetadecorationsegmentlength}{-0.25\pgfdecorationsegmentamplitude}}
        {\pgfpoint{0.25*\pgfmetadecorationsegmentlength}{-0.75\pgfdecorationsegmentamplitude}}
        {\pgfpoint{0pt}{-\pgfdecorationsegmentamplitude}}
    \pgfpathmoveto{\pgfpointorigin}
}
  \state{do nothing}[width=\pgfdecorationsegmentlength,next state=do nothing]{
    \pgfpathlineto{\pgfpointdecoratedinputsegmentlast}
  }
  \state{final}
  {
    \pgfpathlineto{\pgfpointdecoratedpathlast}
  }
}

\begin{tikzpicture}
\draw [decoration={%
        discontinuity,
        amplitude=0.75cm},
    decorate](0,0) -- (3,2);
\draw [decoration={%
        discontinuity,
        amplitude=0.5cm,
        segment length=0.25cm,
        meta-segment length=0.5cm},
    decorate](1,-1) -- (3,-2);
\end{tikzpicture}
\end{document}

答案2

这是包含中断的一种方法。我使用了直线,但现在您知道它是如何完成的,您可以根据自己的喜好进行安排。

\documentclass{minimal}

\usepackage{tikz}
\usetikzlibrary{decorations.markings}

\tikzstyle{interrupt}=[
    postaction={
        decorate,
        decoration={markings,
                    mark= at position 0.5 
                          with
                          {
                            \fill[white] (-0.1,-0.3) rectangle (0.1,0.3);
                            \draw (-0.1,0.3) -- (-0.1,-0.3)
                                  (0.1,0.3) -- (0.1,-0.3);
                          }
                    }
                }
]

\begin{document}

\begin{tikzpicture}

\draw[interrupt] (0,0) -- (5,5);

\end{tikzpicture}

\end{document}

结果是

打断

相关内容