In another thread (Basic geometric shapes, sections, shading), I stalled figuring out how to position things properly. What follows is clearly wrong and indicative of almost completely missing the boat. OK, scratch the "almost" in that last sentence. How should one do this right?
The goal is to simply lay out the circle, the square and the pill horizontally where the sum of the circle and square equal the pill. I missing something about nodes, assuming that is what I should be doing.
ThanX to Gonzalo for the original code!
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{shapes,snakes}
\begin{document}
Consider the joining of a circle and square partitioned into four equal sections and labeled 1/4, as given below.
\\ \\
\newcommand\FillSquare[5]{%
\begin{tikzpicture}
\fill[#2] (0,0) rectangle +(0.5*#1,0.5*#1);
\fill[#3] (0.5*#1,0cm) rectangle +(0.5*#1,0.5*#1);
\fill[#4] (0,0.5*#1) rectangle +(0.5*#1,0.5*#1);
\fill[#5] (0.5*#1,0.5*#1) rectangle +(0.5*#1,0.5*#1);
\end{tikzpicture}%
}
\newcommand\MySquare[5]{%
\begin{tikzpicture}
\FillSquare{#1}{#2}{#3}{#4}{#5}
\draw (0,0) rectangle (-#1,#1);
\node [right, black] at (0,1) {+};
\draw (-#1,0.5*#1) -- +(#1,0);
\draw (-0.5*#1,0) -- +(0,#1);
\node [below right, white] at (-0.75,1.85) {$\frac{1}{4}$};
\end{tikzpicture}%
}
\newcommand\MyCircle[5]{%
\begin{tikzpicture}
\fill[#4] (0,0) arc[radius=0.5*#1,start angle=180,end angle=90] -- +(0,-0.5*#1) --cycle;
\fill[#5] (#1,0) arc[radius=0.5*#1,start angle=0,end angle=90] -- +(0,-0.5*#1) --cycle;
\fill[#3] (#1,0) arc[radius=0.5*#1,start angle=0,end angle=-90] -- +(0,0.5*#1) -- cycle;
\fill[#2] (0.5*#1,-0.5*#1) arc[radius=0.5*#1,start angle=-90,end angle=-180] -- +(0.5*#1,0) -- cycle;
\draw (0.5*#1,0) circle [radius=0.5*#1];
\node [below right, black] at (2,0.3) {=};
\draw (0,0) -- +(#1,0);
\draw (0.5*#1,-0.5*#1) -- +(0,#1);
\node [below right, white] at (1.2,0.8) {$\frac{1}{4}$};
\end{tikzpicture}%
}
\newcommand\Joined[9]{%
\begin{tikzpicture}
\fill[#2] (0,0) arc[radius=0.5*#1,start angle=270,end angle=180] -- +(1.5cm,0) --cycle;
\fill[#5] (-0.5*#1,0.5*#1) arc[radius=0.5*#1,start angle=180,end angle=90] -- +(0,-0.5*#1) --cycle;
\fill[#6] (1.5*#1,0.5*#1) arc[radius=0.5*#1,start angle=0,end angle=90] -- +(0,-0.5*#1) --cycle;
\fill[#9] (1.5*#1,0.5*#1) arc[radius=0.5*#1,start angle=0,end angle=-90] -- +(0,0.5*#1) -- cycle;
\FillSquare{#1}{#3}{#4}{#7}{#8}
\draw (0,0) -- +(-#1,0)
arc[radius=0.5*#1,start angle=270,end angle=90] -- +(#1,0)
arc[radius=0.5*#1,start angle=90,end angle=-90] -- cycle;
\draw (-1.5*#1,0.5*#1) -- +(2*#1,0);
\draw (-0.5*#1,0) -- +(0,#1);
\draw (-#1,0) -- +(0,#1);
\draw (0,0) -- +(0,#1);
\node [below right, white] at (-0.25,1.8) {$\frac{1}{4}$};
\end{tikzpicture}%
}
\MySquare{2cm}{white}{white}{white}{gray} \ \ \ \ \ \ \ \ \ \ \ \ \\
\MyCircle{2cm}{white}{white}{white}{gray} \Joined{2cm}{white}{white}{white}{white}{gray}{white}{gray}{white}\quad
\\ \\
As the picture suggests, somehow 1/4 + 1/4 = 1/4.\\
\end{document}

+and=in a node works of course but it would be better to use these three TikZ pictures in math mode (displayed!), then you also wouldn’t need to do dirty tricks with\and\\ \\. Thebaselineoption, e.g.baseline=-.5excould help here. (Or you could try the code from my answer from the linked question.;)) – Qrrbrbirlbel Jun 21 '13 at 00:57