但是,我只能绘制矩阵,而不能进行它们之间的数学运算,即点积和等号(括号的高度相同是一个优点)。下面我附上了我的部分代码以及我目前所取得的进展。
任何帮助将非常感激
谢谢
\documentclass[usenames,dvipsnames]{beamer}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{fit, calc, matrix, positioning, arrows.meta, intersections, through, backgrounds, patterns}
\usepackage{pgfplots}
\pgfplotsset{compat = newest}
\pgfplotsset{overwrite option/.style args={#1 with #2}{#1=#2,#1/.code=}}
\begin{frame}{MATRIX MULTIPLICATION}
More graphically:
\begin{tikzpicture}
\scriptsize
\matrix (m)[
matrix of math nodes,
nodes in empty cells,
%minimum width=width("998888"),
left delimiter=(,
right delimiter=)
] {
a_{11} && \cdots && a_{1k} && \cdots && a_{1n} \\
\vdots && && \vdots && &&\vdots \\
a_{i1} && \cdots && a_{ik} && \cdots && a_{in} \\
\vdots && && \vdots && && \vdots \\
a_{m1} && \cdots && a_{mk} && \cdots && a_{mn} \\
} ;
\draw (m-3-1.south west) rectangle (m-3-5.north east);
\begin{scope}[xshift=95pt]
\matrix (m)[
matrix of math nodes,
nodes in empty cells,
%minimum width=width("998888"),
left delimiter=(,
right delimiter=)
] {
b_{11} && \cdots && b_{1j} && \cdots && b_{1p} \\
\vdots && && \vdots && &&\vdots \\
b_{k1} && \cdots && b_{kj} && \cdots && b_{kp} \\
\vdots && && \vdots && && \vdots \\
b_{n1} && \cdots && b_{nj} && \cdots && b_{np} \\
} ;
\draw (m-5-3.south west) rectangle (m-1-3.north east);
\end{scope}
\begin{scope}[xshift=200pt]
\matrix (m)[
matrix of math nodes,
nodes in empty cells,
%minimum width=width("998888"),
left delimiter=(,
right delimiter=)
] {
c_{11} && \cdots && c_{1j} && \cdots && c_{1p} \\
\vdots && && \vdots && &&\vdots \\
c_{i1} && \cdots && c_{ij} && \cdots && c_{ip} \\
\vdots && && \vdots && && \vdots \\
c_{m1} && \cdots && c_{mj} && \cdots && c_{mp} \\
} ;
\draw (m-3-3.south west) rectangle (m-3-3.north east);
\end{scope}
\end{tikzpicture}
\end{frame}
答案1
首先,我会使用positioning
库将矩阵彼此相邻放置,然后无需找出正确的xshift
。 (您也可以这样做\matrix (m2) at (95pt,0) ...
而不是scope
。)
命名矩阵m
和m2
后m3
,您可以例如执行
\path (m) -- node {$\cdot$} (m2)
(m2) -- node {$=$} (m3);
将符号置于它们中间。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning, matrix}
\begin{document}
\begin{tikzpicture}
\scriptsize
\matrix (m)[
matrix of math nodes,
nodes in empty cells,
%minimum width=width("998888"),
left delimiter=(,
right delimiter=)
] {
a_{11} && \cdots && a_{1k} && \cdots && a_{1n} \\
\vdots && && \vdots && &&\vdots \\
a_{i1} && \cdots && a_{ik} && \cdots && a_{in} \\
\vdots && && \vdots && && \vdots \\
a_{m1} && \cdots && a_{mk} && \cdots && a_{mn} \\
} ;
\draw (m-3-1.south west) rectangle (m-3-5.north east);
\matrix (m2) [
matrix of math nodes,
nodes in empty cells,
%minimum width=width("998888"),
left delimiter=(,
right delimiter=),
right=of m
] {
b_{11} && \cdots && b_{1j} && \cdots && b_{1p} \\
\vdots && && \vdots && &&\vdots \\
b_{k1} && \cdots && b_{kj} && \cdots && b_{kp} \\
\vdots && && \vdots && && \vdots \\
b_{n1} && \cdots && b_{nj} && \cdots && b_{np} \\
} ;
\draw (m-5-3.south west) rectangle (m-1-3.north east);
\matrix (m3)[
matrix of math nodes,
nodes in empty cells,
%minimum width=width("998888"),
left delimiter=(,
right delimiter=),
right=of m2
] {
c_{11} && \cdots && c_{1j} && \cdots && c_{1p} \\
\vdots && && \vdots && &&\vdots \\
c_{i1} && \cdots && c_{ij} && \cdots && c_{ip} \\
\vdots && && \vdots && && \vdots \\
c_{m1} && \cdots && c_{mj} && \cdots && c_{mp} \\
} ;
\draw (m-3-3.south west) rectangle (m-3-3.north east);
\path (m) -- node {$\cdot$} (m2)
(m2) -- node {$=$} (m3);
\end{tikzpicture}
\end{document}
附录
请注意,beamer
您不能直接使用矩阵,您需要一个fragile
框架或使用ampersand replacement
,例如在 beamer 中使用 tikz 矩阵时出现“单个 & 符号与错误的 catcode 一起使用”错误
下面我制作了框架fragile
。我还制作了一种新样式pmat
,并将其应用于所有矩阵,并进行了一些修改,以便它们实际上适合框架。
\documentclass[usenames,dvipsnames]{beamer}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{fit, calc, matrix, positioning, arrows.meta, intersections, through, backgrounds, patterns}
\usepackage{pgfplots}
\pgfplotsset{compat = newest}
\pgfplotsset{overwrite option/.style args={#1 with #2}{#1=#2,#1/.code=}}
\begin{document}
\begin{frame}[fragile]{MATRIX MULTIPLICATION}
More graphically:
\begin{tikzpicture}[
pmat/.style={
matrix of math nodes,
nodes={font=\footnotesize\strut, inner sep=1.5pt},
left delimiter=(,
right delimiter=),
}
]
\matrix (m)[pmat] {
a_{11} && \cdots && a_{1k} && \cdots && a_{1n} \\
\vdots && && \vdots && &&\vdots \\
a_{i1} && \cdots && a_{ik} && \cdots && a_{in} \\
\vdots && && \vdots && && \vdots \\
a_{m1} && \cdots && a_{mk} && \cdots && a_{mn} \\
} ;
\draw (m-3-1.south west) rectangle (m-3-5.north east);
\matrix (m2) [pmat,right=of m] {
b_{11} && \cdots && b_{1j} && \cdots && b_{1p} \\
\vdots && && \vdots && &&\vdots \\
b_{k1} && \cdots && b_{kj} && \cdots && b_{kp} \\
\vdots && && \vdots && && \vdots \\
b_{n1} && \cdots && b_{nj} && \cdots && b_{np} \\
} ;
\draw (m-5-3.south west) rectangle (m-1-3.north east);
\matrix (m3)[pmat,right=of m2] {
c_{11} && \cdots && c_{1j} && \cdots && c_{1p} \\
\vdots && && \vdots && &&\vdots \\
c_{i1} && \cdots && c_{ij} && \cdots && c_{ip} \\
\vdots && && \vdots && && \vdots \\
c_{m1} && \cdots && c_{mj} && \cdots && c_{mp} \\
} ;
\draw (m-3-3.south west) rectangle (m-3-3.north east);
\path (m) -- node {$\cdot$} (m2)
(m2) -- node {$=$} (m3);
\end{tikzpicture}
\end{frame}
\end{document}
答案2
使用\vphantom{b_{ij}}
第一个和最后一个矩阵中每行开头的变量:
\documentclass[usenames,dvipsnames]{beamer}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
backgrounds,
calc,
decorations.pathreplacing,
fit,
intersections,
matrix,
positioning, patterns,
through
}
\begin{document}
\begin{frame}[fragile]
\frametitle{MATRIX MULTIPLICATION}
More graphically:
\[
\begin{tikzpicture}[
every matrix/.style = {matrix of math nodes,
nodes in empty cells,
nodes = {inner sep=2pt, font=\scriptsize},
left delimiter=(,
right delimiter=),
inner sep=0pt
},
]
\matrix (m1)
{
\vphantom{b_{ij}}
a_{11} & \cdots & a_{1k} & \cdots & a_{1n} \\
\vdots & & \vdots & & \vdots \\
\vphantom{b_{ij}}
a_{i1} & \cdots & a_{ik} & \cdots & a_{in} \\
\vdots & & \vdots & & \vdots \\
\vphantom{b_{ij}}
a_{m1} & \cdots & a_{mk} & \cdots & a_{mn} \\
} ;
\draw (m1-3-1.south west) rectangle (m1-3-5.north east);
\node (m1a) [right=2mm of m1] {$\cdot$};
\matrix (m2)[right=2mm of m1a]
{
b_{11} & \cdots & b_{1j} & \cdots & b_{1p} \\
\vdots & & \vdots & & \vdots \\
b_{k1} & \cdots & b_{kj} & \cdots & b_{kp} \\
\vdots & & \vdots & & \vdots \\
b_{n1} & \cdots & b_{nj} & \cdots & b_{np} \\
} ;
\draw (m2-5-3.south west) rectangle (m2-1-3.north east);
\node (m2a) [right=2mm of m2] {$=$};
\matrix (m3) [right=2mm of m2a]
{
\vphantom{b_{ij}}
c_{11} & \cdots & c_{1j} & \cdots & c_{1p} \\
\vdots & & \vdots & &\vdots \\
\vphantom{b_{ij}}
c_{i1} & \cdots & c_{ij} & \cdots & c_{ip} \\
\vdots & & \vdots & & \vdots \\
\vphantom{b_{ij}}
c_{m1} & \cdots & c_{mj} & \cdots & c_{mp} \\
} ;
\draw (m3-3-3.south west) rectangle (m3-3-3.north east);
\end{tikzpicture}
\]
\end{frame}
\end{document}
答案3
您可以使用{pNiceMatrix}
of来实现这一点。此环境与ofnicematrix
类似,但在数组的单元格下创建 PGF/Tikz 节点。使用这些节点可以轻松使用 Tikz 绘制矩形。{pmatrix}
amsmath
\documentclass[usenames,dvipsnames]{beamer}
\usepackage{tikz}
\usepackage{nicematrix}
\begin{document}
\begin{frame}[fragile]{MATRIX MULTIPLICATION}
More graphically:
\NiceMatrixOptions{small,create-large-nodes,columns-width=4mm}
$\begin{pNiceArray}{ccccc<{\vphantom{b_{np}}}}
a_{11} & \cdots & a_{1j} & \cdots & a_{1p} \\
\vdots & & \vdots & &\vdots \\
a_{i1} & \cdots & a_{ij} & \cdots & a_{ip} \\
\vdots & & \vdots & & \vdots \\
a_{m1} & \cdots & a_{mj} & \cdots & a_{mp}
\CodeAfter
\tikz \draw (3-1-large.south west) rectangle (3-5-large.north east);
\end{pNiceArray}
\cdot
\begin{pNiceArray}{ccccc}
b_{11} & \cdots & b_{1j} & \cdots & b_{1p} \\
\vdots & & \vdots & &\vdots \\
b_{k1} & \cdots & b_{kj} & \cdots & b_{kp} \\
\vdots & & \vdots & & \vdots \\
b_{n1} & \cdots & b_{nj} & \cdots & b_{np}
\CodeAfter
\tikz \draw (5-3-large.south west) rectangle (1-3-large.north east);
\end{pNiceArray}
=
\begin{pNiceArray}{ccccc<{\vphantom{b_{np}}}}
c_{11} & \cdots & c_{1j} & \cdots & c_{1p} \\
\vdots & & \vdots & &\vdots \\
c_{i1} & \cdots & c_{ij} & \cdots & c_{ip} \\
\vdots & & \vdots & & \vdots \\
c_{m1} & \cdots & c_{mj} & \cdots & c_{mp}
\CodeAfter
\tikz \draw (3-3-large.south west) rectangle (3-3-large.north east);
\end{pNiceArray}$
\end{frame}
\end{document}