0

If I have a path in TikZ I can easily decorate it relative to its overall extent. However can I also just add the decoration to its edges?

In my example

\documentclass[tikz]{standalone}

\usetikzlibrary{decorations.markings}

\begin{document} \begin{tikzpicture}[decoration={ markings,% switch on markings mark=% actually add a mark between positions 0 and 1 step 10mm with { \draw (0pt,-2pt) -- (0pt,2pt); } }] \draw [help lines] grid (3,2); \draw [postaction={decorate}] (0,0) -- (3,1) -- (2,2) -- (2,1) -- cycle; \end{tikzpicture} \end{document}

I only want to have the perpendicular lines at (0,0), (3,1), (2,2) and (2,1).

TobiBS
  • 5,240
  • See question: https://tex.stackexchange.com/q/79977/4778 – Alenanno Oct 12 '20 at 19:40
  • I am sorry @Alenanno but I don't see, how this relates to my question. In the answer given, two subpaths are decorated along each of them, but not ONLY at each edge given as a coordinate. What am I overlooking? – TobiBS Oct 12 '20 at 20:08
  • uhm so you don't want to change the path itself but just add perpendicular lines at the coordinates? – Alenanno Oct 12 '20 at 20:24
  • @Alenanno exactly, but preferably in an automated way. What I am trying right now is to use show path construction and then set [decoration={show path construction, moveto code={}, lineto code={ \draw [-{Bar[]}] (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast); }, curveto code={ \draw [-{Bar[]}] (\tikzinputsegmentfirst) .. controls (\tikzinputsegmentsupporta) and (\tikzinputsegmentsupportb) ..(\tikzinputsegmentlast); }, closepath code={ \draw [-{Bar[]}] (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast); } }], but not sure if this is misuse or not. – TobiBS Oct 12 '20 at 20:36
  • By the way, there is a thing: if you add lines at the coordinates, they're not going to be perpendicular, unless the line is straight. If you change the next coordinate's Y, it will be vertical maybe, but not perpendicular. Is that fine? – Alenanno Oct 13 '20 at 08:48
  • In other words, should the perpendicular line appear at the coordinate, or between two coordinates? – Alenanno Oct 13 '20 at 10:02
  • @Alenanno at the coordinates, please see my own answer and maybe improve it! – TobiBS Oct 13 '20 at 13:00

1 Answers1

0

I solved the problem myself, you can actually get perpendicular marks at the end of each segment by using the show path construction technique as a postaction:

\documentclass[tikz]{standalone}

\usetikzlibrary{arrows.meta,decorations.pathreplacing}

\tikzset{ show segments/.style={ decoration={ show path construction, moveto code={}, lineto code={ \draw [{Tee Barb[line width=1pt,inset=0pt,length=0pt,width=12]}-{Tee Barb[line width=1pt,inset=0pt,length=0pt,width=12]}] (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast); }, curveto code={ \draw [{Tee Barb[line width=1pt,inset=0pt,length=0pt,width=12]}-{Tee Barb[line width=1pt,inset=0pt,length=0pt,width=12]}] (\tikzinputsegmentfirst) .. controls (\tikzinputsegmentsupporta) and (\tikzinputsegmentsupportb) ..(\tikzinputsegmentlast); }, closepath code={ \draw [{Tee Barb[line width=1pt,inset=0pt,length=0pt,width=12]}-{Tee Barb[line width=1pt,inset=0pt,length=0pt,width=12]}] (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast); } },decorate } }

\begin{document} \begin{tikzpicture} \draw [help lines] grid (3,2); \draw [postaction=show segments] (0,0) -- (3,1) -- (2,2) -- (2,1) -- cycle; \end{tikzpicture} \end{document}

This results in:

enter image description here

TobiBS
  • 5,240