我想要将元素 $A_0,A_1 \cdots A_l,Z_1,Z_2, \cdots Z_d$ 放入一个框内。我编写了以下代码。
\documentclass[13pt]{article}
\usepackage{tikz,amsmath,amssymb,mathtools,nccmath}
\DeclarePairedDelimiter\abs{\lvert}{\rvert}%
\newcommand\cbox[1]{\tikz[overlay, remember picture,baseline=-\the\dimexpr\fontdimen22\textfont2\relax]\node[rectangle,fill=blue!50,fill opacity = 0.2,draw,thick,text opacity =1] {$#1$};}
\begin{document}
\begin{equation*}
\textbf{F}~~ = ~~
\begin{bmatrix}
\begin{matrix}
a_{10}~~~\cbox{A_0}\\[0.22cm]
a_{20}~~~\cbox{A_0}\\[0.22cm]
\vdots\\
a_{l0}~~~\cbox{A_0}\\
\end{matrix} & ~~\vline~~ &
\begin{matrix}
\cbox{A_1}\\[0.22cm]
\cbox{A_2}\\[0.22cm]
\vdots\\
\cbox{A_l}
\end{matrix} & ~~\vline &
\begin{matrix}
a_{11}~~~\cbox{Z_1} ~~~& a_{12}~~~\cbox{Z_2} & \dots & a_{1d}~~~\cbox{Z_d}\\[0.22cm]
a_{21}~~~\cbox{Z_1} ~~~& a_{22}~~~\cbox{Z_2}& \dots & a_{2d}~~~\cbox{Z_d}\\[0.22cm]
\vdots & \vdots & \dots & \vdots\\
a_{l1}~~~\cbox{Z_1} ~~~& a_{l2}~~~\cbox{Z_2} & \dots & a_{ld}~~~\cbox{Z_d}\\
\end{matrix}
\end{bmatrix}
\end{equation*}
\end{document}
但是矩阵边界与最后一列重叠。有人能帮忙解决吗?
答案1
我个人最喜欢的当然是后者。请注意,我还将矩阵条目(3,5)
从\dots
改为\ddots
。
\documentclass[13pt]{article}
\usepackage{tikz,amsmath,amssymb,mathtools,nccmath}
\DeclarePairedDelimiter\abs{\lvert}{\rvert}%
\newcommand\cbox[1]{\tikz[overlay, remember picture,baseline=-\the\dimexpr\fontdimen22\textfont2\relax]\node[rectangle,fill=blue!50,fill opacity = 0.2,draw,thick,text opacity =1] {$#1$};}
\begin{document}
Initial:
\begin{equation*}
\textbf{F}~~ = ~~
\begin{bmatrix}
\begin{matrix}
a_{10}~~~\cbox{A_0}\\[0.22cm]
a_{20}~~~\cbox{A_0}\\[0.22cm]
\vdots\\
a_{l0}~~~\cbox{A_0}\\
\end{matrix} & ~~\vline~~ &
\begin{matrix}
\cbox{A_1}\\[0.22cm]
\cbox{A_2}\\[0.22cm]
\vdots\\
\cbox{A_l}
\end{matrix} & ~~\vline &
\begin{matrix}
a_{11}~~~\cbox{Z_1} ~~~& a_{12}~~~\cbox{Z_2} & \dots & a_{1d}~~~\cbox{Z_d}\\[0.22cm]
a_{21}~~~\cbox{Z_1} ~~~& a_{22}~~~\cbox{Z_2}& \dots & a_{2d}~~~\cbox{Z_d}\\[0.22cm]
\vdots & \vdots & \dots & \vdots\\
a_{l1}~~~\cbox{Z_1} ~~~& a_{l2}~~~\cbox{Z_2} & \dots & a_{ld}~~~\cbox{Z_d}\\
\end{matrix}
\end{bmatrix}
\end{equation*}
\renewcommand\cbox[1]{\tikz[baseline={(n.base)}]\node (n) [rectangle,fill=blue!10,draw,thick] {$#1$};}
Only changed \verb|\cbox| and removed \verb|~|:
\begin{equation*}
\textbf{F}\quad=\quad
\begin{bmatrix}
\begin{matrix}
a_{10}\cbox{A_0} \\[0.22cm]
a_{20}\cbox{A_0} \\[0.22cm]
\vdots \\
a_{l0}\cbox{A_0} \\[0.22cm]
\end{matrix}
& \vline &
\begin{matrix}
\cbox{A_1} \\[0.22cm]
\cbox{A_2} \\[0.22cm]
\vdots \\
\cbox{A_l} \\[0.22cm]
\end{matrix}
& \vline &
\begin{matrix}
a_{11}\cbox{Z_1} & a_{12}\cbox{Z_2} & \dots & a_{1d}\cbox{Z_d} \\[0.22cm]
a_{21}\cbox{Z_1} & a_{22}\cbox{Z_2} & \dots & a_{2d}\cbox{Z_d} \\[0.22cm]
\vdots & \vdots & \ddots & \vdots \\
a_{l1}\cbox{Z_1} & a_{l2}\cbox{Z_2} & \dots & a_{ld}\cbox{Z_d} \\[0.22cm]
\end{matrix}
\end{bmatrix}
\end{equation*}
Changed to single matrix, with some tweaking of \verb|\arraystretch| and extra row distance:
\begin{equation*}
\textbf{F}\quad=\quad
\left[
\renewcommand{\arraystretch}{1.75}
\begin{array}{@{}c|c|cccc}
a_{10}\cbox{A_0} & \cbox{A_1} & a_{11}\cbox{Z_1} & a_{12}\cbox{Z_2} & \dots & a_{1d}\cbox{Z_d} \\
a_{20}\cbox{A_0} & \cbox{A_2} & a_{21}\cbox{Z_1} & a_{22}\cbox{Z_2} & \dots & a_{2d}\cbox{Z_d} \\
\vdots & \vdots & \vdots & \vdots & \ddots & \vdots \\[-1mm]
a_{l0}\cbox{A_0} & \cbox{A_l} & a_{l1}\cbox{Z_1} & a_{l2}\cbox{Z_2} & \dots & a_{ld}\cbox{Z_d} \\[1.5mm]
\end{array}
\right]
\end{equation*}
\end{document}
答案2
你不需要像 TiKZ 那样的大锤子来实现这一点:简单\fcolorbox
就可以了。
13pt
不相关:标准类中没有选项(即使有extsizes
包)。
\documentclass[12pt]{article}
\usepackage{tikz, amssymb, mathtools, nccmath}
\DeclarePairedDelimiter\abs{\lvert}{\rvert}%
\newcommand\cbox[1]{\tikz[overlay, remember picture,baseline=-\the\dimexpr\fontdimen22\textfont2\relax]\node[rectangle,fill=blue!50,fill opacity = 0.2,draw,thick,text opacity =1] {$#1$};}
\colorlet{myblue}{blue!12}
\newcommand{\Cbox}[1]{\setlength{\fboxrule}{0.8pt}\fcolorbox{black}{myblue}{$ #1 $}}
\usepackage{makecell, bigstrut}
\begin{document}
\begin{equation*}
\setlength{\extrarowheight}{5pt}
\textbf{F}~~ = ~~
\begin{bmatrix}
\begin{array}{@{}c@{\,}c|c|*{4}{c@{\,}c}@{\,}}
a_{10} & \Cbox{A_0} & \Cbox{A_1} & a_{11} & \Cbox{Z_1} & a_{12} & \Cbox{Z_2} & \dots & \mkern-1mu\dots & a_{1d} & \Cbox{Z_d}\bigstrut[t]\\
a_{20} & \Cbox{A_0} & \Cbox{A_2} & a_{21} & \Cbox{Z_1} & a_{22} & \Cbox{Z_2}& \dots & \mkern-1mu\dots & a_{2d} & \Cbox{Z_d}\\
\vdots & & \vdots & \vdots & & & & & & & \vdots \\
a_{l0} & \Cbox{A_0} & \Cbox{A_l} & a_{l1} & \Cbox{Z_1} & a_{l2} & \Cbox{Z_2} & \dots & \mkern-1mu\dots & a_{ld} & \Cbox{Z_d}\bigstrut[b]
\end{array}
\end{bmatrix}
\end{equation*}
\end{document}