3

I have been trying to draw an arrow like the image below.

enter image description here

The code I generated is given below.

\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage[compat=1.0.0]{tikz-feynman}
\title{}
\author{ }
\date{}
\begin{document}

\maketitle

\begin{center}
\begin{tikzpicture}[scale=1]
\draw[] (0,0) -- (0,1.5) -- (-0.2, 1.5) -- (0.25,2.5) -- (0.7,1.5) -- (0.5,1.5) -- 
(0.5,0) -- (0,0) ;
\filldraw [gray] (0.25,0.5) circle (0.4cm);
\end{tikzpicture}    
\end{center}
\end{document}

I could not find a way to make the circle invisible inside the arrow. Can anyone help to resolve this?

1
  • 1
    Draw the circle first. Then fill and draw the arrow.
    – cfr
    Dec 8, 2023 at 2:39

2 Answers 2

4

Just draw things from back to front, since you want to fill the arrow anyway.

\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[thick]
  \draw [black, line width=3mm] (-0.75,0.5) -- (1.25,0.5);
  \filldraw [gray,draw=black] (0.25,0.5) circle (0.4cm);
  \draw [draw=red!80!gray, top color=red!35, bottom color=red] (0,0) -- (0,1.5) -- (-0.2, 1.5) -- (0.25,2.5) -- (0.7,1.5) -- (0.5,1.5) -- 
  (0.5,0) -- cycle ;
\end{tikzpicture}    
\end{document}

Note that you may find it easier if you put the centre of the circle at (0,0) as it makes it straightforward to ensure symmetry.

arrow on circle on line

4

You could use layers as described in the "Layered graphics" section of the pgf manual. The idea is to first declare some layers (with the \pgfdeclarelayer macro) and then order them (with the \pgfsetlayers). The main layer is declared when loading the tikz/pgf package. It is the default layer. To use a declared layer, just put your code inside a pgfonlayer environment.

(Code adapted from @cfr nice answer)

\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
% Ordered layers (bottom to top)
\pgfsetlayers{background, main, foreground}
\begin{document}
\begin{tikzpicture}[thick]
  \draw[draw = red!80!gray, top color = red!35, bottom color = red] (0, 0) -- (0, 1.5) -- (-0.2, 1.5) -- (0.25, 2.5) -- (0.7, 1.5) -- (0.5, 1.5) -- (0.5, 0) -- cycle;
  \begin{pgfonlayer}{background}
    \draw[black, line width = 3mm] (-0.75, 0.5) -- (1.25, 0.5);
    \filldraw[gray, draw = black] (0.25, 0.5) circle (0.4cm);
  \end{pgfonlayer}
\end{tikzpicture}
\end{document}
1
  • 1
    The main advantage of layers is that you can position background objects relative to foreground objects (defined earlier). Dec 8, 2023 at 15:59

You must log in to answer this question.

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