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}
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}
minimum width=<length>
works. Or do you want to accomplish something different?\strut
may help. Aminimum width=
as a style may also solve the problem.