7

I want to draw a cross symbol through the arrow in the tree below. I'm looking for something similar to the image attached below.

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
   \usepackage{tikz-qtree-compat}
 \tikzset{every tree node/.style={baseline=(top.base),
level distance=2em, sibling distance=4em, align=center,
parent anchor=south, child anchor=north, anchor=north}, sibling distance=15pt}
\usetikzlibrary{positioning}



  \begin{document}

\begin{center}
\begin{tikzpicture}  [inv/.style={overlay, coordinate  }, sibling distance=10pt] 
\Tree [.XP  \node(AA){X};               [.YP [.Y   ] [.ZP Z  \node(BB){X}; ]   ]]]]
  \draw[ ->  ] (AA.south)
.. controls +(south:5em)
 and +(south:2em) .. (BB.south);
\end{tikzpicture}
  \end{center}
 \end{document}

enter image description here

1

5 Answers 5

6

Some easy solutions:

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
   \usepackage{tikz-qtree-compat}
 \tikzset{every tree node/.style={baseline=(top.base),
level distance=2em, sibling distance=4em, align=center,
parent anchor=south, child anchor=north, anchor=north}, sibling distance=15pt}
 \usetikzlibrary{positioning}
 \usetikzlibrary{decorations}



  \begin{document}

\begin{center}
\begin{tikzpicture}  [inv/.style={overlay, coordinate  }, sibling distance=10pt] 
\Tree [.XP  \node(AA){X};               [.YP [.Y   ] [.ZP Z  \node(BB){X}; ]   ]]]]
  \draw[ ->,red] (AA.south)
.. controls +(south:5em)
  and +(south:2em) .. (BB.south) node[pos=0.3,sloped]{\Large$X$};
    \draw[ -> ,blue] ([xshift=-15,yshift=-15]AA.south)
.. controls +(south:5em)
 and +(south:2em) .. ([xshift=-15,yshift=-15]BB.south) node[pos=0.3,sloped,rotate=45]{\Large$|$}node[pos=0.3,rotate=-65]{\Large$|$};
\end{tikzpicture}
  \end{center}
 \end{document}

enter image description here

PS: Shifted just to demonstrate next to each other

8

enter image description here

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
   \usepackage{tikz-qtree-compat}
 \tikzset{every tree node/.style={baseline=(top.base),
level distance=2em, sibling distance=4em, align=center,
parent anchor=south, child anchor=north, anchor=north}, sibling distance=15pt}
\usetikzlibrary{positioning}

\tikzset{pics/.cd,
    % Marque croix en diagonale
    Cross/.style args={#1 and #2}{%
        code = {%
        \draw[#2,rotate=45,scale=1.4,very thick]
                (0,#1 pt) -- (0,-#1 pt) ;
        \draw[#2,rotate=-45,scale=1.4,very thick]
                (0,#1 pt) -- (0,-#1 pt) ;
        }
    },
    Cross/.default={2.5 and gray!25!black}}


  \begin{document}

\begin{center}
\begin{tikzpicture}  [inv/.style={overlay, coordinate  }, sibling distance=10pt] 
\Tree [.XP  \node(AA){X};               [.YP [.Y   ] [.ZP Z  \node(BB){X}; ]   ]]]]
  \draw[ ->  ] (AA.south)
.. controls +(south:5em)
 and +(south:2em) .. (BB.south) pic[pos=.35,-,rotate=30] {Cross={4 and red}} ;



\end{tikzpicture}
  \end{center}
 \end{document}
8

And yet another proposal, based on this answer, mainly to say that Ignasi did this some time ago.

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
   \usepackage{tikz-qtree-compat}
   \usetikzlibrary{shapes.misc}

   \usetikzlibrary{decorations.markings}
 \tikzset{every tree node/.style={baseline=(top.base),
level distance=2em, sibling distance=4em, align=center,
parent anchor=south, child anchor=north, anchor=north}, sibling distance=15pt}
\usetikzlibrary{positioning}


% from https://tex.stackexchange.com/a/124064/121799
\tikzset{cross/.style={cross out, draw, 
         minimum size=2*(#1-\pgflinewidth), 
         inner sep=0pt, outer sep=0pt}}


  \begin{document}

\begin{center}
\begin{tikzpicture}  [inv/.style={overlay, coordinate  }, sibling distance=10pt] 
\Tree [.XP  \node(AA){X};               [.YP [.Y   ] [.ZP Z  \node(BB){X}; ]   ]]]]
  \draw[ ->] (AA.south)
.. controls +(south:5em)
 and +(south:2em) .. (BB.south) node[pos=0.4,cross=5pt,sloped]{};
\end{tikzpicture}
  \end{center}
 \end{document}

enter image description here

5

Just to achieve your goal, without a very general (nor probably too elegant) approach, you could position a node along the path and then use it to draw your cross.

To position a node along the path, use something like

\draw[ ->  ] (AA.south) .. controls +(south:5em) and +(south:2em) .. (BB.south) node[pos=0.4] (M) {};

where the pos key moves the node along the path.

Once the node is placed, you can use something like

\draw (M.20) -- (M.200) (M.110) -- (M.290);

to put the cross on the path. M.x, where x is an angle in degree, denotes an anchor around the node. Connecting 180-degrees apart anchors starting with a 90-degrees shift (x to x+180 and x+90 to x+270), you obtain a cross on the path (because the center of the node is exactly on the path).

Have a look to section 17.8 "Placing Nodes on a Line or Curve Explicitly" of the pgf manual and in general chapter 17 about nodes and edges to get inspired.

3
  • Instead of emty nodes we can always use '\coordinate'
    – koleygr
    Commented Mar 3, 2018 at 4:35
  • 1
    @koleygr I agree, but a coordinate is just a point and, in my answer, the idea was to take advantage of the node inner sep in the following \draw command to draw the cross. Commented Mar 3, 2018 at 12:18
  • you are right... for a moment forgot the "pos" parameter there and thought you could name the point by a "coordinate" command. Anyway... already upvoted
    – koleygr
    Commented Mar 3, 2018 at 12:46
5

I have used, for example, tikz-cd. It is another way to resolve the question.

enter image description here

\documentclass[a4paper,12pt]{article}
\usepackage{tikz-cd}
\usepackage{mathabx}
\usepackage{relsize, xcolor}
\begin{document}
\begin{tikzcd}
 & XP \arrow[dash,ld] \arrow[dash,rd] &  &  &  \\
X \arrow[rrrrdd, bend right=49, "\textcolor{red}{\mathlarger{\mathlarger{\mathlarger{\bigtimes}}}}" description] &  & YP \arrow[dash,ld] \arrow[dash,rd] &  &  \\
 & Y &  & ZP \arrow[dash,ld] \arrow[dash,rd] &  \\
 &  & Z &  & X
\end{tikzcd}
\end{document}

You must log in to answer this question.