I suggest to use a matrix of nodes
from the tikz matrix library.
A small example using the style devloped in the other topic:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\tikzstyle{ball} = [circle, shading=ball,
ball color=black!80!white, minimum size=1cm]
\begin{tikzpicture}
\matrix (m) [matrix of nodes,nodes=ball] {
{} & & {} & & {} & & {} & \\
& {} & & {} & & {} & & {} \\
{} & & {} & & {} & & {} & \\};
\end{tikzpicture}
\end{document}
Output:
The answer is surprisingly simple. It transpires that the \foreach
command can't come at arbitrary places in a path command. My guess, based on experiment, would be that it can only come when TikZ is looking for the next type of path, namely just after a coordinate. Once TikZ knows the type of path, it goes into a different mode where it looks just for those things it knows can be part of that path.
As a simpler example, try:
\draw (0,0) -- \foreach \a in {0,1,...,10} {(\a,0) -- (\a,1) -- } (11,0);
Here, TikZ is looking for a coordinate when it encounters the \foreach
, so it complains. The simplest solution is to switch things around a little to ensure that the \foreach
comes when TikZ is expecting it. In the baby example, this would be:
\draw (0,0) \foreach \a in {0,1,...,10} { -- (\a,0) -- (\a,1) } -- (11,0);
To a human, these are the same, but the second compiles (and gives a nice sawtooth wave) because TikZ encounters the \foreach
when it is able to cope with it.
In your example, you would have:
\pgfmathsetmacro{\in}{#1}
\pgfmathsetmacro{\out}{#2}
\pgfmathsetmacro{\intop}{2*\in - 4}
\pgfmathsetmacro{\intopp}{2*\in - 2}
% Connected piece
\draw
(0,0) \foreach \a in {0,2,...,\intop}{
.. controls (-0.25,\a) and (-0.25,\a+1) .. (0,\a+1) ..
controls (0.5,\a+1) and (0.5,\a+2) .. (0,\a+2)
} .. controls (-0.25,\intopp) and (-0.25,\intopp+1) ..
(0,\intopp+1);
So I've shifted the first ..
inside the \foreach
, and the last ..
that was inside the loop outside again. This now works.
This answer was sponsored by the Answers to Packages team, suppliers of cobordisms for quality TQFTs.
Best Answer
You can use a
\foreach
loop that takes the number of positions in each row as the loop list. For the standard chinese checkers boards, that could look like\foreach \m [count=\count] in {1,...,4,13,12,...,9,10,11,...,13,4,3,...,1}
.If you systematically name the nodes you create in this loop, you've got a very nice framework for drawing Chinese Checkers setups and moves. I've written a couple of macros and styles for this.
The command
\checkerboard[checkerboard labels]
will draw a blank board with the fields labeled<row>-<column>
:You can then place pieces using
\placepieces[<colour>]{<comma separated list of positions>}
and show moves using
For example,
Here's the full code: