1

From this code is from an answer to my previous post. The arrow is nice but if I want to move the arrow to the end of the path by setting mark = at position 1 there is still a protrude part which doesn't look nice.

Is there any idea to remove this part?

enter image description here

\documentclass[tikz, border=1cm]{standalone} 
\usepackage[american, siunitx, RPvoltages]{circuitikz} 
\usetikzlibrary{decorations.markings, arrows.meta} 
\usetikzlibrary{backgrounds}

\begin{document}

\begin{tikzpicture}
\ctikzset{inductors/scale=0.5, capacitors/scale=0.5, sources/scale=0.5, switches/scale=0.5}
\draw  (0,0) coordinate (start)  node[ocirc]{} to [cute open switch]
++(1,0)  to [cute inductor, l^=$L$] ++(1,0) to [short]++(0.5,0) node[ocirc]{} coordinate (end);
\begin{scope}[on background layer, decoration={
markings, mark=at position 1 with {\arrow{Stealth[scale=0.8]}}} ]  
\draw[ultra thick, red!40, postaction={decorate}, transform canvas={yshift=3pt}] (start) --(end);
\end{scope}
\end{tikzpicture}
\end{document}
4
  • Do you need a decoration for that? Just do -{Stealth[scale=0.8]} at that path and PGF/TikZ will handle the tip correctly. Commented Dec 14, 2022 at 15:18
  • @Qrrbrbirlbel sorry where should I add that in the code?
    – internet
    Commented Dec 14, 2022 at 15:22
  • \begin{scope}[on background layer]\draw[ultra thick, red!40, -{Stealth[scale=0.8]}, transform canvas={yshift=3pt}] (start) -- (end);\end{scope}. No need for the decoration if you want to just use an arrow tip at the end of a line, that's the original usecase. The markings decoration is only needed if you need an arrow tip somewhere else. Commented Dec 14, 2022 at 15:35
  • @Qrrbrbirlbel that is nice. It would be best if you put that as an answer so we can refer it later (although it would be great if decoration works as well).
    – internet
    Commented Dec 14, 2022 at 15:41

1 Answer 1

2

Normal arrow:

\draw[-{Stealth[scale=0.8]}, ultra thick, red!40, transform canvas={yshift=3pt}] (start) -- (end);

If you for some reason need to do it with a decoration, you need to manually shorten the line like this:

\draw[ultra thick, red!40, postaction={decorate}, transform canvas={yshift=3pt}, shorten >=2pt] (start) --(end);

Circuit with red arrow behind

2
  • It's nice to know shorten.
    – internet
    Commented Dec 14, 2022 at 17:40
  • 1
    Notice that the option is not shorten but shorten > (or shorten < for the other end). Commented Dec 14, 2022 at 17:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .