TikZ 双块矩阵

TikZ 双块矩阵

我想得到一个像下面我所画的图,基本上是相同矩阵的两个块,红色块的箭头向上且反向对角,绿色块的箭头向上。绿色中间的点表示重复相同的模式......我有下面的 TikZ 代码作为起点,但我不确定哪种方法是最简单的方法......我仍然在努力用复杂的标记在 TikZ 的 for 循环中获得条件。

在此处输入图片描述

作为起点,我有这个,包括一个带注释的尝试来创建上三角效果,省略对角线下方元素的箭头,但无法使该代码工作。

\begin{figure}[!h]
\centering
    \begin{tikzpicture}[scale=1.5]
    \clip (-0.3,-1.3) rectangle (8.3,4.3);
%   \foreach \x in {0,...,8} {
%       \foreach \y [evaluate=\y as \z using int(4-\y)] in {0,...,4} {
%           \pgfmathtruncatemacro{\myresult}{\x<\z ? 1 : 0}
%           \ifnum\myresult=0%
%           \node at (\x cm,\y cm) (g-\x-\y) {$a_{\x,\z}$};\fi
%       }
%   }
    \foreach \x in {0,...,8} {
      \foreach \y [evaluate=\y as \z using int(4-\y)] in {0,...,4} {
        \node at (\x cm,\y cm) (g-\x-\y) {$a_{\x,\z}$};
      }
    }
    % vertical dependency
    \foreach \x in {0,...,8} {
      \foreach \y in {0,...,3} {
        \draw[->,shorten <=2pt,shorten >=7pt] (g-\x-\y) -- +(0,20pt);
      }
    }
    % horizontal
    \foreach \x in {0,...,7} {
      \foreach \y in {0,...,4} {
        \draw[<-,shorten >=2pt,shorten >=7pt] (g-\x-\y) -- +(20pt,0);
      }
    }
    % diagonal
    \foreach \x in {1,...,8} {
      \foreach \y in {0,...,3} {
        \draw[->] (\x-.3,\y+.3) -- (\x - .6, \y+.6);
      }
    }
    \end{tikzpicture}
\caption{Triangularize}
\label{fig:triangularize1}
\end{figure}

在这种情况下生成的图像是(但实际上我不需要水平箭头):

在此处输入图片描述

答案1

我可能理解得过于字面化了。

\documentclass{article} 
\usepackage{emerald,tikz}
\usepackage[T1]{fontenc}

\usetikzlibrary{calc,decorations.pathmorphing,fit}

\makeatletter

\pgfdeclaredecoration{penciline}{initial}{
    \state{initial}[width=+\pgfdecoratedinputsegmentremainingdistance,auto corner on length=1mm,]{
        \pgfpathcurveto%
        {% From
            \pgfqpoint{\pgfdecoratedinputsegmentremainingdistance}
                            {\pgfdecorationsegmentamplitude}
        }
        {%  Control 1
        \pgfmathparse{0.1*rand}
        \pgfpointadd{\pgfqpoint{\pgfdecoratedinputsegmentremainingdistance}{0pt}}
                        {\pgfqpoint{-\pgfdecorationsegmentaspect\pgfdecoratedinputsegmentremainingdistance}%
                                        {\pgfmathresult\pgfdecorationsegmentamplitude}
                        }
        }
        {%TO 
        \pgfpointadd{\pgfpointdecoratedinputsegmentlast}{\pgfpoint{1pt}{1pt}}
        }
    }
    \state{final}{}
}
\makeatother


\begin{document}\ECFTallPaul

\begin{tikzpicture}
[zeros/.style={},scale=0.8,transform shape,
xes/.style={outer sep=1.5pt,decoration=penciline,decorate}]
\foreach \y in {1,...,4}{
    \foreach \x in {1,...,5}{
    \ifnum\x>\numexpr\y+1
    \node[zeros] (mynode-\x-\y) at (\y,-\x) {0};
    \else
    \pgfmathparse{\y-\x<1?"draw":""}
    \node[xes,\pgfmathresult](mynode-\x-\y) at (\y,-\x) {X};
    \ifnum\x<5
    \ifnum\x<\y\draw[<-,xes] (mynode-\x-\y) -- +(0,-0.7);\fi 
    \ifnum\x=\y\draw[<-,xes] (mynode-\x-\y) -- +(0,-0.7);\fi
    \ifnum\y<4\draw[<-,xes] (mynode-\x-\y) -- +(0.7,-0.7);\fi
    \fi
    \fi
    }
}
\node[fit=(mynode-1-1)(mynode-5-4),draw,thick,xes,red,label=90:{\Large dependencies}] {};

\begin{scope}[xshift=4.7cm]
    \foreach \x[remember=\x as \lastx] in {1,...,5}{
        \node (myvecs1-\x) at (0,-\x) {X};
        \node (myvecs2-\x) at (1,-\x) {X};
        \node (myvecsn-\x) at (5,-\x) {X};
        \ifnum\x>1
        \draw[->,xes] (myvecs1-\x) -- (myvecs1-\lastx);
        \draw[->,xes] (myvecs2-\x) -- (myvecs2-\lastx);
        \draw[->,xes] (myvecsn-\x) -- (myvecsn-\lastx);
        \fi
        }
\node[fit=(myvecs1-1)(myvecsn-5),draw,thick,xes,green!50!blue,label=90:{\Large Free of diagonal dep.}] {};
\end{scope}
\end{tikzpicture}


\end{document}

在此处输入图片描述

大部分是从

模拟手绘线条

TikZ 在矩阵中标记几个块

对于字体

CTAN 字体目录

相关内容