Beamer で tikZ を使用して階段マトリックスを描画する方法は?

Beamer で tikZ を使用して階段マトリックスを描画する方法は?

私は Beamer と LaTeX の初心者です。添付の​​ように階段状のマトリックスを描きたいのですが、とても簡単なはずですが、描き方がわかりません。tikZ (とマトリックス) のみを使用し、他のライブラリは使用しないでください。どうぞよろしくお願いいたします![ここに画像の説明を入力してください1

答え1

適度に最小限:

\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{matrix}
\begin{document}
\tikz[x=1em, y=1em, inner sep=1em/6]]
  \matrix [left delimiter={[}, right delimiter={]}] {
  \draw (0,0) \foreach \i [count=\j] in {1,2,1,3,1,2,2,1,1}{ 
    \ifnum\j>1-- ++(0,-1)\fi node [above right] (x-\j) {$x$} -- ++(\i,0)
  }
  (x-1 -| x-\j) node [left]  {possibly nonzero entries}
  (x-1 |- x-\j) node [right] {zero entries};
\\};
\end{document}

ここに画像の説明を入力してください

答え2

TikZ では、Tikz ノードを使用し{NiceTabular}てを作成しますnicematrix

\documentclass{article}
\usepackage{nicematrix,tikz}

\begin{document}

\begin{NiceTabular}{[*{14}c]}[margin=1em]
x \\
  & x &&   &   &&&   & \clap{possibly non zero entries} \\
  &   && x \\
  &   &&   & x \\
  &   &&   &   &&& x \\
  &   &&   &   &&&   & x \\
  &   &&   &   &&&   &   && x \\
  &   &&   \clap{zero entries}
           &   &&&   &   &&   && x \\
  &   &&   &   &&&   &   &&   &&   & x \\
\CodeAfter
  \tikz \draw (2-|1) -| (3-|2) -| (4-|4) -| (5-|5) 
            -| (6-|8) -| (7-|9) -| (8-|11) -| (9-|13) -| (10-|14) -- (10-|15) ; 
\end{NiceTabular}

\end{document}

上記コードの出力

答え3

1 つのオプション:

\documentclass[tikz,border=2mm]{standalone}

\usetikzlibrary{matrix}

\begin{document}
\begin{tikzpicture}
\matrix (A) [matrix of nodes, left delimiter=[,right delimiter={]}]{
 x \\
 & x\hspace*{3mm}\\
 & & x \\
 & & & x\hspace*{6mm}\\
 & & & & x\\
 & & & & & x\hspace*{3mm}\\
 & & & & & & x\hspace*{3mm}\\
 & & & & & & & x\\
 & & & & & & & & x\\};
 \foreach \i [remember=\i as \j (initially 1)] in {2,...,9}
\draw (A-\j-\j.south west) -|(A-\i-\i.south west);
\draw (A-9-9.south west)--(A-9-9.south east);
\node[anchor=south west] at ([shift={(5mm,5mm)}]A.south west) {zero entries};
\node[anchor=north east] at ([shift={(-3mm,-3mm)}]A.north east) {possibly nonzero entries};
\end{tikzpicture}
\end{document}

ここに画像の説明を入力してください

関連情報