在另一个主题中(基本几何形状、截面、阴影),我迟迟没有搞清楚如何正确定位事物。接下来的内容显然是错误的,表明我几乎完全错过了机会。好吧,把最后一句中的“几乎”划掉。应该如何做才正确?
目标是简单地水平放置圆形、正方形和药丸,使圆形和正方形的总和等于药丸。我遗漏了一些有关节点的信息,假设这就是我应该做的。
感谢 Gonzalo 提供的原始代码!
\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}
答案1
这是一种可能性奎伯比尔贝尔的excellent answer
到基本几何形状、截面、阴影:
\documentclass{article}
\usepackage{etoolbox}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{calc,shapes.misc}
\makeatletter
\def\qrr@ppbb{path picture bounding box}
\tikzset{
divide/.style={%
/utils/exec=%
\let\qrr@pathpicture\pgfutil@empty
\pgfutil@tempcnta\z@ % rows
\pgfutil@tempcntb\z@,% cols
/tikz/@divide rows/.list={#1},
path picture/.expand once=\qrr@pathpicture
},
@divide rows/.style={%
/utils/exec=\pgfutil@tempcntb\z@,
@divide cols/.list={#1},
/utils/exec=\advance\pgfutil@tempcnta\@ne
},
@divide cols/.code=
\let\pgf@tempb\pgfutil@empty
\let\pgf@tempc\pgfutil@empty
\pgfutil@in@{:}{#1}%
\ifpgfutil@in@
\pgfkeysalso{@divide cols split={#1}}%
\else
\def\pgf@tempa{#1}%
\fi
\eappto\qrr@pathpicture{%
\noexpand\path
($(\[email protected] west)!\the\pgfutil@tempcntb/\noexpand\the\pgfutil@tempcntb!(\[email protected] east)$)
coordinate (qrr@pp@tl)
($(\[email protected] west)!\number\numexpr\pgfutil@tempcntb+\@ne\relax/\noexpand\the\pgfutil@tempcntb!(\[email protected] east)$)
coordinate (qrr@pp@tr)
($(\[email protected] west)!\the\pgfutil@tempcnta/\noexpand\the\pgfutil@tempcnta!(\[email protected] west)$)
coordinate (qrr@pp@lt)
($(\[email protected] west)!\number\numexpr\pgfutil@tempcnta+\@ne\relax/\noexpand\the\pgfutil@tempcnta!(\[email protected] west)$)
coordinate (qrr@pp@bl);
\noexpand\path[
every divide/.try,
every divide \the\pgfutil@tempcntb\space row/.try,
every divide \the\pgfutil@tempcnta\space column/.try,
every divide \the\pgfutil@tempcntb-\the\pgfutil@tempcntb\space cell/.try,
\pgf@tempa,
every divide later/.try,
every divide \the\pgfutil@tempcntb\space row later/.try,
every divide \the\pgfutil@tempcnta\space column later/.try,
every divide \the\pgfutil@tempcntb-\the\pgfutil@tempcntb\space cell later/.try,
midway
] (qrr@pp@tl |- qrr@pp@lt)
coordinate (cell-\the\pgfutil@tempcntb-\the\pgfutil@tempcnta-tl)
rectangle (qrr@pp@tr |- qrr@pp@bl)
coordinate (cell-\the\pgfutil@tempcntb-\the\pgfutil@tempcnta-br)
\ifx\pgf@tempc\pgfutil@empty\else
node[
every divide node/.try,
every divide \the\pgfutil@tempcntb\space row node/.try,
every divide \the\pgfutil@tempcnta\space column node/.try,
every divide \the\pgfutil@tempcntb-\the\pgfutil@tempcntb\space cell node/.try,
\expandafter\unexpanded\expandafter{\pgf@tempb}] {\expandafter\unexpanded\expandafter{\pgf@tempc}}
\fi
;
}%
\advance\pgfutil@tempcntb\@ne,
@divide cols split/.code args={#1:#2}{
\def\pgf@tempa{#1}%
\pgfutil@ifnextchar[\qrr@divide@splitopt{\qrr@divide@splitopt[]}#2\@qrr@divide@splitopt
}
}
\def\qrr@divide@splitopt[#1]#2\@qrr@divide@splitopt{\def\pgf@tempb{#1}\def\pgf@tempc{#2}}
\makeatother
\tikzset{every divide node/.style={midway,text=black}}
\begin{document}
Consider the joining of a circle and square partitioned into four equal sections and labeled $\frac{1}{4}$, as given below.
\[
\begin{tikzpicture}
\draw[every divide/.style={fill},,every divide later/.style={draw=black}] (0,0) rectangle (2,2) [divide={{white,gray:$\frac{1}{4}$},{white,white}}];
\draw[every divide/.style={fill},every divide later/.style={draw=black}]
(4,1) circle [radius=1] [divide={{white,gray:$\frac{1}{4}$},{white,white}}];
\node[draw,rounded rectangle,minimum size=4cm,minimum height=2cm,
divide={{draw,draw=gray!75!black,{fill=gray,draw=gray!75!black},{draw,fill=gray}},{draw,,draw=gray!75!black,draw}}
] (n) at (8,1) {};
\node[yshift=-0.5cm,xshift=1cm] at (n.north) {$\frac{1}{4}$};
\node at (2.5,1) {$+$};
\node at (5.5,1) {$=$};
\end{tikzpicture}
\]
As the picture suggests, somehow $\frac{1}{4} + \frac{1}{4} = \frac{1}{4}$.
\end{document}