Tikz - 节点突出显示/背景着色

Tikz - 节点突出显示/背景着色

这是 MWE,它可以保留 unicode 天城体文本。

\documentclass[fleqn,12pt,a4paper]{article}
\usepackage{tikz}
\usepackage{tabularx}
\usepackage{color}
\begin{document}

\newcounter{sbnodecount}
\newcommand\sbtabnode[1]{\addtocounter{sbnodecount}{1} \tikz \node (\arabic{sbnodecount}) {#1};}

\tikzstyle{every picture}+=[remember picture,baseline]
\tikzstyle{every node}+=[inner sep=0pt,anchor=base,
minimum width=1.8cm,align=center,text depth=.25ex,outer sep=1.5pt]
\tikzstyle{every path}+=[thick, rounded corners]

\begin{table}[!htb]
 \begin{center}
   \begin{tabular}{|c|c|c|c|c|}
   \hline
Class   & one & Two & Three \\
 \hline
I  & \sbtabnode{A ()}& \sbtabnode{B} & \sbtabnode{C} \\
II & \sbtabnode{D }& \sbtabnode{E} & \sbtabnode{F} \\
III  & \sbtabnode{G} & \sbtabnode{H } & \sbtabnode{I} \\ 
IV  & \sbtabnode{J} & \sbtabnode{K} & \sbtabnode{L} \\
V    & \sbtabnode{M}& \sbtabnode{N} & \sbtabnode{O } \\
VI  & \sbtabnode{P} & \sbtabnode{Q} & \sbtabnode{R}   \\
VII & \sbtabnode{S} & \sbtabnode{T} & \sbtabnode{U}  \\
VIII   & \sbtabnode{V)} & \sbtabnode{V} & \sbtabnode{X} \\
\hline
     \end{tabular}
      \caption{Alphabets}
%   \end{minipage}
\end{center}

\begin{tikzpicture}[overlay]
% Define the circle paths
\draw [blue](1.north west) -- (3.north east) -- (3.south east) -- (3.south west) -- (5.south east) -- (4.south west) -- cycle;
\draw [red] (7.north west) -- (8.north east) -- (6.north west) -- (6.north east) -- (21.south east) -- (19.south west)  -- cycle;
\draw [orange] (2.north west) -- (2.north east) -- (5.south east) -- (5.south west) -- cycle;
\draw [green] (22.north west) -- (22.north east) -- (22.south east) -- (22.south west) -- cycle;
\draw[black] (1.north west) -- (3.north east) -- (6.south east) -- (7.north east) -- (16.north east) -- (18.north east) -- (18.south east) -- (17.south east) -- (20.south east) -- (19.south west) -- cycle;
% Labels
\node [left=2cm,above=1cm,minimum width=0pt] at (3) (A) { Group A};
\draw[orange] [stealth-,out=5,in=180] (2) to (A);
\node [below=5cm,right=2cm,minimum width=0pt] at (3) (B) {Group B};
\draw[blue] [stealth-,out=0,in=180] (3) to (B);
\node [right=5cm,below=2cm,minimum width=0pt] at (21) (C) {Group C};
\draw[red] [stealth-,out=350,in=90] (21) to (C);
\node [left=5cm,below=2cm,minimum width=0pt] at (22) (D) {Group D};
\draw[green] [stealth-,out=-180,in=0] (22) to (D);

\node [below=5cm,right=2cm,minimum width=0pt] at (18) (E) {Group E};
\draw[black] [stealth-,out=0,in=180] (18) to (E);


\end{tikzpicture}

\end{table}
\end{document} 

在此处输入图片描述 对我来说效果还行。但是线条相互重叠会破坏突出显示的效果。是否可以将线条分开,以便可以清楚地看到突出显示的区域。由于这些线条都经过同一个节点,因此可能不容易分开。是否可以将一些线条的背景更改为浅色,而将一些线条显示边框线,以便可以清楚地看到差异。

我将衷心感谢您的帮助

答案1

我建议你拉长表格的行,并使用以下组合

  1. 调整标签的位置以尽量减少交叉
  2. 不同的线条样式
  3. 填充阴影
  4. 稍微调整线条的位置

下面是对此的说明,但也许有更优雅的方式,但这应该可以帮助您入门:

在此处输入图片描述

笔记:

  • 在每个节点上添加一个,\strut以确保每个节点的高度相同。

代码:

\documentclass[fleqn,12pt,a4paper]{article}
\usepackage{xcolor}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{tabularx}
\begin{document}

\newcounter{sbnodecount}
\newcommand\sbtabnode[1]{\addtocounter{sbnodecount}{1} \tikz \node (\arabic{sbnodecount}) {#1\strut};}

\tikzstyle{every picture}+=[remember picture,baseline]
\tikzstyle{every node}+=[inner sep=0pt,anchor=base,
minimum width=1.8cm,align=center,text depth=.25ex,outer sep=1.5pt]
\tikzstyle{every path}+=[thick, rounded corners]

\begin{table}[!htb]
\renewcommand{\arraystretch}{1.3}
    \begin{tabular}{|c|c c c|}
    \hline
Class   & one & Two & Three \\
 \hline
I  & \sbtabnode{A ()}& \sbtabnode{B} & \sbtabnode{C} \\[1.5pt]
II & \sbtabnode{D }& \sbtabnode{E} & \sbtabnode{F} \\
III  & \sbtabnode{G} & \sbtabnode{H } & \sbtabnode{I} \\ 
IV  & \sbtabnode{J} & \sbtabnode{K} & \sbtabnode{L} \\
V    & \sbtabnode{M}& \sbtabnode{N} & \sbtabnode{O } \\
VI  & \sbtabnode{P} & \sbtabnode{Q} & \sbtabnode{R}   \\
VII & \sbtabnode{S} & \sbtabnode{T} & \sbtabnode{U}  \\
VIII   & \sbtabnode{V)} & \sbtabnode{V} & \sbtabnode{X} \\
\hline
    \end{tabular}
    \caption{Alphabets}

\begin{tikzpicture}[overlay]
% Define the circle paths
\draw [blue]
    ($(1.north west)+(-2.5pt,0.5pt)$) -- ($(3.north east)+(2.5pt,0.5pt)$) -- 
    ($(3.south east)+(2.5pt,0)$) -- (3.south west) -- 
    (5.south east) -- ($(4.south west)+(-2.5pt,0)$) -- 
    cycle;
\draw [red, ultra thick, fill=red!10, fill opacity=0.2, dotted] 
    ($(7.north west)+(-2.5pt,3.0pt)$) -- ($(8.north east)+(0,3.0pt)$) -- 
    (6.north west) -- ($(6.north east)+(2.5pt,0)$) -- 
    ($(21.south east)+(2.5pt,-2.0pt)$) -- ($(19.south west)+(-2.5pt,-2.0pt)$)  -- 
    cycle;
\draw [orange] 
    ($(2.north west)+(0,-1.75pt)$) -- ($(2.north east)+(0,-1.75pt)$) -- 
    ($(5.south east)+(0,1.75pt)$) -- ($(5.south west)+(0,1.75pt)$) -- 
    cycle;
\draw [green] (22.north west) -- (22.north east) -- (22.south east) -- (22.south west) -- cycle;
\draw[black, fill=gray!50, fill opacity=0.3, dashed] 
    ($(1.north west)+(0,-0.75pt)$) -- ($(3.north east)+(0,-0.75pt)$) -- 
    ($(6.south east)+(0,-4.0pt)$) -- ($(4.south east)+(0,-4.0pt)$) -- 
    (16.north east) -- (18.north east) -- 
    (18.south east) -- (17.south east) -- 
    (20.south east) -- (19.south west) -- 
    cycle;
% Labels
\node [right=0.2cm,above=1cm,minimum width=0pt] at (3) (A) { Group A};
\draw[orange] [stealth-,out=5,in=180] (2) to (A);
\node [below=0.5cm,right=2cm,minimum width=0pt] at (3) (B) {Group B};
\draw[blue] [stealth-,out=0,in=180] ($(3.east)+(2.5pt,0)$) to (B);
\node [right=3cm,below=1cm,minimum width=0pt] at (21) (C) {Group C};
\draw[red] [stealth-,out=-50,in=180] ($(21.south east)+(2.5pt,0)$) to (C.west);
\node [left=5cm,below=2cm,minimum width=0pt] at (22) (D) {Group D};
\draw[green] [stealth-,out=-120,in=0] (22.south) to (D);

\node [below=0cm,right=2cm,minimum width=0pt] at (18) (E) {Group E};
\draw[black] [stealth-,out=0,in=180] (18) to (E);
\end{tikzpicture}
\end{table}
\end{document} 

相关内容