带圆头的分段标记

带圆头的分段标记

(我猜很多人会认为这是吹毛求疵。)我怎样才能复制 GeoGebra 柔和而又美观的线段标记。

在此处输入图片描述

\documentclass[tikz,border=10pt]{standalone}
\usepackage{tkz-euclide}
\usetkzobj{all}
\begin{document}
\begin{tikzpicture}
    \coordinate (A) at (0,0);
    \coordinate (B) at (2,4);
    \coordinate (C) at (4,0);

    \draw(A)--(B)--(C)--cycle;
    \tkzMarkSegment[pos=0.5,mark=||](A,B)
    \tkzMarkSegment[pos=0.5,mark=||](B,C)
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案1

您可以构建自己的外观,然后完全灵活地控制其外观的各个方面。

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}[|| mark/.style={postaction=decorate,decoration={markings,
mark=at position #1 with {\draw[line cap=round,mark segment] (-1pt,-2pt) -- (-1pt,2pt);
\draw[line cap=round,mark segment] (1pt,-2pt) -- (1pt,2pt);
}}},mark segment/.style={thick}]
    \coordinate (A) at (0,0);
    \coordinate (B) at (2,4);
    \coordinate (C) at (4,0);

    \draw(A)--(B)--(C)--cycle;
    \path[|| mark=0.5] (A) -- (B);
    \path[|| mark=0.5] (B) -- (C);
\end{tikzpicture}
\end{document}

在此处输入图片描述

在此处输入图片描述

一个更加可定制的版本是

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{decorations.markings,angles}
\begin{document}
\tikzset{insert |/.style={decoration={markings,
  mark=at position #1 with {%
   \draw[line cap=round,mark segment] 
    (0,-\pgfkeysvalueof{/tikz/mark
    segment length}/2) -- (0,\pgfkeysvalueof{/tikz/mark
    segment length}/2);}
  }},
  | mark/.style={postaction=decorate,insert |=#1},
  insert ||/.style={decoration={markings,
  mark=at position #1 with {%
   \draw[line cap=round,mark segment] 
    (-\pgfkeysvalueof{/tikz/mark segment distance}/2,-\pgfkeysvalueof{/tikz/mark
    segment length}/2) -- (-\pgfkeysvalueof{/tikz/mark segment distance}/2,\pgfkeysvalueof{/tikz/mark
    segment length}/2);
   \draw[line cap=round,mark segment] (\pgfkeysvalueof{/tikz/mark segment distance}/2,-\pgfkeysvalueof{/tikz/mark
    segment length}/2) -- (\pgfkeysvalueof{/tikz/mark segment distance}/2,\pgfkeysvalueof{/tikz/mark
    segment length}/2);}
  }},
  || mark/.style={postaction=decorate,insert ||=#1},
 insert |||/.style={decoration={markings,
  mark=at position #1 with {%
   \draw[line cap=round,mark segment] 
    (-\pgfkeysvalueof{/tikz/mark segment distance},-\pgfkeysvalueof{/tikz/mark
    segment length}/2) -- (-\pgfkeysvalueof{/tikz/mark segment distance},\pgfkeysvalueof{/tikz/mark
    segment length}/2);
   \draw[line cap=round,mark segment] 
    (0,-\pgfkeysvalueof{/tikz/mark
    segment length}/2) -- (0,\pgfkeysvalueof{/tikz/mark
    segment length}/2); 
   \draw[line cap=round,mark segment] 
   (\pgfkeysvalueof{/tikz/mark segment distance},-\pgfkeysvalueof{/tikz/mark
    segment length}/2) -- (\pgfkeysvalueof{/tikz/mark segment distance},\pgfkeysvalueof{/tikz/mark
    segment length}/2);}
  }},
  ||| mark/.style={postaction=decorate,insert |||=#1},
 mark segment/.style={thick},
 mark segment options/.code=\tikzset{mark segment/.style={#1}},
 mark segment distance/.initial=2pt,
 mark segment length/.initial=4pt,
 angle deco |/.style={insert |=0.5,
      pic actions/.append code=\tikzset{postaction=decorate}},
 angle deco ||/.style={insert ||=0.5,
      pic actions/.append code=\tikzset{postaction=decorate}},
 angle deco |||/.style={insert |||=0.5,
      pic actions/.append code=\tikzset{postaction=decorate}}}
\begin{tikzpicture}[]
    \coordinate (A) at (0,0);
    \coordinate (B) at (2,4);
    \coordinate (C) at (4,0);

    \draw(A)--(B)--(C)--cycle;
    \path[| mark=0.5] (A) -- (B);
    \path[mark segment options={thick,yscale=2},|| mark=0.5] (B) -- (C);
    \path[mark segment options={blue,line width=1pt,scale=2},||| mark=0.5] (C) -- (A);
    \pic [draw,angle radius=1cm,angle deco ||] {angle = A--B--C};
\end{tikzpicture}
\end{document}

在此处输入图片描述

解释:decoration.markings切换到给定点的切线空间,由位置决定。因此,y 方向的线将与该点处的曲线切线正交。

被转移到其他地方插入任何东西(例如钻石)的方法。

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{decorations.markings,angles,shapes.geometric,calc}
\begin{document}
\tikzset{insert any/.style={decoration={markings,
  mark=at position #1 with {%
   \path (0,0) node[any mark]{};}
  }},
  diamond mark/.style={postaction=decorate,any mark options=common diamond,insert any=#1},
  insert two/.style={decoration={markings,
  mark=at position #1 with {%
   \path (-\pgfkeysvalueof{/tikz/mark any distance}/2,0) node[any mark]{}
   (\pgfkeysvalueof{/tikz/mark any distance}/2,0) node[any mark]{};}
  }},
  two diamonds mark/.style={postaction=decorate,any mark options=common diamond,,insert two=#1},
 insert three/.style={decoration={markings,
  mark=at position #1 with {%
   \path (-\pgfkeysvalueof{/tikz/mark any distance},0) node[any mark]{}
   (0,0) node[any mark]{}
   (\pgfkeysvalueof{/tikz/mark any distance},0) node[any mark]{};}
  }},
  three diamonds mark/.style={postaction=decorate,any mark options=common diamond,insert three=#1},
 any mark/.style={transform shape},
 any mark options/.code=\tikzset{any mark/.append style={#1}},
  common diamond/.style={shape=diamond,inner  xsep=0.2ex,aspect=0.3,fill},
 mark any distance/.initial=0.6em,}
\begin{tikzpicture}[]
    \coordinate (A) at (0,0);
    \coordinate (B) at (2,4);
    \coordinate (C) at (4,0);

    \draw(A)--(B)--(C)--cycle;
    \path[diamond mark=0.5] (A) -- (B);
    \path[any mark options={aspect=0.5},two diamonds mark=0.5] (B) -- (C);
    \path[any mark options={blue,draw,fill=white},three diamonds mark=0.5] (C) -- (A);
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

用于decorations.markings按照您的喜好定制标记。

要控制两个刻度之间的距离,只需修改此处的 x 坐标:

\draw[line cap=round, thick] (-2pt,-2pt) -- (-2pt,2pt);
\draw[line cap=round, thick] (2pt,-2pt) -- (2pt,2pt);

梅威瑟:

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}[decoration={
markings,
mark=at position .5 with
{
\draw[line cap=round, thick] (-2pt,-2pt) -- (-2pt,2pt);
\draw[line cap=round, thick] (2pt,-2pt) -- (2pt,2pt);
}
}
]
    \coordinate (A) at (0,0);
    \coordinate (B) at (2,4);
    \coordinate (C) at (4,0);

    \draw(A)--(B)--(C)--cycle;
    \path[postaction={decorate}] (A) -- (B);
    \path[postaction={decorate}] (B) -- (C);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容