3

How can I add labels to the corners and arrows of the following diagram?

\documentclass{article}
\usepackage{tikz-cd}
\usetikzlibrary{decorations.markings,arrows.meta}
\usetikzlibrary{backgrounds}

\begin{document}

\begin{tikzpicture}
\end{tikzpicture}

\begin{tikzcd}[
sep=2cm,
cells={shape=coordinate},
]
  \ar[draw=none,r, "{\tikz\node[rotate=90,inner sep=0pt] {\tikz\draw[->](0,0) ;};  }" description]
  \ar[dash,r] 
& 
{} 
\\
  \ar[draw=none,r, "{\tikz\node[rotate=270,inner sep=0pt] {\tikz\draw[->](0,0) ;};  }" description] 
  \ar[draw=none,u, "{\tikz\node[inner sep=0pt] {\tikz\draw[->>](0,0) ;};  }" description] 
  \ar[draw=none,ur, "{\tikz\node[rotate=-45,inner sep=0pt] {\tikz\draw[->>>](0,0) ;};  }" description] 
  \ar[dash,r] 
  \ar[dash,u] 
  \ar[dash,ur] 
& 
{}
  \ar[draw=none,u, "{\tikz\node[inner sep=0pt] {\tikz\draw[->>](0,0) ;};  }" description]
    \ar[dash,u]  
\end{tikzcd}
\end{document}

resulting diagram

The diagram stems from the question How to draw a Klein Bottle

mathology
  • 131

1 Answers1

2

Your code unfortunately nests tikzpictures, which can lead to uncontrollable results. However, you are already loading decorations.markings, and using it allows you to avoid the nesting. I add two ways to answer your question, one with tikz-cd and another one with plain TikZ. For your convenience, I define styles ->-, ->>- and ->>>- for the single, double and triple arrows. (EDIT: For your convenience I added the reversed arrow styles.)

\documentclass{article}
\usepackage{tikz-cd}
\usetikzlibrary{decorations.markings}
\tikzset{> at/.style={postaction={decorate,decoration={markings,mark=at position
#1 with {\arrow{>};}}}},
->-/.style={> at=0.5},
->>-/.style={>
at/.list={0.5*\pgfdecoratedpathlength-1.5pt,0.5*\pgfdecoratedpathlength+1.5pt}},
->>>-/.style={>
at/.list={0.5*\pgfdecoratedpathlength-3pt,0.5,0.5*\pgfdecoratedpathlength+3pt}},
< at/.style={postaction={decorate,decoration={markings,mark=at position
#1 with {\arrowreversed{>};}}}},
-<-/.style={< at=0.5},
-<<-/.style={<
at/.list={0.5*\pgfdecoratedpathlength-1.5pt,0.5*\pgfdecoratedpathlength+1.5pt}},
-<<<-/.style={<
at/.list={0.5*\pgfdecoratedpathlength-3pt,0.5,0.5*\pgfdecoratedpathlength+3pt}}}
\begin{document}

\begin{tikzcd}[sep=2cm,cells={nodes={text height=1em,minimum width=0.8em}}]
a
& 
b\ar[dash,l,-<-,start anchor=south west,end anchor=south east,"\ell_1"']
\\
c \ar[dash,u,->>-,start anchor=north east,end anchor=south east,"\ell_2"]
\ar[dash,r,->-,start anchor=north east,end anchor=north west,"\ell_3"']
\ar[dash,ur,->>>-,start anchor=north east,end anchor=south west,"\ell_4"]
& 
d \ar[dash,u,->>-,start anchor=north west,end anchor=south west,"\ell_5"]
\end{tikzcd}

\begin{tikzpicture}
 \path (0,0) coordinate[label=above left:$a$] (a)
  (2,0) coordinate[label=above right:{$b$}](b) 
  (0,-2) coordinate[label=below left:$c$] (c)
  (2,-2) coordinate[label=below right:$d$] (d)
  (b) edge[->-,"$\ell_1$"'] (a)
  (c) edge[->>-,"$\ell_2$"] (a)
  (d) edge[->>-,"$\ell_5$"'] (b)
  (c) edge[->>-,"$\ell_3$"'] (d)
  (c) edge[->>>-,"$\ell_4$"] (b);
\end{tikzpicture}
\end{document}

enter image description here

  • Thank you! How can I also label the arrows? – mathology Oct 29 '19 at 17:34
  • @PhilippWeder I added labels (didn't read carefully, sorry!). –  Oct 29 '19 at 17:44
  • thank you! If I want to change the direction of one arrow, why can't I just change start and end point? – mathology Oct 29 '19 at 18:57
  • @PhilippWeder You can. What do you mean? What have you tried? –  Oct 29 '19 at 19:08
  • I tried the following

    b \ar[dash,u,->>-,start anchor=south east,end anchor=north east,"\ell_2"]

    instead of

    b \ar[dash,u,->>-,start anchor=north east,end anchor=south east,"\ell_2"]

    – mathology Oct 29 '19 at 20:00
  • @mathology In tikz-cd, an arrow always starts at the cell you are issuing the \ar command. So if you want to convert the arrow going from b to a into an arrow going from a to b, you need to replace a & b\ar[dash,l,->-,start anchor=south west,end anchor=south east,"\ell_1"'] by a \ar[dash,r,->-,start anchor=south east,end anchor=south west,"\ell_1"] & b. Alternatively, you could define decorations like -<- and so on in which you reverse the arrow in the decoration by replacing \arrow{>}; with \arrowreversed{>};. –  Oct 29 '19 at 20:24
  • thank you for your quick answer – mathology Oct 29 '19 at 20:32