5

I want a commutative diagram in a footnote using tikzcd. For footnotes I just use the standard \footnote command. However, using \[\begin{tikzcd}A&B\\C&D\end{tikzcd}\] inside the footnote gives just enter image description here instead of all four letters. Can anyone help me out?

2

2 Answers 2

8

Welcome to TeX-SE! You need to use an ampersand replacement (or another trick), but then it works.

\documentclass{article}
\usepackage{tikz-cd}
\begin{document}
\[\begin{tikzcd}A&B\\C&D\end{tikzcd}\] 

X\footnote{\[\begin{tikzcd}[ampersand replacement=\&]A\&B\\C\&D\end{tikzcd}\]}
\end{document}
4
  • I think that your solution is unique: see the manual pag. 13 By default, TikZ makes the character & active inside matrices, and this causes the error message ! Package pgfbasematrix Error: Single ampersand used with wrong catcode. when {tikzcd} is used inside the argument to a macro such as a Beamer frame or a footnote.
    – Sebastiano
    Jul 6, 2019 at 16:06
  • 1
    @Sebastiano Thanks! I think you could also use a savebox. But yes, I think this is the most direct solution.
    – user121799
    Jul 6, 2019 at 16:08
  • Perfect! I do not really understand why this works, but it helps. Thank you!
    – EBP
    Jul 6, 2019 at 16:57
  • 1
    @EBP And ampersand is a special character, which can cause all sorts of little headaches here and there. And \footnote and \section commands, beamer frames and so on are special, so there some "standard tricks" one can use. By now this site has as a huge repertoire of these tricks, very often a google search with site:tex.stackexchange.com and the error message will drag you to a trick (but this one I knew out of the top of my hat because I have seen similar questions before).
    – user121799
    Jul 6, 2019 at 17:23
0

This solution uses a savebox. Interestingly, the \savebox macro didn't work, even though it should be equivalent.

Note that \box automatically empties the contents, while \usebox preserves them.

\documentclass{article}
\usepackage{tikz-cd}
\newsavebox{\tempbox}
\begin{document}
\[\begin{tikzcd}A&B\\C&D\end{tikzcd}\] 

\setbox\tempbox=\hbox{\begin{tikzcd}A&B\\C&D\end{tikzcd}}%
X\footnote{\[\box\tempbox\]}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .