0

I am trying to use the tikzcd package to make a commutative diagram inside a colorbox. I am having trouble combining these two environments, although the code works outside of the colorbox environment. Any help would be much appreciated! Below is my code:

     % Colored Boxed Definition
     \newenvironment{colbox}[3]{       
       \begin{center}                   % Centering minipage
       \colorbox[HTML]{#1} {            % Set's the color of minipage
       \begin{minipage}[b]{380px}       % Starts minipage
      \textbf{#2}\\ \textit{#3}       
     \end{minipage}}                     % End minipage
     }{\end{center}}                    

 \begin{document}

\begin{center}
    \colorbox[HTML]{F8E0E0}{
     \begin{minipage}[c]{450px}
      \textbf{Definition 1.1}\\ 
Let $V^1, \ V^2, \ \ldots , \ V^d, \ T$ be vectors spaces over K and let $\otimes$ be the multilinear mapping   
\begin{align*} 
 &\quad  \otimes\\
V^1 \times V^2 \times \ldots \times V^d \ &\longrightarrow \quad T\\\
\end{align*} 
such that T equals the space spanned by the image of $\otimes$, and for any multilinear mapping 
\begin{align*} 
 &\quad  f\\
V^1 \times V^2 \times \ldots \times V^d \ &\longrightarrow \quad H\\\
\end{align*} 
for any vector space H, there exists a unique linear mapping
\begin{align*} 
 &\quad  F\\
T \ &\longrightarrow \quad H\\\
\end{align*} 
which makes the following diagram commute
\begin{tikzcd}
V^1 \times V^2 \times \ldots \times V^d \arrow [r, "\otimes"]
                                     \arrow [dr, swap, "f \text{ multilinear}"]
&
T \arrow [densely dotted, d, "\exists 1 \ F \text{ linear}"]
\\
&
H
\end{tikzcd}
T is called the $\textbf{d-fold tensor product of $V^1 \times V^2 \times \ldots \times V^d$}$ and is denoted ${V^1 \otimes V^2 \otimes \ldots \otimes V^d}$, and its elements are called \textbf{tensors}. $\otimes({v^1 \times v^2 \times \ldots \times v^d})$ is denoted ${v^1 \otimes v^2 \otimes \ldots \otimes v^d}$. The tensors in the image of $\otimes$ are called $\textbf{simple tensors}$. 
     \end{minipage}}
\end{center}

\end{document}
5
  • 2
    As always on the site please post a full (but minimal) example instead of sniplets like this. Then it is easy for others to copy and test your code. Here we have to guess a lot.
    – daleif
    Commented Mar 19, 2020 at 16:18
  • 1
    This cannot be compiles on its own. There is no document class, and at least a color support package and tikzcd is missing. Please provide something that others can copy as is to a blank document (on their own system, overleaf whatever) and expect to be able to try this example.
    – daleif
    Commented Mar 19, 2020 at 17:03
  • 1
    BTW you;re doing a lot of other things wrong here. For example: $\textbf{simple tensors}$, why math mode here? It is a purely textual element.
    – daleif
    Commented Mar 19, 2020 at 17:07
  • 1
    Also don't make theorems by hand, have a look at tcolorbox it has an wast number of box constructions, some are even theorems with a box. You do not wan't to be writing stuff like this \textbf{Definition 1.1} by hand. That is a waste of time, plus you cannot refer to it other than by hard coded text, which again is a waste of time..
    – daleif
    Commented Mar 19, 2020 at 17:09
  • 1
    Never use px as a unit.
    – egreg
    Commented Mar 19, 2020 at 17:24

1 Answer 1

1

The problem is that when tikzcd is inside the argument to another command you need to use ampersand-replacement.

It's better if you properly define your colbox environment.

\documentclass{article}
\usepackage{amsmath,xcolor,tikz-cd}

% Colored Boxed Definition
\newenvironment{colbox}[3][380pt]{%
  \renewcommand{\colboxcolor}{#2}%
  \begin{lrbox}{\colboxbox}
  \begin{minipage}[b]{#1}
  \textbf{#3}\\ \itshape
}{%
  \end{minipage}
  \end{lrbox}%
  \begin{center}
  \colorbox[HTML]{\colboxcolor}{\usebox{\colboxbox}}
  \end{center}
}
\newsavebox{\colboxbox}
\newcommand{\colboxcolor}

\begin{document}

\begin{colbox}[\dimexpr\textwidth-2\fboxsep]{F8E0E0}{\textbf{Definition 1.1}}
Let $V^1$, $V^2$, \dots, $V^d$, $T$ be vector spaces over $K$ and let 
$\otimes$ be the multilinear mapping   
\begin{equation*} 
V^1 \times V^2 \times \dots \times V^d \xrightarrow{\otimes} T
\end{equation*} 
such that $T$ equals the space spanned by the image of $\otimes$, and 
for any multilinear mapping 
\begin{equation*} 
V^1 \times V^2 \times \dots \times V^d \xrightarrow{f} H
\end{equation*} 
for any vector space $H$, there exists a unique linear mapping
\begin{equation*} 
T \xrightarrow{F} H
\end{equation*} 
which makes the following diagram commute
\[
\begin{tikzcd}
V^1 \times V^2 \times \dots \times V^d \arrow [r, "\otimes"]
                                     \arrow [dr, swap, "f \text{ multilinear}"]
&
T \arrow [densely dotted, d, "\exists 1 \ F \text{ linear}"]
\\
&
H
\end{tikzcd}
\]
$T$ is called the \textbf{d-fold tensor product of 
$V^1 \times V^2 \times \dots \times V^d$} and is denoted 
${V^1 \otimes V^2 \otimes \dots \otimes V^d}$, and its elements 
are called \textbf{tensors}. 
$\otimes({v^1 \times v^2 \times \dots \times v^d})$ is denoted 
${v^1 \otimes v^2 \otimes \dots \otimes v^d}$. The tensors in the 
image of $\otimes$ are called $\textbf{simple tensors}$. 
\end{colbox}

\end{document}

enter image description here

Please, note the changes I made to the code, in particular for the labels over arrows.

I'd recommend not using px as a unit. Its value is not fixed and has nothing to do with device resolutions.

1
  • Thank you! Any idea how to add a circular arrow into the commutative triangle?
    – fdzsfhaS
    Commented Mar 19, 2020 at 18:18

You must log in to answer this question.

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