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 am using the TikZ and tkz-berge packages to create a direct acyclic graph. I've pasted my code below. I would like the variable labels "variable1", "variable2", etc to have an outline around them and a white background so they are easy to read over the arrows. Is there a way to do this? ( I would like to keep LabelOut=true)

\documentclass[]{article}
\usepackage{tikz}
\usepackage{tikz,fullpage}
\usetikzlibrary{arrows,%
                petri,%
                topaths}%
\usepackage{tkz-berge}
\usepackage[position=top]{subfig}
\usepackage{verbatim}
\begin{document}
\begin{figure}
\centering
\subfloat[]{
\begin{tikzpicture}[scale=0.75,transform shape]
  \Vertex[x=2.221,y=2.379, LabelOut=true, Lpos=-90]{variable1}
  \Vertex[x=-1.786,y=-2.495, LabelOut=true, Lpos=-90]{variable2}
  \Vertex[x=-0.808,y=-0.482, LabelOut=true, Lpos=-90]{variable3}
  \Vertex[x=1.834,y=-5.724, LabelOut=true, Lpos=-90]{variable4}
  \Vertex[x=1.855,y=-1.202, LabelOut=true, Lpos=-90]{variable5}
  \Vertex[x=2.820,y=5.684, LabelOut=true, Lpos=-90]{variable6}
  \Vertex[x=-3.821,y=-0.308, LabelOut=true, Lpos=-90]{variable7}
  \Vertex[x=-1.800,y=-5.955, LabelOut=true, Lpos=-90]{variable8}
  \Vertex[x=-4.797,y=-4.289, LabelOut=true, Lpos=-90]{variable9}
  \Vertex[x=5.243,y=3.474, LabelOut=true, Lpos=-90]{variable10}
  \Vertex[x=4.377,y=-0.046, LabelOut=true, Lpos=-90]{variable11}
  \Vertex[x=1.025,y=-3.360, LabelOut=true, Lpos=-90]{variable12}
  \Vertex[x=-1.086,y=1.824, LabelOut=true, Lpos=-90]{variable13}
  \Vertex[x=1.200,y=0.993, LabelOut=true, Lpos=-90]{variable14}
\tikzstyle{LabelStyle}=[fill=blue,sloped]
\tikzstyle{EdgeStyle}=[post]
  \Edge[](variable3)(variable2)
  \Edge[](variable4)(variable2)
  \Edge[](variable4)(variable5)
  \Edge[](variable5)(variable2)
  \Edge[](variable5)(variable1)
  \Edge[](variable1)(variable14)
  \Edge[](variable6)(variable1)
  \Edge[](variable7)(variable2)
  \Edge[](variable7)(variable13)
  \Edge[](variable8)(variable2)
  \Edge[](variable9)(variable2)
  \Edge[](variable10)(variable1)
  \Edge[](variable11)(variable1)
  \Edge[](variable11)(variable5)
  \Edge[](variable12)(variable2)
  \Edge[](variable12)(variable5)
  \Edge[](variable13)(variable1)
  \Edge[](variable14)(variable3)

\end{tikzpicture}
}

\end{figure}
\end{document}
share|improve this question
    
Welcome to TeX.SX. A tip: If you indent lines by 4 spaces, then they're marked as a code sample. You can also highlight the code and click the "code" button ({}). –  Claudio Fiandrino Jul 23 '12 at 17:55

1 Answer 1

As, to be honest, I didn't feel like reading the tkz-berge manual, I threw together this example. The pgfonlayer is for drawing the edges in the background, thus behind the labels:

\documentclass{article}
\usepackage{tikz}

\pgfdeclarelayer{background}
\pgfsetlayers{background,main}

\newcommand{\Vertex}[2]% pos, name
{ \node[circle,draw,minimum width=0.5cm,inner sep=0] (#2) at (#1) {};
    \node[rounded corners=3pt,below,draw=black,fill=white,inner sep=1.5pt] at (#2.south) {\footnotesize#2};
}

\newcommand{\Edge}[2]%
{ \begin{pgfonlayer}{background}
        \draw (#1) -- (#2);
    \end{pgfonlayer}
}

\begin{document}

\begin{tikzpicture}
    \Vertex{2.221,2.379}{variable1}
    \Vertex{2.221,2.379}{variable1}
    \Vertex{-1.786,-2.495}{variable2}
    \Vertex{-0.808,-0.482}{variable3}
    \Vertex{1.834,-5.724}{variable4}
    \Vertex{1.855,-1.202}{variable5}
    \Vertex{2.820,5.684}{variable6}
    \Vertex{-3.821,-0.308}{variable7}
    \Vertex{-1.800,-5.955}{variable8}
    \Vertex{-4.797,-4.289}{variable9}
    \Vertex{5.243,3.474}{variable10}
    \Vertex{4.377,-0.046}{variable11}
    \Vertex{1.025,-3.360}{variable12}
    \Vertex{-1.086,1.824}{variable13}
    \Vertex{1.200,0.993}{variable14}
    \Edge{variable3}{variable2}
    \Edge{variable4}{variable2}
    \Edge{variable4}{variable5}
    \Edge{variable5}{variable2}
    \Edge{variable5}{variable1}
    \Edge{variable1}{variable14}
    \Edge{variable6}{variable1}
    \Edge{variable7}{variable2}
    \Edge{variable7}{variable13}
    \Edge{variable8}{variable2}
    \Edge{variable9}{variable2}
    \Edge{variable10}{variable1}
    \Edge{variable11}{variable1}
    \Edge{variable11}{variable5}
    \Edge{variable12}{variable2}
    \Edge{variable12}{variable5}
    \Edge{variable13}{variable1}
    \Edge{variable14}{variable3}
\end{tikzpicture}

\end{document}

enter image description here

share|improve this answer
    
Great, thank you very much! –  azaleah Jul 24 '12 at 16:19
    
No problemo, you're welcome. Sorry for not keeping LabelOut=true :) –  Tom Bombadil Jul 24 '12 at 16:40
    
not a problem ;) –  azaleah Jul 24 '12 at 18:07

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.