我改变了圆的半径,使它们变大了,但不确定如何改变它们之间的空间,因为它们重叠了。谢谢。
\documentclass[tikz, border=5]{standalone}
\newcount\segmentsleft
\tikzset{pics/.cd,
circle fraction/.style args={#1/#2}{code={%
\segmentsleft=#1\relax
\pgfmathloop
\ifnum\segmentsleft<1\else
\ifnum\segmentsleft<#2 \edef\n{\the\segmentsleft}\else\def\n{#2}\fi
\begin{scope}[shift={(\pgfmathcounter,0)}]
\foreach \i [evaluate={\a=360/#2*(\i-1)+90;}] in {1,...,\n}
\fill[fill=green] (0,0) -- (\a:1) arc (\a:\a+360/#2:1) -- cycle;
\draw circle [radius=1];
\ifnum#2>1
\foreach \i [evaluate={\a=360/#2*(\i-1);}] in {1,...,#2}
\draw (0,0) -- (90+\a:1);
\fi
\end{scope}
\advance\segmentsleft by-#2
\repeatpgfmathloop
}}
}
\begin{document}
\begin{tikzpicture}
\foreach \numerator/\denominator [count=\y]
in {1/1, 1/3, 2/4, 3/5, 8/8, 4/1, 10/3, 20/6, 30/7, 40/15}{
\node at (-1/2,-\y) {};
\pic at (0, -\y) {circle fraction={\numerator/\denominator}};
}
\end{tikzpicture}
\end{document}
上面的代码来自-在此处输入链接描述
答案1
我会将尺寸设为可配置的。例如,
\documentclass[border=5]{standalone}
\usepackage{tikz}
\newcount\segmentsleft
\tikzset{%
pics/circle fraction/.style args={#1/#2}{%
code={%
\segmentsleft=#1\relax
\pgfmathloop
\ifnum\segmentsleft<1
\else
\ifnum\segmentsleft<#2
\edef\n{\the\segmentsleft}
\else
\def\n{#2}
\fi
\begin{scope}[shift={(\pgfmathcounter*2*\circlefractionsize,0)}]
\foreach \i [evaluate={\a=360/#2*(\i-1)+90;}] in {1,...,\n}
\fill[fill=green] (0,0) -- (\a:\circlefractionsize) arc (\a:\a+360/#2:\circlefractionsize) -- cycle;
\draw circle [radius=\circlefractionsize];
\ifnum#2>1
\foreach \i [evaluate={\a=360/#2*(\i-1);}] in {1,...,#2}
\draw (0,0) -- (90+\a:\circlefractionsize);
\fi
\end{scope}
\advance\segmentsleft by-#2
\repeatpgfmathloop
}
},
circle fraction size/.store in=\circlefractionsize,
circle fraction size=1,
}
\begin{document}
\begin{tikzpicture}
\foreach \numerator/\denominator [count=\y,evaluate=\y as \s using (-2*\circlefractionsize*\y)]
in {1/1, 1/3, 2/4, 3/5, 8/8, 4/1, 10/3, 20/6, 30/7, 40/15}{
\node at (-1/2,\s) {};
\pic at (0,\s) {circle fraction={\numerator/\denominator}};
}
\end{tikzpicture}
\begin{tikzpicture}[circle fraction size=1.5]
\foreach \numerator/\denominator [count=\y,evaluate=\y as \s using (-2*\circlefractionsize*\y)]
in {1/1, 1/3, 2/4, 3/5, 8/8, 4/1, 10/3, 20/6, 30/7, 40/15}{
\node at (-1/2,\s) {};
\pic at (0,\s) {circle fraction={\numerator/\denominator}};
}
\end{tikzpicture}
\end{document}
我可能也不会pic
像这样设置代码,但这可能是个人喜好问题。我倾向于pic
以标准方式设置我的 s,这样它们就可以采用键值选项,并且是半隔离的,以避免冲突。例如,
\documentclass[border=5]{standalone}
\usepackage{tikz}
% ateb: https://tex.stackexchange.com/a/710293/ addaswyd o gwestiwn user292225: https://tex.stackexchange.com/q/710289/
\newcount\segmentsleft
\usetikzlibrary{fit}
\newcount\circlefracnum
\newcount\circlefracdenom
\tikzset{%
circle frac/.search also={/tikz,/pgf},
circle frac/.code={\tikzset{circle frac/.cd,#1,/tikz/.cd}},
circle frac/.cd,
back/.code={\colorlet{circle frac back}{#1}},
back=white,
draw/.code={\colorlet{circle frac draw}{#1}},
draw=black,
fill/.code={\colorlet{circle frac fill}{#1}},
fill=green,
frac/.code args={#1/#2}{%
\circlefracnum=#1
\circlefracdenom=#2
},
frac=1/2,
label/.store in=\circlefraclabel,
label=,
name/.store in=\circlefracname,
name=,
size/.store in=\circlefracsize,
size=1,
/tikz/.cd,
pics/circle frac/.style={%
code={%
\tikzset{circle frac/.cd, #1, /tikz/.cd}%
\begin{scope}[local bounding box/.expanded=\circlefracname]
\segmentsleft=\circlefracnum\relax
\pgfmathloop
\ifnum\segmentsleft<1
\else
\ifnum\segmentsleft<\circlefracdenom
\edef\n{\the\segmentsleft}
\else
\def\n{\circlefracdenom}
\fi
\begin{scope}[draw=circle frac draw,shift={(\pgfmathcounter*2*\circlefracsize,0)}]
\fill [circle frac back] circle [radius=\circlefracsize];
\foreach \i [evaluate={\a=360/\circlefracdenom*(\i-1)+90;}] in {1,...,\n}
\fill [fill=circle frac fill] (0,0) -- (\a:\circlefracsize) arc (\a:\a+360/\circlefracdenom:\circlefracsize) -- cycle;
\draw circle [radius=\circlefracsize];
\ifnum\circlefracdenom>1
\foreach \i [evaluate={\a=360/\circlefracdenom*(\i-1);}] in {1,...,\circlefracdenom}
\draw (0,0) -- (90+\a:\circlefracsize);
\fi
\end{scope}
\advance\segmentsleft by-\circlefracdenom
\repeatpgfmathloop
\end{scope}
\node (\circlefracname) [fit=(\circlefracname.north east) (\circlefracname.south west), label/.expanded=\circlefraclabel] {};
}%
},
}
\begin{document}
\begin{tikzpicture}
\foreach \numerator/\denominator [count=\y,evaluate=\y as \s using (-2*\circlefracsize*\y)]
in {1/1, 1/3, 2/4, 3/5, 8/8, 4/1, 10/3, 20/6, 30/7, 40/15}{
\node at (-1/2,\s) {};
\pic at (0,\s) {circle frac={frac=\numerator/\denominator}};
}
\end{tikzpicture}
\begin{tikzpicture}[circle frac={size=1.5}]
\foreach \numerator/\denominator [count=\y,evaluate=\y as \s using (-2*\circlefracsize*\y)]
in {1/1, 1/3, 2/4, 3/5, 8/8, 4/1, 10/3, 20/6, 30/7, 40/15}{
\node at (-1/2,\s) {};
\pic at (0,\s) {circle frac={frac=\numerator/\denominator}};
}
\end{tikzpicture}
\begin{tikzpicture}[circle frac={size=1.5}]
\foreach \numerator/\denominator/\col [count=\y,evaluate=\y as \s using (-2*\circlefracsize*\y)]
in {1/1/pink, 1/3/magenta, 2/4/red, 3/5/orange, 8/8/yellow, 4/1/green, 10/3/cyan, 20/6/blue, 30/7/purple, 40/15/gray}{
\node at (-1/2,\s) {};
\pic at (0,\s) {circle frac={frac=\numerator/\denominator,fill=\col,back=\col!5,name=row\y}};
\node [anchor=east,font=\sffamily,xshift=-20pt] at (row\y.west) {Row \y};
}
\end{tikzpicture}
\end{document}
当然,您可能想要更少、更多或与我在此处设置的切换按钮不同的切换按钮。一旦您掌握了基本结构,扩展模式就相当简单了。
答案2
要水平移动圆圈,请替换
\begin{scope}[shift={(\pgfmathcounter,0)}]
经过
\begin{scope}[shift={(2*\pgfmathcounter,0)}]
对于垂直距离,替换
\pic at (0, -\y) {circle fraction={\numerator/\denominator}};
经过
\pic at (0, -2*\y) {circle fraction={\numerator/\denominator}};
目前,该线
\node at (-1/2,-\y) {};
什么都不做(没有给出标签,没有绘制任何内容),但在这里你可能还需要
\node at (-1/2,-2*\y) {};
\documentclass[tikz, border=5]{standalone}
\newcount\segmentsleft
\tikzset{pics/.cd,
circle fraction/.style args={#1/#2}{code={%
\segmentsleft=#1\relax
\pgfmathloop
\ifnum\segmentsleft<1\else
\ifnum\segmentsleft<#2 \edef\n{\the\segmentsleft}\else\def\n{#2}\fi
\begin{scope}[shift={(2*\pgfmathcounter,0)}]
\foreach \i [evaluate={\a=360/#2*(\i-1)+90;}] in {1,...,\n}
\fill[fill=green] (0,0) -- (\a:1) arc (\a:\a+360/#2:1) -- cycle;
\draw circle [radius=1];
\ifnum#2>1
\foreach \i [evaluate={\a=360/#2*(\i-1);}] in {1,...,#2}
\draw (0,0) -- (90+\a:1);
\fi
\end{scope}
\advance\segmentsleft by-#2
\repeatpgfmathloop
}}
}
\begin{document}
\begin{tikzpicture}
\foreach \numerator/\denominator [count=\y]
in {1/1, 1/3, 2/4, 3/5, 8/8, 4/1, 10/3, 20/6, 30/7, 40/15}{
\node at (-1/2,-2*\y) {};
\pic at (0, -2*\y) {circle fraction={\numerator/\denominator}};
}
\end{tikzpicture}
\end{document}