4

I am trying to put a diagram into a box as

\fbox{
\begin{tikzcd}
A \arrow[rd] \arrow[r, "\phi"] & B \\
& C
\end{tikzcd}
}

The whole code is

\documentclass[10pt]{amsart}
\usepackage{amssymb}
\usepackage{mathrsfs}
\usepackage{amsmath}
\usepackage[new]{old-arrows}
\usepackage{extpfeil}
\usepackage{mathtools}
\usepackage[margin = 0.5 in]{geometry}
\usepackage{graphicx}
\usepackage[utf8]{inputenc}
\usepackage[usenames, dvipsnames]{color}
\usepackage{fancyhdr}
\usepackage{tikz-cd}
\usetikzlibrary{cd}
\begin{document}
\fbox{ d}
\begin{tikzcd}
A \arrow[rd] \arrow[r, "\phi"] & B \\
& C
\end{tikzcd}
\end{document}

But it gives me error every single time. Is there any way to put the diagram into box?

Sebastiano
  • 54,118
Lev Bahn
  • 143
  • 3

2 Answers2

8

By using ampersand replacement.

\documentclass[10pt]{amsart}
\usepackage{amssymb}
\usepackage{tikz-cd}
\begin{document}
\fbox{
\begin{tikzcd}[ampersand replacement=\&]
A \arrow[rd] \arrow[r, "\phi"] \& B \\
\& C
\end{tikzcd}}
\end{document}

enter image description here

5

The problem is, that the category codes are fixed if the contents are grabbed as an argument once. The following uses the grabbox package, to define an alternative form of \fbox that doesn't grab its contents as an argument but as a \hbox (you could use the collectbox package, too).

\documentclass[10pt]{amsart}
\usepackage{amssymb}
\usepackage{mathrsfs}
\usepackage{amsmath}
\usepackage[new]{old-arrows}
\usepackage{extpfeil}
\usepackage{mathtools}
\usepackage[margin = 0.5 in]{geometry}
\usepackage{graphicx}
\usepackage[utf8]{inputenc}
\usepackage[usenames, dvipsnames]{color}
\usepackage{fancyhdr}
\usepackage{tikz-cd}
\usetikzlibrary{cd}

\usepackage{grabbox}

\newcommand\Fbox {% \begingroup\grabbox0\hbox{\fbox{\usebox0}\endgroup}% } \begin{document} \Fbox{\begin{tikzcd} A \arrow[rd] \arrow[r, "\phi"] & B \ & C \end{tikzcd}} \end{document}

enter image description here

Skillmon
  • 60,462