
製作描述矩陣維度的圖表(如下圖)最簡單的方法是什麼?
我可以用簡單的下標來完成,但我喜歡這些圖表給出的視覺效果。
答案1
在這裡,我使用堆疊來完成此操作,將索引設置在框下方。主要宏是
\matbox{rows}{columns}{row index}{column index}{matrix name}
。
輔助宏是\raiserows
,它類似於\raisebox
,只不過「長度」是按行指定的,而不是實際長度。注意,在 MWE 中,因為X
有 7 行,而P^T
只有 2 行,所以P^T
必須提升 (7-2)/2 = 2.5 行。
\matscale
我介紹了縮放盒子尺寸的因素。預設情況下,框尺寸的每一行和每一列將佔據\baselineskip
一邊尺寸的一個正方形。該因子\matscale
(預設為 1)將縮放該值。
編輯以設定數組索引\scriptstyle
\documentclass{article}
\usepackage{stackengine}
\stackMath
\newlength\matfield
\newlength\tmplength
\def\matscale{1.}
\newcommand\dimbox[3]{%
\setlength\matfield{\matscale\baselineskip}%
\setbox0=\hbox{\vphantom{X}\smash{#3}}%
\setlength{\tmplength}{#1\matfield-\ht0-\dp0}%
\fboxrule=1pt\fboxsep=-\fboxrule\relax%
\fbox{\makebox[#2\matfield]{\addstackgap[.5\tmplength]{\box0}}}%
}
\newcommand\raiserows[2]{%
\setlength\matfield{\matscale\baselineskip}%
\raisebox{#1\matfield}{#2}%
}
\newcommand\matbox[5]{
\stackunder{\dimbox{#1}{#2}{$\mathbf{#5}$}}{\scriptstyle(#3\times #4)}%
}
\parskip 1em
\begin{document}
$\renewcommand\matscale{.6}
\matbox{7}{4}{I}{J}{X} =
\matbox{7}{2}{I}{R}{T} \raiserows{2.5}{\matbox{2}{4}{R}{J}{P^T}} +
\matbox{7}{4}{I}{J}{E}$
\end{document}
只是為了澄清,以防不清楚。我們可以使用實際的(非常大的)矩陣維度,只要比例適當小即可。例如,以下作品:
$\renewcommand\matscale{.05}
\matbox{300}{75}{I}{J}{X} =
\matbox{300}{25}{I}{R}{T} \raiserows{137.5}{\matbox{25}{75}{R}{J}{P^T}} +
\matbox{300}{75}{I}{J}{E}$
答案2
這是一種“手動”執行此操作的方法。
\documentclass{article}
\usepackage{amsbsy}
\newcommand*{\clap}[1]{\hbox to 0pt{\hss#1\hss}}
\newcommand*{\mat}[1]{\boldsymbol{\mathrm{#1}}}
\newcommand*{\subdims}[3]{\clap{\raisebox{#1}[0pt][0pt]{$\scriptstyle(#2 \times #3)$}}}
\fboxrule=1pt
\begin{document}
\Huge
\[
\framebox[2.5cm]{\clap{\raisebox{0pt}[1.5cm][1.5cm]{$\mat X$}}\subdims{-2.5cm} I J} =
\framebox[1.5cm]{\clap{\raisebox{0pt}[1.5cm][1.5cm]{$\mat T$}}\subdims{-2.5cm} I R} \
\framebox[2.5cm]{\clap{\raisebox{5mm}[1.5cm]{$\mat P^T$}} \subdims{-1cm} R J} +
\framebox[2.5cm]{\clap{\raisebox{0pt}[1.5cm][1.5cm]{$\mat E$}}\subdims{-2.5cm} I J}
\]
\end{document}
結果:
顯然這無法與 Segletes 先生的有力而籠統的答案相比!然而,它確實使用了更基本的命令,這可能具有在慢速機器上編譯速度更快的好處,並且即使在缺少軟體包的較小安裝中也能工作。或者也許您只是喜歡把手弄髒。當然,缺點是您必須自己確定所有寬度、高度和深度。
注意:如果您使用mathtools
或任何其他提供\clap
命令的套件,它將與定義衝突。在這種情況下,只需省略此定義並使用\clap
提供的定義即可。
答案3
這是透過amsmath
包的一種可能的解決方案。
程式碼
\documentclass[12pt]{article}
\usepackage[margin=1cm,paper size={20cm,5cm}]{geometry}
\usepackage{amsmath,amssymb}
\thispagestyle{empty}
\begin{document}
\[
{\begin{pmatrix}
& & \\
& X &\\
& &
\end{pmatrix}
\mkern-10mu}_{I \times J}=
{\begin{pmatrix}
\phantom{T}\\
\makebox[20pt][c]{$T$}\\
\phantom{T}
\end{pmatrix}
\mkern-10mu}_{I \times R}
{\begin{pmatrix}
& & \\
& \raisebox{10pt}{$P^T$} &\\
\end{pmatrix}\mkern-10mu}_{R \times J}+
{\begin{pmatrix}
& & \\
& E &\\
& &
\end{pmatrix}
\mkern-10mu}_{I \times J}
\]
\end{document}