astoff / tikz-cd

Commutative diagrams with TikZ
46 stars 3 forks source link

allows use of tikzcd inside tikzpicture as scope #3

Open kpym opened 5 years ago

kpym commented 5 years ago

Following the idea of this answer and to make the interaction with tikz more fluent in some cases like this one, I modified the code to use tikzpicture or scope depending from where we call the tikzcd environment. I also added a style name to facilitate the access to the cells.

Here is a demonstration how it works:

\documentclass[tikz,border=7pt]{standalone}
\usetikzlibrary{cd}

\begin{document}
  \begin{tikzpicture}
    \fill[blue!14] circle(2);
    \begin{tikzcd}[name=A]
      K \arrow{r}{a} \arrow{d}{b} & B \arrow{d}{c} \\
      C \arrow{r}{d} & D
    \end{tikzcd}
    \draw[red,-latex] (A-1-1) to[bend right] (-1,-1) node[below]{Test};
  \end{tikzpicture}
\end{document}

tikzcd inside tikzpicture

astoff commented 5 years ago

To somehow allow a tikzcd inside a tikzpicture is a good feature to add. There are a few other ways to achieve this, and I'm not sure your proposal is the best option — as you said on stackexchange, it is not "in the spirit of tikz".

One thing that works (and has always worked) is to put the tikzcd environment inside a \node. Another possibility I can imagine is to define a style so that \matrix[commutative diagram]{diagram contents} produces a diagram.

kpym commented 5 years ago

The problem with including tikzcd inside a node is that this do not help with drawing on the diagram, and that including \tikzpicture inside node is not always a good idea.

But I agree that if you can produce a single style commutative diagram such that any code write inside tikzcd can be copy/pasted inside \matrix[commutative diagram] will be a good solution. In this case the tikzcd environment will simply be equivalent to \tikz\matrix[commutative diagram]{...};.

The solution that I propose has the pros :

But if you don't like it, no problem, it's just a proposal ;) In this case you can simply close this pull request.

muzimuzhi commented 2 years ago

Testing \ifx\path\tikz@command@path might be another option.