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 instead of all four letters. Can anyone help me out?
-
3Welcome to TeX.SX! Could you please add a minimal working example (MWE) to your question? Also, do you get any error messages from your code?– leandriisJul 6, 2019 at 15:50
-
Thank you! Will include a minimal working example next time.– EBPJul 6, 2019 at 16:56
2 Answers
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}
-
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. 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.– user121799Jul 6, 2019 at 16:08
-
Perfect! I do not really understand why this works, but it helps. Thank you!– EBPJul 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 withsite: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).– user121799Jul 6, 2019 at 17:23
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}