在 colorbox 中使用 tikzcd 包

在 colorbox 中使用 tikzcd 包

我正在尝试使用 tikzcd 包在 colorbox 中制作交换图。虽然代码在 colorbox 环境之外也能工作,但我在结合这两个环境时遇到了麻烦。任何帮助都将不胜感激!以下是我的代码:

     % 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}

答案1

问题是当tikzcd位于另一个命令的参数内时,您需要使用ampersand-replacement

colbox如果您正确定义您的环境那就更好了。

\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}

在此处输入图片描述

请注意我对代码所做的更改,特别是箭头上的标签。

我建议不要将其用作px单位。其值不固定,与设备分辨率无关。

相关内容