4

In order to create nice alignments in a tikzcd-like environment (zx-calculus package), I'd like to find a simple way to change the bounding box of a node (without changing its content itself ideally, but in practice it will have opacity 0 anyway, and I may also be interested in scopes), notably to have zero-height or zero-width similar to how vphantom or hphantom can work. Is it possible to create a simple style that would apply this?

MWE:

enter image description here

\documentclass[]{article} \usepackage{tikz-cd} \NewExpandableDocumentCommand{\mynode}{O{}m}{\node[circle, inner sep=10pt,draw,fill=red,#1]{#2};} \begin{document} I'd like the bounding box of the semi-transparent Foo circle to have zero width (so its content will overlap with B and go outside of the fbox to the right, in practice it is not much of an issue as opacity will often be 0) but its actual height should be unchanged: \fbox{\begin{tikzcd}[ampersand replacement=\&,column sep=3mm] A \& \mynode{Foo} \\ \& B \& \mynode[opacity=.1]{Foo} \end{tikzcd}} \end{document} 
3
  • Unrelated, but \NewExpandableDocumentCommand is out of place: it should be \NewDocumentCommand, because the replacement text is not fully expandable. Commented Jan 6 at 11:02
  • @egreg for some reasons, if I put \NewDocumentCommand this wont compile, I think that tikzcd is testing if \node is the next text and if not it does something different… and using expandable fixes this. If you have a cleaner solution that lets me use xparse syntax I'd be happy to hear it though. Commented Jan 6 at 12:19
  • 1
    samcarter has shown what to do: a style is the answer. Commented Jan 6 at 12:54

1 Answer 1

4

You could

  • use the overlay option to prevent the semi-transparent node from influencing the bounding box (or interrupt the bounding box with \begin{pgfinterruptboundingbox}...\end{pgfinterruptboundingbox})

  • draw something invisible at the south edge of the semi-transparent node to make sure that the height of the bounding box is adjusted

  • currently, the red node specifies the width of the second column. If you want the semi-transparent circle to overlap "B", either make the semi-transparent circle larger or the red circle smaller.


\documentclass[]{article} \usepackage{tikz-cd} \tikzset{mynode/.style={circle, inner sep=10pt,draw,fill=red}} \begin{document} {\begin{tikzcd}[ampersand replacement=\&,column sep=3mm] A \& \node[mynode]{Foo}; \\ \& B \& \node[opacity=.1,mynode,overlay] (quack) {Foo}; \draw[opacity=0] (quack.south) circle [radius=0pt]; \end{tikzcd}} \end{document} 

enter image description here

1
  • Thanks for this workaround… it is not as nice as a simple node option, but is quite configurable if I want, e.g., only half of it… I'll keep it in mind but still wait to see if a style-based approach can be used before accepting. Or maybe we can automatically add this kind of code at the end of the drawing of the node without inheriting the overlay property? Commented Jan 6 at 13:49

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.