9

(I guess many will view this nitpicking.) How can I replicate the soft-yet-beautiful-looking segment marks of GeoGebra.

enter image description here

\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}

enter image description here

6

You could just build your own and then have the full flexibility of controlling every aspect of its appearance.

\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}

enter image description here

enter image description here

A more customizable version thereof is

\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}

enter image description here

Explanation: With decoration.markings you switch to the tangent space at a given point, determined by the position. Thus a line in y direction will be orthogonal to the tangent at the curve at the point.

To be moved somewhere else A means to insert anything (like e.g. a diamond).

\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}

enter image description here

  • 5
    I was renewing my answer while you answered, however the answers are slightly different, I would leave them both. – CarLaTeX Mar 2 at 14:54
  • @blackened I added a version in which you can control the parameters with pgfkeys. – user121799 Mar 2 at 15:06
  • @blackened What do you mean by that? Do you want the line caps of angle arcs to be round? – user121799 Mar 8 at 15:31
  • 1
    @blackened Something like tex.stackexchange.com/a/411018/121799 ? – user121799 Mar 8 at 15:59
  • 1
    @blackened I added a version that does all that except for the arcs and the dot. (Several users want to have updates to their answers at the same time, so that is the best I can do given my other time constraints.) – user121799 Mar 8 at 16:31
7

Use decorations.markings to customize the markings as you like.

To control the distance between the two ticks, just modify the x coordinates here:

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

MWE:

\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}

enter image description here

  • @blackened Don't use tikz-euclide but decorations.markings to customize the markings as you like. See my renewed answer. – CarLaTeX Mar 2 at 14:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.