Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allows use of tikzcd inside tikzpicture as scope #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kpym
Copy link

@kpym kpym commented Apr 3, 2019

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
Copy link
Owner

astoff commented Apr 12, 2019

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
Copy link
Author

kpym commented Apr 12, 2019

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 :

  • really simple code modification;
  • it is 100% backward compatible because if outside tikzpicture the code stays the same;
  • the learning curve is smooth, because nothing new to learn : the old tikzcd works inside and outside.

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants