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.

Please which keys may I use to get the circles in the following two categories of the same size? minimum size and inner sep don't improve the output. Please, if needed, use any looping macro of your choice.

\begin{document}
\begin{tikzpicture}[scale=.8,auto=left,every node/.style={circle,thick}]
\foreach \x/\y in {a/{-1,-2},b/{1,-2},c/{2,-1},d/{2,1},e/{1,2},
  f/{-1,2},g/{-2,1},h/{-2,-1}}{
  \node (\x) at (\y) [fill=blue!20,draw=yellow] {\x};
}
\foreach \x/\y {a/b,b/c,c/d,d/e,e/f,f/g,g/h,h/a}{
  \draw [->] (\x)--(\y) node [midway,fill=red!20,draw=blue,] {\x--\y};
}
\end{tikzpicture}
\end{document}

enter image description here

share|improve this question
    
Should all circles have the same size or are there two sizes for the two categories? –  Heiko Oberdiek Sep 29 '12 at 2:50
    
For me minimum width=<length> works. Or do you want to accomplish something different? –  Qrrbrbirlbel Sep 29 '12 at 2:53
    
There's no solution as it obviously depends on the height and (in this case) more importantly the width of what's in the nodes. It the width is small, adding a \strut may help. A minimum width= as a style may also solve the problem. –  Marc van Dongen Sep 29 '12 at 4:17

2 Answers 2

up vote 6 down vote accepted

In the following examples I have replaced \foxloop (package ltxtools), because it causes an error message. Also I have increased the scaling factor to reduce overlappings.

The examples uses the loops two times. In the first loop the maximal box dimensions of the node contents are calculated. (Update: Missing \tempDimBox added for the nodes with \x--\y.)

\documentclass{article}
\usepackage{tikz}

\newdimen\tempDimWD
\newdimen\tempDimHT
\newdimen\tempDimDP
\newcommand*{\tempDimBox}[1]{%
  \begingroup
    \sbox0{\makebox[\tempDimWD]{#1}}%
    \ht0=\tempDimHT
    \dp0=\tempDimDP
    \usebox0 %
  \endgroup
}
\newcommand*{\tempDimMeasure}[3]{%
  \node at (0,0) {%
    \global\tempDimWD=0pt
    \global\tempDimHT=0pt
    \global\tempDimDP=0pt
    \foreach #1 in #2 {%
      \sbox0{#3}%
      \ifdim\wd0>\tempDimWD
        \global\tempDimWD=\wd0 %
      \fi
      \ifdim\ht0>\tempDimHT
        \global\tempDimHT=\ht0
      \fi
      \ifdim\dp0>\tempDimDP
        \global\tempDimDP=\dp0
      \fi
    }%
  };%
}

\begin{document}
\begin{tikzpicture}[
  % scale=.8,
  auto=left,
  every node/.style={circle,thick},
]
\def\yellowlist{%
  a/{-1,-2},b/{1,-2},c/{2,-1},d/{2,1},e/{1,2},f/{-1,2},g/{-2,1},h/{-2,-1}%
}
\def\bluelist{a/b,b/c,c/d,d/e,e/f,f/g,g/h,h/a}

\tempDimMeasure{\x/\y}{\yellowlist}{\x}%
\foreach \x/\y in \yellowlist {
   \node (\x) at (\y) [fill=blue!20,draw=yellow] {\tempDimBox{\x}};
}

\tempDimMeasure{\x/\y}{\bluelist}{\x--\y}
\foreach \x/\y in \bluelist {
  \draw [->] (\x) -- (\y) node [midway,fill=red!20,draw=blue,] {\tempDimBox{\x--\y}};
}
\end{tikzpicture}
\qquad
\begin{tikzpicture}[
  % scale=.8,
  scale=1.2,
  auto=left,
  every node/.style={circle,thick},
]
\def\yellowlist{%
  a/{-1,-2},b/{1,-2},c/{2,-1},d/{2,1},e/{1,2},f/{-1,2},g/{-2,1},h/{-2,-1}%
}
\def\bluelist{a/b,b/c,c/d,d/e,e/f,f/g,g/h,h/a}

%\tempDimMeasure{\x/\y}{\yellowlist}{\x}% Since we're looking for largest circle.
\tempDimMeasure{\x/\y}{\bluelist}{\x--\y}
\foreach \x/\y in \yellowlist {
   \node (\x) at (\y) [fill=blue!20,draw=yellow] {\tempDimBox{\x}};
}
\foreach \x/\y in \bluelist {
  \draw [->] (\x) -- (\y)
  node [midway,fill=red!20,draw=blue] {\tempDimBox{\x--\y}};
}
\end{tikzpicture}
\end{document}

Result

A variant, where the nodes a to h are on the vertices of a regular octagon.

\documentclass{article}
\usepackage{tikz}

\newdimen\tempDimWD
\newdimen\tempDimHT
\newdimen\tempDimDP
\newcommand*{\tempDimBox}[1]{%
  \begingroup
    \sbox0{\makebox[\tempDimWD]{#1}}%
    \ht0=\tempDimHT
    \dp0=\tempDimDP
    \usebox0 %
  \endgroup
}
\newcommand*{\tempDimMeasure}[3]{%
  \node at (0,0) {%
    \global\tempDimWD=0pt
    \global\tempDimHT=0pt
    \global\tempDimDP=0pt
    \foreach #1 in #2 {%
      \sbox0{#3}%
      \ifdim\wd0>\tempDimWD
        \global\tempDimWD=\wd0 %
      \fi
      \ifdim\ht0>\tempDimHT
        \global\tempDimHT=\ht0
      \fi
      \ifdim\dp0>\tempDimDP
        \global\tempDimDP=\dp0
      \fi
    }%
  };%
}

\begin{document}
\begin{tikzpicture}[
  % scale=.8,
  auto=left, 
  every node/.style={circle,thick},
]
\def\yellowlist{a,...,h}
\def\bluelist{a/b,b/c,c/d,d/e,e/f,f/g,g/h,h/a}

\tempDimMeasure{\x/\y}{\yellowlist}{\x}%
\foreach [count=\xi] \x in \yellowlist {
  \node (\x) at ({180+360/16+360/8*\xi:2})
  [fill=blue!20,draw=yellow] {\tempDimBox{\x}};
}

\tempDimMeasure{\x/\y}{\bluelist}{\x--\y}
\foreach \x/\y in \bluelist {
  \draw [->] (\x) -- (\y) node [midway,fill=red!20,draw=blue,] {\tempDimBox{\x--\y}};
}
\end{tikzpicture}
\qquad
\begin{tikzpicture}[
  % scale=.8,
  scale=1.2, 
  auto=left, 
  every node/.style={circle,thick},
]
\def\yellowlist{a,...,h}
\def\bluelist{a/b,b/c,c/d,d/e,e/f,f/g,g/h,h/a}

%\tempDimMeasure{\x/\y}{\yellowlist}{\x}% Since we're looking for largest circle.
\tempDimMeasure{\x/\y}{\bluelist}{\x--\y}
\foreach [count=\xi] \x/\y in \yellowlist {
  \node (\x) at ({180+360/16+360/8*\xi:2}) 
  [fill=blue!20,draw=yellow] {\tempDimBox{\x}};
}
\foreach \x/\y in \bluelist {
  \draw [->] (\x) -- (\y)
  node [midway,fill=red!20,draw=blue] {\tempDimBox{\x--\y}};
}
\end{tikzpicture}
\end{document}   

Result

share|improve this answer
    
Heiko solves Ahmed's problem. –  Marc van Dongen Sep 29 '12 at 4:51
    
@HeikoOberdiek: Many thanks. I see that circle (e-f) is smaller, or is it my screen or eyes that give me that impression? Master Heiko knows the macros in all CTAN packages.:). I defined \foxloop in more one place. I should correct that. Thanks. –  Ahmed Musa Sep 29 '12 at 16:13
    
@AhmedMusa I had forgotten to add \tempDimBox for the nodes with \x--\y. –  Heiko Oberdiek Sep 29 '12 at 16:31
    
@HeikoOberdiek: The best way I can ask this question is to edit your answer. Please let me know if I have done any harm there. –  Ahmed Musa Sep 29 '12 at 19:33
    
@AhmedMusa Yes, two \tempDimMeasuer after each other do not make sense, because the second resets the dimen registers at the beginning. And since all single letters of the smaller nodes \x are also contained in the larger nodes \x--\y, the line can just be dropped. –  Heiko Oberdiek Sep 29 '12 at 20:14

a solution which also uses two polygons

command \GrapheBoucle[0.8]{8}{a, b​​, c, d, e, f, g, h}{ab, bc, cd,, ef, fg, gh, ha}{4.5cm} generates two polygons are angularly offset

  • The first apex to the terms of the first list {a, b, c, d, e, f, g, h}, such summit are connected by arcs,
  • The second peaks correspond to the second list {ab, bc, cd,, ef, fg, gh, ha}
  • The radius of the circle passing through the vertices of the first polygon is specified by the last parameter {4.5cm}
  • The first parameter (optional) [0.8] is a draft ratio which is used to specify the radius of the second polygon with respect to the first.
  • The second parameter {8}, the number of vertices of polygons

\documentclass{article}

\usepackage{tikz}
enter code here
\usetikzlibrary{shapes,arrows,patterns,snakes,decorations,chains,fit}
\newcommand{\GrapheBoucle}[5][0.8]{
\node[regular polygon, regular polygon sides=#2, minimum size=#5,rotate=180](sommet) at (0,0) {};
\node[regular polygon, regular polygon sides=#2, minimum size={#5*#1},rotate={180+(180)/#2}](lien) at (0,0)  {};
\pgfmathparse{180/(#2+1)}
\foreach \i in {1,...,#2}{
\node (LGraphe\i) at (lien.corner \i){};
}
\begin{scope}[start chain=graphe placed {at=(sommet.corner \tikzchaincount)}, every join/.style={bend right=\pgfmathresult},->]
\foreach \i in {#3}{
\node [on chain,join, circle, draw,fill=blue!20,draw=yellow](NGraphe\tikzchaincount) {\i};
}
\end{scope}
\begin{scope}[start chain=noeud placed {at=(lien.corner \tikzchaincount)}, every join/.style={bend right=\pgfmathresult}]
\foreach \i in {#4}{
\node [on chain, circle, draw,fill=red!20,draw=blue](NGraphe\tikzchaincount) {\i};
}

\end{scope}
\draw (graphe-end) to[bend right={\pgfmathresult}] (graphe-begin);
}

\begin{document}

\begin{tikzpicture}
\GrapheBoucle[0.8]{8}{a,b,c,d,e,f,g,h}{a-b,b-c,c-d,d-e,e-f,f-g,g-h,h-a}{4.5cm}
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
sorry, my answer does not address the problem –  rpapa Sep 29 '12 at 10:14
    
Thanks for trying. –  Ahmed Musa Sep 29 '12 at 15:54

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.