我怎样才能将箭头放在桌子上?

我怎样才能将箭头放在桌子上?

我想在表格旁边放置箭头。这是我当前的代码:

\renewcommand{\arraystretch}{1.5}
\begin{table}[!h]
\centering
\begin{tabular}{|C{2.0cm}|C{2.0cm}|C{2.0cm}|C{2.0cm}|}
    \hline
    \tikzmark{m1}\cellcolor{gray!75}\ifthenelse{\boolean{zeige_lsg}}{}{\space} & \ifthenelse{\boolean{zeige_lsg}}{}{} & \ifthenelse{\boolean{zeige_lsg}}{}{} & \ifthenelse{\boolean{zeige_lsg}}{}{}\\
    \hline
    \cellcolor{gray!75}\ifthenelse{\boolean{zeige_lsg}}{}{} & \ifthenelse{\boolean{zeige_lsg}}
    {}{} &  \ifthenelse{\boolean{zeige_lsg}}
    {}{} & \ifthenelse{\boolean{zeige_lsg}}{}{}\\
    \hline
    \tikzmark{m2}\cellcolor{black}\ifthenelse{\boolean{zeige_lsg}}{}{} & \cellcolor{gray!75}\ifthenelse{\boolean{zeige_lsg}}{}{} & \cellcolor{gray!75}\ifthenelse{\boolean{zeige_lsg}}{}{} &
    \tikzmark{m3}\cellcolor{gray!75}\ifthenelse{\boolean{zeige_lsg}}{}{}\\
    \hline
\end{tabular}

% table
\begin{tikzpicture}[overlay, remember picture]
\node[yshift=0.5cm] (a) at (pic cs:m1) {\vphantom{h}};
\node[xshift=-1.45cm,yshift=-0.7cm] (a1) at (pic cs:m1) {$\boldsymbol{a}$};
\node[] (b) at (pic cs:m2) {\vphantom{g}}; 
\node[] (c) at (pic cs:m3) {\vphantom{i}};
\node[xshift=-4.7cm,yshift=-0.8cm] (c1) at (pic cs:m3) {$\boldsymbol{b}$};
\draw [<-, thick]([shift={(-1.2cm,0cm)}]a -| {pic cs:m1}) -- ([shift={(-1.2cm,0cm)}]b -| {pic cs:m2});
\draw [->, thick]([shift={(-0.5cm,-0.5cm)}]b -| {pic cs:m2}) -- ([shift={(1.2cm,-0.5cm)}]c -| {pic cs:m3});
\end{tikzpicture}
\end{table}
\renewcommand{\arraystretch}{1.0}

% small diagram
\begin{tikzpicture}
\node[] (a) at (0,0) {};
\node[] (b) at (-1,0) {1};
\node[] (c) at (0,-1) {1};
\node[] (d) at (-1,-1) {2};
\draw[->, thick] (b) -- (a);
\draw[->, thick] (d) -- (a);
\draw[->, thick] (c) -- (a);
\end{tikzpicture}

有此结果

在此处输入图片描述 不知何故,它起作用了,但是箭头的尺寸缩放得不太好,并且不是从左下角开始并以表格的形状结束。左边较小的图表也存在同样的缩放问题,箭头没有以正确的方式缩放。

我怎样才能改进这个草图?

答案1

(按照tikz@ leandriis 的建议):

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta, matrix, positioning, quotes}
\usepackage{bm}

\begin{document} 
    \begin{tikzpicture}[auto,
node distance = 5mm and 8mm,
every edge/.style = {draw, -{Straight Barb[angle=45:2pt 3]}, semithick}
                        ]
\matrix (m) [matrix of nodes,
             nodes in empty cells,
             nodes={draw, minimum height=8mm, minimum width=20mm,
                    anchor=center},
             column sep=-\pgflinewidth,
             row sep=-\pgflinewidth,
             column 1/.style = {nodes={fill=gray!30}},
             row 3/.style = {nodes={fill=green!30}},
             row 3 column 1/.style = {nodes={fill=black, text=white}},
             inner sep=0pt
         ]
{
    &   &   &   \\
    &   &   &   \\
    &   &   &   \\
};
\draw[->] ([xshift=-2mm] m.south west) to ["$\bm{a}$"  ] ([xshift=-2mm] m.north west);
\draw[->] ([yshift=-2mm] m.south west) to ["$\bm{b}$" '] ([yshift=-2mm] m.south east);
% small diagram
\node[below left=of m.north west] (a) {};
\coordinate[below=of a |- m, label=below:1] (b);
\coordinate[left=of b, label=below left:2] (c);
\coordinate[left=of a, label=left:1] (d);
\draw   (b) edge (a)
        (c) edge (a)
        (d) edge (a);
    \end{tikzpicture}
\end{document}

在此处输入图片描述

我不知道“小图表”应该放在哪里,以及它的尺寸是多少。所以它可能需要改变。

相关内容