强调图表中的标签

强调图表中的标签

我有一个包含节点和节点之间弧的图。然后我给节点添加了标签。

我现在的问题是:由于弧线干扰,标签部分无法读取。

我是否有机会突出显示标签,使其更易读。比如背景颜色或类似的东西?这个问题的常见解决方案是什么?

我尝试改变文本颜色,但这不足以解决问题。

编辑:示例代码!

\documentclass{article}
\usepackage{tikz}
\begin{document}
 \begin{tikzpicture}
    \tikzstyle{every node}=[draw,circle,fill=white,minimum size=18pt, inner sep=0pt]
    \def \x{2}
    \def \y{1.5}
    \draw (1 * \x, 0 * \y) node (leer) [draw=green, label=90:5] {$\emptyset$};
    \draw (1 * \x,-1 * \y) node (b) [draw=green, label=90:{1,2,3}] {b};
    \draw [->]  (leer) -- (b);
\end{tikzpicture}

\end{document}

在这个例子中,你几乎看不清“2”。我该如何强调“1,2,3”字符串以提高可读性!

现在动态地:

\documentclass{article}
\usepackage{tikz}
\newcount\incount
\def\tin#1#2{\incount=0\relax\edef\marshal{\noexpand\TIn#1@@;#2@@;}\marshal}
\def\TIn#1#2;#3#4;{%
  \ifx#1@%   
    \ifx#3@%
      \incount=\ifnum0>\incount-\fi\incount%
      \let\next=\relax%
    \else%
      \advance\incount by-1%
      \def\next{\TIn#1#2;#4;}%
    \fi%
  \else%
    \def\test##1#1##2##3?{\ifx##2*\else\advance\incount by1\fi}%
    \test#3#4;#1**?%
    \def\next{\TIn#2;#3#4;}%
  \fi%
  \next%      
}

\begin{document}

\begin{tikzpicture}
[declare function={nchoosek(\n,\k)=\n!/(\k!*(\n-\k)!);}, x=1.5cm,y=2.5cm,
NULL/.style={fill=green!30, label=90:{1,2,3,4,5}},
A/.style={fill=green!30, label=90:{1,3,4,5}},
B/.style={fill=green!30, label=90:{1,3,5}},
C/.style={fill=green!30, label=90:{1,2,4,5}},
D/.style={fill=red!30, label=90:{2,5}},
E/.style={fill=green!30, label=90:{1,3,5}},
]

\foreach \R [count=\y from 0, evaluate={\s=nchoosek(5,\y);}, remember=\R as \r] in {
   {NULL},
   {A,B,C,D,E}}
   \foreach \C [count=\x from 0] in \R {   
     \node [circle, draw, anchor=base, minimum width=1cm, minimum height=0.75cm, \C/.try]
       (\C) at (-\s/2+\x,-\y+1) {\C};       
      \foreach \c in \r {
        \tin{\c}{\C}
        \ifnum\incount=1
          \draw (\c.south) -- (\C.north);
        \fi
     }
  }
\end{tikzpicture}
\end{document}

答案1

1,2,3将标签插入到段线内的节点上。从节点上移除标签(b)

\documentclass{article}
\usepackage{tikz}
\begin{document}
 \begin{tikzpicture}
    \tikzstyle{every node}=[draw,circle,fill=white,minimum size=18pt, inner sep=0pt]
    \def \x{2}
    \def \y{1.75} %% edited here for better view
    \draw (1 * \x, 0 * \y) node (leer) [draw=green, label=90:5] {$\emptyset$};
    \draw (1 * \x,-1 * \y) node (b) [draw=green] {b};
    \draw [->]  (leer) --node[fill=white,draw=white,rectangle]{1,2,3} (b);
\end{tikzpicture}

\end{document}

在此处输入图片描述


编辑:根据编辑的帖子,您可以使用相同的技巧。 笔记:修复了导致代码无法编译的拼写错误

使用 加载backgrounds\usetikzlibrary{backgrounds}。然后使用 为节点定义样式every label/.style={fill=white,rectangle,inner sep=2pt}。最后,在背景层内插入连接节点的线段。

查看带注释的代码:

\begin{tikzpicture}[%
 every label/.style={fill=white,rectangle,inner sep=2pt},  %% here is new
 declare function={nchoosek(\n,\k)=\n!/(\k!*(\n-\k)!);},
 x=1.75cm,y=2.5cm,  %% changed x value for better view
NULL/.style={fill=green!30, label=90:{1,2,3,4,5}},
A/.style={fill=green!30, label=90:{1,3,4,5}},
B/.style={fill=green!30, label=90:{1,3,5}},
C/.style={fill=green!30, label=90:{1,2,4,5}},
D/.style={fill=red!30, label={90:{2,5}}},
E/.style={fill=green!30, label=90:{1,3,5}},
]

\foreach \R [count=\y from 0, evaluate={\s=nchoosek(5,\y);}, remember=\R as \r] in {
   {NULL},
   {A,B,C,D,E}}
   \foreach \C [count=\x from 0] in \R {   
     \node [circle, draw, anchor=base, minimum width=1cm, minimum height=0.75cm, \C/.try]
       (\C) at (-\s/2+\x,-\y+1) {\C};       
      \begin{pgfonlayer}{background}  %% here is new
      \foreach \c in \r {
        \in{\c}{\C}
        \ifnum\incount=1
          \draw (\c.south) -- (\C.north);
        \fi
     }
      \end{pgfonlayer}                %% here is new
  }
\end{tikzpicture}

在此处输入图片描述

相关内容