3

I want to put arrows beside a table. Here is my current code:

\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}

with this result

enter image description here Somehow, it works, however, the arrows are not scaled well in their size and are not starting at the lower left edge and ending with the shape of the tabular. I have the same scaling problem with the smaller diagram on the left, where the arrows are not getting scaled in the right way.

How can I improve this sketch?

TobWat
  • 33

1 Answers1

3

With tikz (as suggested @ 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}

enter image description here

I didn't figured out where should be "small diagram` and what is its size. So probably it shell be changed.

Zarko
  • 296,517