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 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?

share|improve this question
    
I'd suggest tikz-cd. I will write an answer for you grabbing an example from the manual... –  kan Apr 24 '13 at 11:11
2  
add comment

1 Answer

up vote 6 down vote accepted

The final version is here:

\documentclass{amsart}
\usepackage{tikz-cd}
\begin{document}
\begin{tikzcd}
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
\end{tikzcd}
\end{document}

meyer-viet.png

Improvements

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)$).

Code

\documentclass[tikz]{standalone}
\usepackage{tikz-cd}
\makeatletter
\tikzset{
  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={
          align=center,
          text width=\widthof{\iftikzcd@mathmode$\fi#2\iftikzcd@mathmode$\fi}}}}},
  @find halfway/.code 2 args={%
    \begingroup
      \pgftransformshift{\pgfpointlineattime{.5}{\pgfpointanchor{#1}{center}}{\pgfpointanchor{#2}{center}}}%
      \pgfnode{coordinate}{center}{}{@aux}{}%
    \endgroup},
  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)}}}
\makeatother
\begin{document}
\begin{tikzcd}[
  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
\end{tikzcd}
\end{document}

Output

enter image description here

share|improve this answer
    
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
show 1 more 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.