如何在表中定位箭头?

如何在表中定位箭头?

我正在尝试制作一个影响矩阵。在此处输入图片描述如图所示,我想要一个从“影响”指向右侧的红色箭头。我想要一个位于旋转文本“可能性”右侧的蓝色箭头。这可能吗?到目前为止,我得到的结果如图所示。如果可能的话,我们将不胜感激。我的代码如下

\documentclass{article}
\usepackage{booktabs}

\usepackage[svgnames,table]{xcolor} % Required to specify font color
\setlength{\arrayrulewidth}{0.5mm}
\setlength{\tabcolsep}{3pt}
\renewcommand{\arraystretch}{1.2}
\usepackage{boldline, multirow}
\usepackage{graphicx}% http://ctan.org/pkg/graphicx

\usepackage{tikz}
\usetikzlibrary{tikzmark}
\usepackage{tikz-3dplot}
%#################

\begin{document}
\begin{table}[ht]
\setlength{\tabcolsep}{2pt} % for the horizontal padding
\renewcommand{\arraystretch}{2}% for the vertical padding
\begin{tabular}[H]{p{1cm}| p{1.2cm}| p{1cm}| p{1.2cm}| p{1.2cm}| p{1.2cm}| p{2.4cm}|}
\cline{2-7}
\multirow{7}{*}{\rotatebox[origin=c]{90}{Likelihood}} &\cellcolor{green} \scriptsize High\tikzmarknode{A} &\cellcolor{green} &\cellcolor{yellow} &\cellcolor{orange} &\cellcolor{red} & \scriptsize  Take Acition\\
\cline{2-7}
 &\cellcolor{green} \scriptsize  Medium &\cellcolor{green} &\cellcolor{yellow} &\cellcolor{orange} &\cellcolor{orange} & \scriptsize  Be Prepared\\
\cline{2-7}
 &\cellcolor{green} \scriptsize  Low &\cellcolor{green} &\cellcolor{green} &\cellcolor{yellow} &\cellcolor{orange} & \scriptsize  Be Aware\\
\cline{2-7}
 &\cellcolor{green} \scriptsize  \tikzmarknode{B}Very Low &\cellcolor{green} &\cellcolor{green} &\cellcolor{yellow} &\cellcolor{yellow} & \scriptsize  No Severe Weather\\
\cline{2-7}
 & \multicolumn{6}{l}{Impacts}\\
 & \multicolumn{2}{l}{\scriptsize Very Low/Minimal\tikzmarknode{D}} & \scriptsize  Low/Min0r & \scriptsize Moderate/Significant & \scriptsize  high/Severe\tikzmarknode{C} &\\
\end{tabular}
\tikz[remember picture,overlay]
{\draw[<-, blue, thick, >=stealth] ($(A.south)+(14pt,0pt)$) -- (B);
\draw[<-, red, thick, >=stealth] ($(C.east)+(6pt,0pt)$) -- (D);}
\end{table}
\end{document}

答案1

嗯,我猜你的意图可能是得到如下结果:

在此处输入图片描述

(表格设计符合我的口味

答案2

这是一个解决方案{NiceTabular}nicematrix以及 Zarko 建议的设计)。

\documentclass{article}
\usepackage{nicematrix}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}

\begin{document}

\begin{table}
\footnotesize
\renewcommand{\arraystretch}{1.6}
\NiceMatrixOptions{cell-space-limits=3pt}

\begin{NiceTabular}[hvlines,corners = {SW,SE}]{l*{4}{X[c]}l}
\CodeBefore
   \columncolor{green!30}{1}
   \cellcolor{green!30}{1-2,2-2,3-2,4-2,3-3,4-3}
   \cellcolor{yellow!30}{1-3,2-3,2-4,3-4}
   \cellcolor{orange!30}{1-4,2-4,2-5,3-5}
   \cellcolor{red!30}{1-5}
\Body
  High        &   &   &   &   &   Take action         \\
  Medium      &   &   &   &   &   Be Prepared         \\
  Low         &   &   &   &   &   Be Aware            \\
  Very Low    &   &   &   &   &   No Severe Weather   \\
              & \Block{}{Very Low/\\ Minimal}
                  & \Block{}{Low/\\ Minor}
                      & \Block{}{Moderate/\\ Significant}
                          & \Block{}{high/\\ Severe} \\
\CodeAfter
  \begin{tikzpicture}
  \draw [->] ([xshift=-3mm]5-|1) to node [above,sloped] {\large Likelyhood} ([xshift=-3mm]1-|1) ;  
  \draw [->] ([yshift=-3mm]6-|2) to node [below] {\large Impact} ([yshift=-3mm]6-|6) ; 
  \end{tikzpicture}
\end{NiceTabular}

\end{table}

\end{document}

上述代码的输出

答案3

如果我理解正确的话,你可能希望它更像这个截图,是吗?

结果

以下是关于我的代码的几点说明:

  • 我标记了你的 tikzmarked 节点,以便% <<<更好地找到它们;这些行可能包含或不包含进一步的更改
  • 这些 tikzmark 似乎比较棘手,可能需要进行 2 次编译
  • 关键是最后一部分:
\tikz[remember picture,overlay, >=stealth]
{
%   \draw[<-, blue, thick] ($(A.south)+(14pt,0pt)$) -- (B);
%   \draw[<-, red, thick, >=stealth] ($(C.east)+(6pt,0pt)$) -- (D);
    \draw[->,red] (E) ++(3mm, 3pt) -- +(7,0);
    \draw[->,blue] (B) ++(-6mm,-1cm) -- +(0,4);
}

关键步骤:

  • 在“影响”之后立即引入另一个节点E(在表格部分)
  • 对于红线:从 开始(E),计算新位置++(3mm, 3pt)并向右相对移动,例如-- +(7,0)
  • 蓝线类似,使(A)过时(请注意:A现在B是之前高的非常(即他们的左边)
  • 将通用格式移至>=stealth开头

最后,我想知道,如果采用 100% tikz 方法,而不是将 tikz 与表格混合,效果是否会更好。

\documentclass{article}
\usepackage{booktabs}

\usepackage[svgnames,table]{xcolor} % Required to specify font color
\setlength{\arrayrulewidth}{0.5mm}
\setlength{\tabcolsep}{3pt}
\renewcommand{\arraystretch}{1.2}
\usepackage{boldline, multirow}
%\usepackage{graphicx}% http://ctan.org/pkg/graphicx% not needed here
%
\usepackage{tikz}
\usetikzlibrary{tikzmark}
%\usepackage{tikz-3dplot}% not needed here
%#################

\begin{document}
\begin{table}[ht]
\setlength{\tabcolsep}{2pt} % for the horizontal padding
\renewcommand{\arraystretch}{2}% for the vertical padding
    \begin{tabular}[H]{p{1cm}| p{1.2cm}| p{1cm}| p{1.2cm}| p{1.2cm}| p{1.2cm}| p{2.4cm}|}
        \cline{2-7}
        \multirow{7}{*}{\rotatebox[origin=c]{90}{Likelihood}}% <<<
        &\cellcolor{green}\scriptsize\tikzmarknode{A} High% <<<
        &\cellcolor{green} 
        &\cellcolor{yellow} 
        &\cellcolor{orange} 
        &\cellcolor{red} 
        & \scriptsize  Take Acition\\
        \cline{2-7}
        &\cellcolor{green} \scriptsize  Medium 
        &\cellcolor{green} 
        &\cellcolor{yellow} 
        &\cellcolor{orange} 
        &\cellcolor{orange}
        & \scriptsize  Be Prepared\\
        \cline{2-7}
        &\cellcolor{green} \scriptsize  Low 
        &\cellcolor{green} 
        &\cellcolor{green} 
        &\cellcolor{yellow} 
        &\cellcolor{orange} 
        & \scriptsize  Be Aware\\
        \cline{2-7}
        &\cellcolor{green}\scriptsize\tikzmarknode{B}Very Low% <<<
        &\cellcolor{green} 
        &\cellcolor{green} 
        &\cellcolor{yellow} 
        &\cellcolor{yellow} 
        & \scriptsize  No Severe Weather\\
        \cline{2-7}
        & \multicolumn{6}{l}{Impacts\tikzmarknode{E}}\\% <<<
        & \multicolumn{2}{l}{\scriptsize Very Low/Minimal\tikzmarknode{D}}% <<<
        & \scriptsize  Low/Minor 
        & \scriptsize Moderate/Significant 
        & \scriptsize  high/Severe\tikzmarknode{C} % <<<
        &\\
    \end{tabular}
\tikz[remember picture,overlay, >=stealth]
{
%   \draw[<-, blue, thick] ($(A.south)+(14pt,0pt)$) -- (B);
%   \draw[<-, red, thick, >=stealth] ($(C.east)+(6pt,0pt)$) -- (D);
    \draw[->,red] (E) ++(3mm, 3pt) -- +(7,0);
    \draw[->,blue] (B) ++(-6mm,-1cm) -- +(0,4);
}
\end{table}
\end{document}

相关内容