我怎样才能并排绘制 2 个 tikz 矩形网格

我怎样才能并排绘制 2 个 tikz 矩形网格

这是我的 MWE。我有以下设置。我想在 X 旁边放置一个矩形网格(与 X 大小相同),在 W 的左侧放置另一个矩形网格(与 X 大小相同)。

基本上。我正在做 Q o X = Q o (WH)(o 是哈达玛积)

\documentclass{standalone}
\usepackage[T1]{fontenc} 
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\begin{document}    
    \begin{tikzpicture}
        
        % % % % % Rectangle  
        \draw (.999,-7.5) grid[step=0.5] (3.5,-12.5); % X
     
        \draw (4.499,-7.5) grid[step=0.5] (5.5,-12.5);
        \draw (6.499,-7.5) grid[step=0.5] (9,-8.5);
        \node at (2.25,-7) {$X$};
        \node at (5,-7) {$W$};
        \node at (7.25,-7) {$H$};
        \node at (4,-8) {$\approx$};
        \node at (6,-8) {$\times$};
        \node at (2.25,-13) {Mesures};
            \node at (5,-13) {Scène};
            \node at (7.75,-9) {Paramètres};
        
        \node (calibration_rect1) at (0,-5){};
        \node (calibration_rect2) at (10,-13.5){};
        
        \draw[line width=2pt,rounded corners=1cm] (calibration_rect1) rectangle (calibration_rect2);
         
    \end{tikzpicture}
\end{document}

在此处输入图片描述

最后我想要一个像这样的布局

在此处输入图片描述

答案1

也许是这样的? 在此处输入图片描述

我不确定尺寸是否正确,但由于我\pic为矩阵做了一个,所以很容易修改。您可以根据需要更改尺寸或位置。这是我的代码:

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

\tikzset
{%
  pics/matrix/.style n args={5}{% rows, columns, text above, text below, text left (or symbol)
    code={%
      \begin{scope}[y=-1cm,scale=0.5]
        \draw    (0,0) grid (#2,#1);
        \node at (0.5*#2,-0.5)   {#3};
        \node at (0.5*#2,#1+0.5) {#4};
        \node at (-0.5,0.5*#1)   {#5};
      \end{scope}     
    }},
}

\begin{document}
\begin{tikzpicture}[line cap=round,line join=round]
  \pic at (0,0)    {matrix={10}{5}{$Q$}{}          {}};
  \pic at (3,0)    {matrix={10}{5}{$X$}{}          {$\circ$}};
  \pic at (6,0)    {matrix={10}{5}{$Q$}{Mesures}   {$\approx$}};
  \pic at (9,0)    {matrix={10}{2}{$W$}{Scène}     {$\circ$}};
  \pic at (10.5,0) {matrix= {2}{5}{$H$}{Parameters}{$\times$}};
\end{tikzpicture}
\end{document}

更新:根据要求添加几个括号。为此,我需要在矩阵右侧添加另一个节点(以及 的另一个参数\pic)。

修改后的代码:

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

\tikzset
{%
  pics/matrix/.style n args={6}{% rows, columns, text above, text below,
                                % text left, text right (or symbols)
    code={%
      \begin{scope}[y=-1cm,scale=0.5]
        \draw    (0,0) grid (#2,#1);
        \node at (0.5*#2,-0.5)   {#3};
        \node at (0.5*#2,#1+0.5) {#4};
        \node at (-0.5,0.5*#1)   {#5};
        \node at (#2+0.5,0.5*#1) {#6};
      \end{scope}     
    }},
}

\begin{document}
\begin{tikzpicture}[line cap=round,line join=round]
  \pic at (0,0)   {matrix={10}{5}{$Q$}{}          {}{}};
  \pic at (3,0)   {matrix={10}{5}{$X$}{}          {$\circ$}{}};
  \pic at (6,0)   {matrix={10}{5}{$Q$}{Mesures}   {$\approx$}{$\circ$}};
  \pic at (9.5,0) {matrix={10}{2}{$W$}{Scène}     {}{}};
  \pic at (11,0)  {matrix= {2}{5}{$H$}{Parameters}{$\times$}{}};
  % parentheses
  \filldraw  (9.25,0) to[out=260,in=100]  (9.25,-5) to [out=98,in=262] cycle;
  \filldraw (13.75,0) to[out=-80,in=80]  (13.75,-5) to [out=82,in=-82] cycle;
\end{tikzpicture}
\end{document}

新的输出: 在此处输入图片描述

笔记:当然,如果需要更多括号,最好再加一个\pic

相关内容