5

I have thought of asking 3 different questions, but then they are all about the same package, and about fiddling with arrows, so they are all related, so I thought I'd go with one. Here we go. My code:

\documentclass[a4paper]{report}
\usepackage{amsmath,amssymb,amsfonts,newtxmath,newtxtext,tikz-cd,graphicx}
\usetikzlibrary{decorations.markings,decorations.pathreplacing,positioning,cd}

\begin{document}
\[\begin{tikzcd}
a \ar[r,leftarrow] \ar[d,rightarrow,red] & id \ar[r,rightarrow,red] & b \ar[d,rightarrow] \\
ab \ar[d,rightarrow] & & ba \ar[d,rightarrow,red] \\
aba \ar[loop left,blue,no head] \ar[rrr,bend left=24,blue,xshift=-5.5ex,yshift=-.4ex,no head] \ar[rrr,bend right=22,blue,xshift=-5.5ex,yshift=.4ex,no head] & & bab \ar[loop right,blue,phantom,"\scalebox{.3}{\bfseries)}",xshift=-2.6ex,yshift=-.5ex] & {\color{white}a}
\end{tikzcd}\]
\[\begin{tikzcd}
G \ar[d,thick, start anchor=center, end anchor=center, xshift=-.5em, decorate,decoration={brace,amplitude=4pt,mirror},"abel"'] \ar[d,no head] \\
N \\
G' \ar[d,dashed,no head] \\
\left\langle\mathcal{C}_1\right\rangle \ar[d,no head] \\
1
\end{tikzcd}\]
\[\begin{tikzcd}
 & & 3 \ar[loop below,red,"b"] \ar[dr,green,"c"] \\
V \ar[loop,blue,"a",out=160,in=110] \ar[loop,green,"c",out=-110,in=-160] \ar[r,red,"b"] & 2 \ar[ur,blue,"a"] \ar[dr,green,"c"'] & {} & 5 \ar[r,red,"b"] & 6 \ar[loop,blue,"a",out=70,in=20] \ar[loop,green,out=-70,in=-20] \\
 & & 4 \ar[loop above,red,"b"] \ar[ur,blue,"a"]
\end{tikzcd}\]
\end{document}

Result:

enter image description here

Problems:

  1. What I want is to circle the two entries on the bottommost row; for the moment, I have a loop left, two no-head arrows pointing one cell too far (well, I would point them rr but I changed them to rrr to get them as they are), and a micro-parenthesis which is almost invisible; is there a way to get any kind of shape (possibly not a rectangle, I'd prefer something more curved, an oval, or a blob, but a rectangle will do if something curved is not feasible) to surround those entries?
  2. "abel" (standing for "abelian", meaning the quotient of the two entries is abelian) is too close to the brace, and the brace has that extra little stroke; how do I remove the stroke and move "abel" further left?
  3. Those loops are too squashed; I specified in and out angles correctly, but I want to take those arrows and "stretch" them in the direction orthogonal to them; more precisely, right now to obtain them one would have to take a loop above or loop below as the ones in the middle of the diagram, squash them vertically until they have almost zero height, then rotate them; how can I get those loops to look like what I described but without the squashing?

Edit: Here is something close to what I want for 3, in particular the loops for V should be more slanted than this, like mirroring those for 6:

enter image description here

Update:

Problems 2 and 3 are fixed, as my answer states. Problem 1 has a touch of bizarre to it. I copy-pasted both answers' solutions into a file and compiled it, and they worked. Then I copy-pasted the solutions for diagram 1 into my old MWE. Here is what happened to LaRiFaRi's fix:

enter image description here

And here is Gonzalo's:

enter image description here

Gonzalo's actually has extra strangeness, in that on the first compilation it was identical to LaRiFaRi's, then I moved it vertically and the ellipse moved erratically, then I compiled it a few times and I saw it again like LaRiFaRi's, then I compiled it once more and the ellipse was gone, as you see above. So what is going on? And what are the [alias…] for?

Update 2: I thought I had irremediably lost the possibility to retrieve those compilations' effects, but then I remembered I take a lot of screenshots when fiddling with LaTeX, so here are a few:

enter image description here

enter image description here

enter image description here

enter image description here

I tried a couple of fiddles, but to no avail:

enter image description here

enter image description here

Notice how Gonzalo's solution fixed the ellipse's placement as I fiddled with LaRiFaRi's.

Update 3: More bizarreness. Here is the code:

\documentclass[a4paper]{report}
\usepackage{amsmath,amssymb,amsfonts,newtxmath,newtxtext,tikz-cd,graphicx}
\usetikzlibrary{decorations.markings,decorations.pathreplacing,positioning,cd,fit,shapes.geometric}
\DeclareMathOperator{\id}{id}

\begin{document}

Gonzalo docet:
\[
\begin{tikzcd}[remember picture,overlay]
  a 
  \ar[r,leftarrow] 
  \ar[d,rightarrow,red] 
& 
  id 
  \ar[r,rightarrow,red] 
& 
  b 
  \ar[d,rightarrow] 
\\
  ab 
  \ar[d,rightarrow] 
& 
& 
  ba 
  \ar[d,rightarrow,red] 
\\
  aba  
  & 
  & 
  bab
\end{tikzcd}
\tikz[remember picture,overlay]{
\node[ellipse,inner xsep=0pt,draw,blue,fit={(tikz@f@1-3-1) (tikz@f@1-3-3)}]   {};
}
\]

\vspace{2cm}

\[
\begin{tikzcd}
  G 
  \ar[d,thick, start anchor=center, end anchor=center,no head, xshift=-.5em,decorate,decoration={brace,amplitude=4pt,mirror},"\text{\normalsize abel}" left=5pt] 
  \ar[d,no head] 
\\
  N 
\\
  G' 
  \ar[d,dashed,no head] 
\\
  \left\langle\mathcal{C}_1\right\rangle 
  \ar[d,no head] 
\\
  1
\end{tikzcd}
\]

\[
\begin{tikzcd}
& 
& 
  3 
  \ar[loop below,red,"b"] \ar[dr,green,"c"] 
\\
  V 
  \ar[loop above,blue,"a",out=155,in=105,looseness=7] 
  \ar[loop below,green,"c",out=-105,in=-155,looseness=7] 
  \ar[r,red,"b"] 
& 
  2 
  \ar[ur,blue,"a"] 
  \ar[dr,green,"c"'] 
& 
  {} 
& 
  5 
  \ar[r,red,"b"] 
& 
  6 
  \ar[loop,blue,"a",out=75,in=25,looseness=7] 
  \ar[loop,green,out=-25,in=-75,looseness=7] 
\\
& 
& 
  4 
  \ar[loop above,red,"b"] 
  \ar[ur,blue,"a"]
\end{tikzcd}
\]

LaRiFaRi docet:
\[\begin{tikzcd}[execute at end picture={\node[ellipse,draw,blue,fit={(tikz@f@1-3-1) (tikz@f@1-3-3)}]{};}]
a \arrow[red]{d} & \id \arrow{l}\arrow[red]{r} & b \arrow{d} \\
ab \arrow{d} & & ba \arrow[red]{d} \\
|[alias=X]|aba  & & |[alias=Y]|bab
\end{tikzcd}\]

\[\begin{tikzcd}[every arrow/.append style=dash]
G \ar[thick, start anchor=center, end anchor=center, xshift=-.5em, decorate,decoration={brace,amplitude=4pt,mirror}]{d}[left= 4pt]{\text{abel}} \arrow{d} \\
N \\
G' \ar[d,dashed] \\
\left\langle\mathcal{C}_1\right\rangle \arrow{d} \\
1
\end{tikzcd}\]

\[\begin{tikzcd}
 & & 3 \ar[loop below,red,"b"] \ar[dr,green,"c"] \\
V \ar[loop,distance=20pt,blue,"a",out=160,in=110] \ar[loop,distance=20pt,green,"c",out=-110,in=-160] \ar[r,red,"b"] & 2 \ar[ur,blue,"a"] \ar[dr,green,"c"'] & {} & 5 \ar[r,red,"b"] & 6 \ar[loop,distance=20pt,blue,"a",out=70,in=20] \ar[loop,distance=20pt,green,out=-70,in=-20] \\
 & & 4 \ar[loop above,red,"b"] \ar[ur,blue,"a"]
\end{tikzcd}\]


\end{document}

First few runs it compiled identically to:

enter image description here

enter image description here

enter image description here

After fiddling with the screenshots from the other update (n. 2), I test it again and:

enter image description here

enter image description here

And I'm like WTF??

5
  • Oh, and the loop for 4 should not be below but above, as in the code I gave.
    – MickG
    Jul 22, 2015 at 21:37
  • 1
    alias gives an alias to the node. In this case it allows you to use fit={(X)(Y)} instead of fit={(tikz@f@1-3-1) (tikz@f@1-3-3)}. Jul 23, 2015 at 13:21
  • 1
    I suspect the problem in your Update 3 code is related to that Gonzalo's code has remember picture, overlay, which allows you to refer to node names outside the tikzpicture where they were defined. This is how Gonzalo drew the ellipse. If you for example remove Gonzalo's code from that example, LaRiFaRi's work fine. If you use fit={(X)(Y)} in LaRiFaRi's code, as I mentioned in my previous comment, both work fine. Jul 23, 2015 at 13:29
  • Indeed. That fixes LaRiFaRi's solution. But Gonzalo's solution also shows erraticness in the ellipse, in Update 1-2. And if I try saying |[alias=A] in Gonzalo's solution, The result is Use of \tikz@fig@scan@at doesn't match its definition. How do I get aliases in Gonzalo's solution? In other words, why is that error coming up and how can I fix it? @TorbjørnT.
    – MickG
    Jul 23, 2015 at 13:40
  • 1
    You need a closing | as well. Jul 23, 2015 at 13:42

3 Answers 3

4

Gonzalo was quicker. Here a slightly different version which does not need to be compiled twice:

% arara: pdflatex

\documentclass[a4paper]{report}
\usepackage{newtxmath,tikz-cd}
\usetikzlibrary{decorations.pathreplacing,fit,shapes.geometric}
\usepackage{mathtools}
\DeclareMathOperator{\id}{id}

\begin{document}
\[\begin{tikzcd}[execute at end picture={\node[ellipse,draw,blue,fit={(tikz@f@1-3-1) (tikz@f@1-3-3)}]{};}]
a \arrow[red]{d} & \id \arrow{l} \arrow[red]{r} & b \arrow{d} \\
ab \arrow{d}     &                              & ba \arrow[red]{d} \\
aba              &                              & bab
\end{tikzcd}\]

\[\begin{tikzcd}[every arrow/.append style=dash]
G 
\arrow[%
    ,thick
    ,start anchor=center
    ,end anchor=center
    ,xshift=-.5em
    ,decorate
    ,decoration={%
        ,brace
        ,amplitude=4pt
        ,mirror
        }
    ]{d}[left=4pt]{\text{abel}} \arrow{d} \\
N \\[-3ex]
G' \arrow[d,dashed] \\
\langle\mathcal{C}_1\rangle \arrow{d} \\
1
\end{tikzcd}\]

\[\begin{tikzcd}
& & 3 \arrow[loop below,red,"b"] \arrow[dr,green,"c"] \\
V 
\arrow[loop,distance=16pt,blue,"a",out=150,in=120] \arrow[loop,distance=16pt,green,"c",out=-120,in=-150] \arrow[r,red,"b"] & 2 \arrow[ur,blue,"a"] \arrow[dr,green,"c"] & & 5 \arrow[r,red,"b"] & 6 \arrow[loop,distance=16pt,blue,"a",out=60,in=30] \arrow[loop,distance=16pt,green,out=-60,in=-30,swap,"c"] \\
& & 4 \arrow[loop above,red,"b"] \arrow[ur,blue,"a"]
\end{tikzcd}\]
\end{document}

enter image description here


The stroke in the second diagram was an arrow head. Just add the dash option to that arrow, as I did above.

2
  • Please see the edit.
    – MickG
    Jul 23, 2015 at 13:16
  • No matter, problem solved.
    – MickG
    Jul 23, 2015 at 13:49
7
  1. You can use the fit library to fit an elliptical node around those elements; I used the remember picture, overlay options so the fitting node can be drawn outside the tikzcd environment. The code needs two or three runs for the ellipse to land in its final place.

  2. You can use something like left=<length> to move the label. I also used \text from amsmath to write it in text mode.

  3. You can use the looseness key.

enter image description here

The code:

\documentclass[a4paper]{report}
\usepackage{amsmath,amssymb,amsfonts,newtxmath,newtxtext,tikz-cd,graphicx}
\usetikzlibrary{decorations.markings,decorations.pathreplacing,positioning,cd,fit,shapes.geometric}

\begin{document}

\[
\begin{tikzcd}[remember picture,overlay]
  a 
  \ar[r,leftarrow] 
  \ar[d,rightarrow,red] 
& 
  id 
  \ar[r,rightarrow,red] 
& 
  b 
  \ar[d,rightarrow] 
\\
  ab 
  \ar[d,rightarrow] 
& 
& 
  ba 
  \ar[d,rightarrow,red] 
\\
  aba  
  & 
  & 
  bab
\end{tikzcd}
\tikz[remember picture,overlay]{
\node[ellipse,inner xsep=0pt,draw,blue,fit={(tikz@f@1-3-1) (tikz@f@1-3-3)}]   {};
}
\]

\vspace{2cm}

\[
\begin{tikzcd}
  G 
  \ar[d,thick, start anchor=center, end anchor=center,no head, xshift=-.5em,decorate,decoration={brace,amplitude=4pt,mirror},"\text{\normalsize abel}" left=5pt] 
  \ar[d,no head] 
\\
  N 
\\
  G' 
  \ar[d,dashed,no head] 
\\
  \left\langle\mathcal{C}_1\right\rangle 
  \ar[d,no head] 
\\
  1
\end{tikzcd}
\]

\[
\begin{tikzcd}
& 
& 
  3 
  \ar[loop below,red,"b"] \ar[dr,green,"c"] 
\\
  V 
  \ar[loop above,blue,"a",out=155,in=105,looseness=7] 
  \ar[loop below,green,"c",out=-105,in=-155,looseness=7] 
  \ar[r,red,"b"] 
& 
  2 
  \ar[ur,blue,"a"] 
  \ar[dr,green,"c"'] 
& 
  {} 
& 
  5 
  \ar[r,red,"b"] 
& 
  6 
  \ar[loop,blue,"a",out=75,in=25,looseness=7] 
  \ar[loop,green,out=-25,in=-75,looseness=7] 
\\
& 
& 
  4 
  \ar[loop above,red,"b"] 
  \ar[ur,blue,"a"]
\end{tikzcd}
\]

\end{document}
11
  • Problem 3 is that the loops on V and 6 should not be up and down but slanted. I tried specifying in and out angles, and the result was terrible. How do I get them slanted without the losing their "height"?
    – MickG
    Jul 22, 2015 at 21:31
  • @MickG Ah, I see. Give me some seconds. Jul 22, 2015 at 21:35
  • @MickG Answer updated, Is it something like that what you need? Jul 22, 2015 at 21:37
  • Absolutely. If you could make the distance between tip and tail of the loop arrows smaller it would be even better.
    – MickG
    Jul 22, 2015 at 21:38
  • I guess that simply amounts to fiddling with the in and out angles, right?
    – MickG
    Jul 22, 2015 at 21:39
0

Posting a sum-up of the two answers to isolate the "tricks" that fixed the diagrams.

  1. On hold as I encountered an additional problem, will update the question;
  2. The extra bit of brace is actually the arrow head, which no head fixes; the positioning of the text is fixed by removing the comma before left=, which somehow caused that option to be ignored; I don't really see why I should say \text{\normalsize abel} instead of just abel; probably to avoid unneeded math mode; \normalsize seems to do pretty much nothing;
  3. The trick with loops is the looseness=, or equivalently distance=, which if modified squashes or enlarges the loop.

Edit: As LaRiFaRi points out in his answer, another fix to the extra stroke in 2 is [every arrow/.append style=dash] as optional argument to \begin{tikzcd}.

Update: 1 is solved. The additional problem is TikZ selecting the wrong tikz@f@1-3-1 or the likes. Using aliases to refer to those points fixes (or seems to fix) all the erratic behaviours of the ellipses, in both solutions. Accepting LaRiFaRi's version because it is tikz-cd-contained and doesn't require to do part of the diagram outside the diagram, but they are pretty much equivalent. Syntax for aliases: enclose the name of the alias between |[alias= (vertical bar, bracket, alias=) and ]|, and don't forget the final closing vertical bar. Upvoting Gonzalo's work and accepting LaRiFaRi's.

You must log in to answer this question.

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