I have to write quite long chain complexes such as

0\rightarrow A \rightarrow B \rightarrow C \rightarrow etc.

with many terms in them, and I would like the arrows close to the side of the page to bend backwards and lead to a new line as you can see at page 31 of these notes (corollary 3.4.2). How do I do that?


The final version is here:

0 \rar &H^0(U \cup V) \rar & H^0(U) \oplus H^0(V) \rar
                                                  \ar[draw=none]{d}[name=X, anchor=center]{}
       & H^0(U \cap V) \ar[rounded corners,
            to path={ -- ([xshift=2ex]\tikztostart.east)
                      |- (X.center) \tikztonodes
                      -| ([xshift=-2ex]\tikztotarget.west)
                      -- (\tikztotarget)}]{dll}[at end]{\partial} \\
  {}   & H^1(U \cap V) \rar & H^1(U) \oplus H^1(V) \rar 
                  \ar[draw=none]{d}[name=Y, anchor=center]{}
       & H^1(U \cap V) \ar[rounded corners,
            to path={ -- ([xshift=2ex]\tikztostart.east)
                      |- (Y.center) \tikztonodes
                      -| ([xshift=-2ex]\tikztotarget.west)
                      -- (\tikztotarget)}]{dll}[at end]{\partial} \\
  {}  & \cdots \rar & H^i(U) \oplus H^i(V) \rar 
                                          \ar[draw=none]{d}[name=I, anchor=center]{}
      & \cdots \ar[rounded corners,
            to path={ -- ([xshift=2ex]\tikztostart.east)
                      |- (I.center) \tikztonodes
                      -| ([xshift=-2ex]\tikztotarget.west)
                      -- (\tikztotarget)}]{dll}[at end]{\partial} \\
  {} & H^n(U \cup V) \rar & H^n(U) \oplus H^n(V) \rar & H^n(U \cap V) \rar & 0



This improvement introduces a two-argument style column width={<col>}{<content>} that sets the text width of the nodes in column <col> to the width of <content>.
It’s not the best solution as the user needs to input the widest <content> of the column itself. One could surely think of either a solution that uses the .aux file to save the widest width or a to path that checks all .west and .east anchors of nodes in the same column to check which nodes are the biggest.

The to path now doesn’t need an auxiliary node that is placed manually (previously X, Y and I) but uses instead the middle between \tikztostart and \tikztotarget. The @find halway code simply defines @aux at this middle point. The code is a calc-less version of ($(\tikztostart)!.5!(\tikztotarget)$).


  commutative diagrams/column width/.style 2 args={
    /tikz/commutative diagrams/matrix of math nodes maybe/.append style={
      column #1/.append style={
        every node/.append style={
          text width=\widthof{\iftikzcd@mathmode$\fi#2\iftikzcd@mathmode$\fi}}}}},
  @find halfway/.code 2 args={%
  line break/.style={
    every node/.append style={at end},
    rounded corners, to path={ 
      [@find halfway/.expanded={\tikztostart}{\tikztotarget}]
       -- ([xshift=2ex]\tikztostart.east)
       |- (@aux) \tikztonodes
       -| ([xshift=-2ex]\tikztotarget.west)
       -- (\tikztotarget)}}}
  column width={2}{H^n(U \cup V)},
  column width={3}{H^n(U) \oplus H^n(V)},
  column width={4}{H^n(U \cap V)}
0 \rar & H^0(U \cup V) \rar
            & H^0(U) \oplus H^0(V) \rar
                  & H^0(U \cap V) \ar[line break]{dll}{\partial} \\
       & H^1(U \cap V) \rar
            & H^1(U) \oplus H^1(V) \rar
                  & H^1(U \cap V) \ar[line break]{dll}{\partial}            & \cdots \rar
            & H^i(U) \oplus H^i(V) \rar
                  & \cdots \ar[line break]{dll}{\partial} \\
       & H^n(U \cup V) \rar
            & H^n(U) \oplus H^n(V) \rar
                  & H^n(U \cap V) \rar
                       & 0


enter image description here

  • There is a way to improve this: by adding minimum size for the nodes (but that looks ugly, once when I tried). – kan Apr 24 '13 at 12:32
  • I think the rounded corners option can be used for the entire diagram since it applies to every corner that might show up. This would simplify the code slightly. – Charles Staats Apr 24 '13 at 13:13
  • Thanks kan, your solution is quite good! i just have one more question: what if I have less than 3 terms in the last row? I tried it and it messes up the last bent arrow – Alternoia Apr 24 '13 at 14:19
  • I solved by filling the voids with \rar[draw=none] & {}, surely it's not the most elegant thing but it does the job. Thank you again – Alternoia Apr 24 '13 at 14:51
  • @Alternoia I had been away for the dinner. Glad that you could sort out the problem. BTW, that is how you should salvage your case (as far as I know). – kan Apr 24 '13 at 16:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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