是否可以使用 LaTeX 创建类似以下草稿的矩阵?
我发现这个蒂克赞普勒,但我不知道如何获取对角线上的点。
编辑:这是我得到的进展:
$$
\begin{pmatrix}
1 & & & & & & & & & \\
& & & & & & & & & \\
& & 1 & & & & & & & \\
& & & -1 & & & & & & \\
& & & & & & & & & \\
& & & & & - 1 & & & & \\
& & & & & & cos \omega_1 & -sin \omega_1 & & \\
& & & & & & sin \omega_1 & cos \omega_1 & & \\
& & & & & & & & & \\
& & & & & & & & & cos \omega_2 \\
& & & & & & & & & sin \omega_2 \\
\end{pmatrix}
$$
我想要的是石灰部分,但无法用 LaTeX 来实现。
答案1
如果您需要矩阵块周围的垂直线和水平线,以下解决方案(也不需要 TikZ)可能会引起您的兴趣。 (我已更新示例以反映您问题中的更新,这似乎需要额外的\ddots
行/列。)
请注意,我使用array
环境而不是matrix
(或pmatrix
)环境,因为需要右对齐某些列的内容。
\documentclass{article}
\usepackage{amsmath,array}
\renewcommand\arraycolsep{4pt} % default value: 6pt
% short-hand commands for multicolumn entries with vertical bar
% on left and right hand sides, respectively
\newcommand{\mcl}[1]{\multicolumn{1}{|r}{#1}}
\newcommand{\mcr}[1]{\multicolumn{1}{r|}{#1}}
\begin{document}
\begin{equation*}
\left( \,\begin{array}{rcr rcr rr c rr}
\cline{1-3}
\mcl{1} & & \mcr{} \\
\mcl{} & \ddots & \mcr{} \\
\mcl{} & & \mcr{1} \\
\cline{1-6}
& & & \mcl{-1} & & \mcr{} \\
& & & \mcl{} & \ddots & \mcr{} \\
& & & \mcl{} & & \mcr{-1}\\
\cline{4-8}
& & & & & & \mcl{\cos \omega} & \mcr{-\sin \omega}\\
& & & & & & \mcl{\sin \omega} & \mcr{ \cos \omega}\\
\cline{7-8}
& & & & & & & & \ddots\\
\cline{10-11}
& & & & & & & & & \mcl{\cos \omega} & \mcr{-\sin \omega}\\
& & & & & & & & & \mcl{\sin \omega} & \mcr{ \cos \omega}\\
\cline{10-11}
\end{array}\,\right)
\end{equation*}
\end{document}
附录:使用\boxed
宏,设置该矩阵的代码可以大大简化:
\documentclass{article}
\usepackage{amsmath,array}
\renewcommand\arraycolsep{4pt} % default value: 6pt
\begin{document}
\begin{equation*}
\left( \,
\begin{array}{r@{}r@{}r r r} % @{} is used twice to suppress intercolumn whitespace
\boxed{ \begin{array}{rrr} % First block
1 \\
& \ddots\\
& & 1 \\
\end{array} } \\
& \boxed{ \begin{array}{rrr} % Second block
-1 \\
& \ddots\\
& & -1\\
\end{array} } \\
& & \boxed{ \begin{array}{rr} % Third block
\cos \omega & -\sin \omega\\
\sin \omega & \cos \omega\\
\end{array} } \\
& & & \ddots\\ % Fourth "block" -- not boxed
& & & & \boxed{ \begin{array}{rr} % Fifth block
\cos \omega & -\sin \omega\\
\sin \omega & \cos \omega\\
\end{array} } \\
\end{array}\,\right)
\end{equation*}
\end{document}
答案2
您可以使用 Stefan 提供的优秀代码:(我个人更喜欢 tikz 的代码)
\documentclass{article}
\usepackage{tikz,amsmath}
\usetikzlibrary{fit,matrix}
\tikzset{%
highlight/.style={rectangle,rounded corners,fill=red!15,draw,fill opacity=0.5,thick,inner sep=0pt}
}
\newcommand{\tikzmark}[2]{\tikz[overlay,remember picture,baseline=(#1.base)] \node (#1) {#2};}
%
\newcommand{\Highlight}[1][submatrix]{%
\tikz[overlay,remember picture]{
\node[highlight,fit=(left.north west) (right.south east)] (#1) {};}
}
\begin{document}
\[
M = \left(\begin{array}{*5{c}}
\tikzmark{left}{1} & 2 & 3 & 4 & 5\\
6 & \ddots & 8 & 9 & 10 \\
11 & 12 & \ddots\tikzmark{right}{} & 14 & 15 \\
16 & 17 & 18 & \ddots & 20 \\
0 & 0 & 0 & 0 & 1
\end{array}\right)
\Highlight[first]
\]
\end{document}
更复杂的事情:
\documentclass{article}
\usepackage{tikz,amsmath}
\usetikzlibrary{fit,matrix}
\tikzset{%
highlight/.style={rectangle,fill=#1!15,draw,fill opacity=0.5,thick,inner sep=1pt}
}
\newcommand{\tikzmark}[2]{\tikz[overlay,remember picture,baseline=(#1.base)] \node (#1) {#2};}
\newcommand{\Highlight}[3]{%
\tikz[overlay,remember picture]{
\node[highlight=#3,fit=(#1.north west) (#2.south east)] {};}
}
\begin{document}
\begin{equation*}
\begin{pmatrix}
\tikzmark{1}{c} & -a & 0 & \dots & \dots & \dots & 0 \\
-b & \tikzmark{2}{c} & -a & \ddots & & & \vdots \\
0 & -b & \tikzmark{3}{c} & \ddots & \ddots & & \vdots \\
\vdots & \ddots & \ddots & \ddots & \ddots & \ddots & \vdots \\
\vdots & & \ddots & \ddots & c & -a & 0 \\
\vdots & & & \ddots & -b & \tikzmark{4}{c} & -a \\
0 & \dots & \dots & \dots & 0 & -b & c
\end{pmatrix}
\end{equation*}
\Highlight{1}{2}{blue}
\Highlight{3}{4}{red}
\end{document}
答案3
如果您使用该amsmath
包,则无需执行以下操作tikz
:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[\begin{pmatrix}1&&&&&&&&&\\
&\ddots&&&&&&&&\\
&&1&&&&&&&\\
&&&-1&&&&&&\\
&&&&\ddots&&&&&\\
&&&&&-1&&&&\\
&&&&&&\cos w&-\sin w&&\\
&&&&&&\sin w&\cos w&&\\
&&&&&&&&\cos w&-\sin w\\
&&&&&&&&\sin w&\cos w\\\end{pmatrix}
\]
或者使用这些框(如果你需要的话):
\[\begin{pmatrix}
\boxed{\begin{matrix}
1&&\\
&\ddots&\\
&&1
\end{matrix}}&&&\\
&\boxed{\begin{matrix}
-1&&\\
&\ddots&\\
&&-1
\end{matrix}}&&\\
&&\boxed{\begin{matrix}
\cos w&-\sin w\\
\sin w&\cos w
\end{matrix}}&\\
&&&\boxed{\begin{matrix}
\cos w&-\sin w\\
\sin w&\cos w
\end{matrix}}
\end{pmatrix}
\]
\end{document}