Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I've got a graph with nodes and arcs between them. Then I added labels to the nodes.

My problem now: The labels are partially unreadable because the arcs disturb.

Do I have an opportunity to highlight the labels, that they are better readable. Like a background color or something like that? What is the common solution for this problem?

I tried to change the text color but this isn't enough to solve the problem.

Edit: example code!

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

In this example, you can barely read the "2". How can I emphasize the "1,2,3"-String to improve die readability!

Now dynamically:

\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}
share|improve this question
    
How about using fill=white? An MWE would be very helpful... –  rainer Nov 21 '13 at 14:39
    
I've edited my post to add example code! Thanks for your help! –  mrbela Nov 21 '13 at 14:57
1  
Sorry, Jake! Now you have a minimal example that should work! –  mrbela Nov 21 '13 at 15:58
1  
@user2438518: Thanks for editing, now it's a perfect MWE (minimal working example)! –  Jake Nov 21 '13 at 16:02
    
You're welcome! Now I'm waiting for an answer.. :) –  mrbela Nov 21 '13 at 16:29

1 Answer 1

up vote 5 down vote accepted

Insert the label on a node inside the segment line. Remove the label 1,2,3 from node (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}

enter image description here


Edit: Based on the edited post, you can make use of the same trick. Note: Fixed typo which prevented code from compiling

Load the backgrounds library with \usetikzlibrary{backgrounds}. Then define a style for the nodes with every label/.style={fill=white,rectangle,inner sep=2pt}. Finally, insert the segment lines connecting the nodes inside the background layer.

See the code with comments:

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

enter image description here

share|improve this answer
    
Hey Sigur! Thank you for your help!! I had to change my graph and now I've had to make it dynamically. I edited the MWE in my prior post! Could you help me once again?? That would be very nice!! thanks a lot! –  mrbela Nov 23 '13 at 4:57
1  
Thank you very much!!! –  mrbela Nov 24 '13 at 12:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.