Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I've been toying with the idea of switching over from Xy-pic to TikZ for all of my diagramming needs, but one feature that's very important to me is the ability to create 2-categorical pasting diagrams (like the ones in Wikipedia's entry on 2-categories), as I can with Xy-pic's "twocell" commands (which, incidentally, I find to be a huge pain to deal with). How do I do these in TikZ? I'd be happy with just a reference to the relevant commands or an arXiv paper with good examples.

share|improve this question
    
It's worth pointing out that the linked page "pasting diagrams" doesn't render as intended without MathML support, so it's hard for people to see exactly what you're after here. –  Scott Morrison Jul 26 '10 at 20:28
    
Thanks Scott, I hadn't thought of that. I'll change the reference. –  Evan Jenkins Jul 26 '10 at 21:25
add comment

3 Answers

Making pasting diagrams in TikZ is pretty easy, as has been said; I think easier than in xypic for complicated ones, since it's easy to place the 2-cell arrows exactly where you want them and in exactly the right orientation. One useful trick for placing them is barycentric coordinates; then once you've got a node/coordinate at the center of the 2-cell arrow, you can use adjustments like +(0,0.2) to get to the starting and ending points.

A significant problem, however, is that as far as I know, in versions of TikZ prior to the current CVS version, there is no good way to draw a double-shafted arrow, as is used for 2-cells in pasting diagrams. In the CVS version of TikZ, you can say \draw[double,-implies], but this won't compile for anyone (such as arXiv or a journal editor) who has an older, "released" version of TikZ. For that reason, I'm personally holding off on switching from xypic to TikZ for pasting diagrams until the next version of TikZ is released and becomes at least somewhat more widely available.

share|improve this answer
    
What's the problem with the double-shafted arrows in older TikZ? Certainly, the "double" option is there. –  Andrew Stacey Aug 13 '10 at 7:19
    
The "double" option is there but with arrow tips it looks very ugly (IMHO). It works by drawing one very thick black line and then one thinner white line inside it, which produces the appearance of a double-shafted arrow. But when "->" is also given, the very thick line comes with a very thick arrow head, and nothing is done to change that, so it looks mismatched. –  Mike Shulman Sep 18 '10 at 7:13
add comment

For such a pasting diagram as on 2-categories, you could use bent arrows and midway coordinates for positioning. I recommend

  • Define styles for as many elements as possibly, so easy to use
  • Define macros for repeatedly used actions

Here's an example where I do that. Here, it's finally as easy as \connect{node1}{node2}:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows}

\newcommand{\connect}[2]{%
  \draw[-angle 60] (#1) to [above] coordinate[midway] (#1#2+) (#2) ;
  \draw[-angle 60] (#1) to [below] coordinate[midway] (#1#2-) (#2);
  \draw (#1) to coordinate[midway] (#1#2=) (#2);
  \draw[double shafted] (#1#2+) -- (#1#2=);
  \draw[double shafted] (#1#2-) -- (#1#2=);
}

\begin{document}
\begin{tikzpicture}[%
  every node/.style={circle,inner sep=2pt,fill},
  node distance=5em,
  above/.style={bend left=70,looseness=2},
  below/.style={bend right=70,looseness=2},
  double shafted/.style={-implies,double,double equal sign distance,
    shorten >=2pt, shorten <=3pt}]
  \node (a) {};
  \node[right of =  a] (b) {};
  \node[right of =  b] (c) {};
  \connect{a}{b}
  \connect{b}{c}
\end{tikzpicture}
\end{document}

pasting diagram

share|improve this answer
add comment

Would commutative diagrams work equivalently well? If so, see this and this. The TikZ matrix "environment" is a good place to look also.

share|improve this answer
    
Pasting diagrams are commutative diagrams that also have "arrows between arrows." The examples in the link I gave are probably not great ones, since these can be simulated using ordinary commutative-diagram-drawing tools. In general, I'd like to be able to put a "2-arrow" (pointing in an appropriate direction) in any open "cell" of a commutative diagram. –  Evan Jenkins Jul 26 '10 at 20:31
    
It should be relatively easy to do this with the above tools. In TikZ, you work principally with "nodes", and you can have nodes mid-arrow. So you could make arrows to arrows and stuff easily. I recommend looking at the PGF/TikZ manual for lots of good examples. –  Quadrescence Jul 26 '10 at 20:34
    
I guess what I was looking for was something that specifically covers pasting diagrams, as there is in the Xy-pic reference manual. It's not that I'm not willing to do the legwork myself; indeed, if no good reference exists, I'm of a mind to work things out and write one; rather, I'd like to know if there's already an accepted way of doing these things so I don't waste time trying to cobble together a less-than-optimal solution. That said, I'll certainly read through the sections of the manual on node placement as you suggest. –  Evan Jenkins Jul 26 '10 at 21:41
1  
Please see TikZ manual especially the Pteri diagramm example. Based on the wikipedia link, you will be able to painlessly define a couple of style and just connect the nodes you want. It takes about an hour to get the hang of nodes & connections. Once you do, it's awesome =) –  Dima Jul 26 '10 at 23:05
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.