在(方形)矩阵内创建形状

在(方形)矩阵内创建形状

我正在尝试用 latex 打印下面的图片,但几个星期都没能成功。如果能得到帮助,我将非常高兴。

图 1:三角形、矩形和正方形矩阵

请注意,第一张图片

  1. 每个形状都涂成灰色

  2. 每个形状都标记为 a1、a2、a3、y 等

  3. 除了变量 y 之外,我们有两个零(左和右),不是字母 0 也不是圆圈

图 2:砧形矩阵

图 2 有一个形状,看起来像两个铁砧连接在一起,然后用虚线分隔。

答案1

尝试理解以下代码。

\documentclass{article}
\usepackage{tikz} 
\usetikzlibrary{positioning, shapes.geometric, matrix}

\begin{document}
\[
A = \left[
\begin{tikzpicture}[%
baseline,
triangle/.style={%
    draw,
    fill=gray!50,
    minimum width=1.4142cm,
    inner sep=0pt,
    isosceles triangle, 
    isosceles triangle apex angle=90,
    shape border uses incircle,
    shape border rotate=#1},
rect/.style={%
        draw, fill=gray!50}
]
\matrix (A) [matrix, row sep=1mm, column sep=2mm] {
\node[triangle=45, anchor=north] (a11) {$a_1$}; &
\node[rect, minimum height=1cm, anchor=north] (a12) {$y_1$}; &
\node[triangle=135, anchor=north] (a13) {$a_2$}; \\
\node[] {$o$}; &
\node[rect, minimum height=1cm] (a22) {$y_1$}; &
\node[] {$o$};\\
\node[triangle=-45, anchor=south] (a31) {$a_3$}; &
\node[rect, minimum height=1cm, anchor=south] (a32) {$y_2$}; &
\node[triangle=-135, anchor=south] (a33) {$a_4$}; \\
};
\end{tikzpicture}
\right] \\
A = \left[
\begin{tikzpicture}[%
baseline,
triangle/.style={%
%    fill=gray!50,
    minimum width=1.4142cm,
    inner sep=0pt,
    isosceles triangle, 
    isosceles triangle apex angle=90,
    shape border uses incircle,
    shape border rotate=#1},
rect/.style={%
%    fill=gray!50
    }
]
\matrix (A) [matrix, row sep=0pt, column sep=0pt] {
\node[triangle=45, anchor=north] (a11) {$a_1$}; &
\node[rect, minimum height=1cm, anchor=north] (a12) {$y_1$}; &
\node[triangle=135, anchor=north] (a13) {$a_2$}; \\
\node[] {$o$}; &
\node[rect, minimum height=1cm] (a22) {$y_1$}; &
\node[] {$o$};\\
\node[triangle=-45, anchor=south] (a31) {$a_3$}; &
\node[rect, minimum height=1cm, anchor=south] (a32) {$y_2$}; &
\node[triangle=-135, anchor=south] (a33) {$a_4$}; \\
};
\draw (a11.left corner)--(a13.right corner)--(a22.north east)--(a22.south east)--(a33.left corner)--(a31.right corner)--(a22.south west)--(a22.north west)--cycle;
\draw[dashed] (a11.left corner|-a22.north)--(a13.right corner|-a22.north);
\draw[dashed] (a11.left corner|-a22.south)--(a13.right corner|-a22.south);
\draw[dashed] (A.north-|a22.west)--(A.south-|a22.west);
\draw[dashed] (A.south-|a22.east)--(A.north-|a22.east);
\end{tikzpicture}
\right]
\]
\end{document}

![在此处输入图片描述

相关内容