我怎样才能绘制具有三个空分数和它们之间的框的圆形扇形,如下图所示?
以下代码无法运行,且不等效。另外,我可以使用蒂克兹一次,而不是如下的三次。
\documentclass{article}
\usepackage{tikz,amsmath}
%=========================
% \draw circle
%==========================
\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=gray] (0,0) -- (\a:3/8) arc (\a:\a+360/#2:3/8) -- cycle;
\draw circle [radius=3/8];
\ifnum#2>1
\foreach \i [evaluate={\a=360/#2*(\i-1);}] in {1,...,#2}
\draw (0,0) -- (90+\a:3/8);
\fi
\end{scope}
\advance\segmentsleft by-#2
\repeatpgfmathloop
}}
}
%-------------------------------------------------------------------------------
%%
% empty box
%-----------------------------------------------------------------------------
\newcommand{\emptybox}[2][\textwidth]{%
\begingroup
\setlength{\fboxsep}{-\fboxrule}%
%\noindent\framebox[#1]{\rule{0pt}{#2}}%
\noindent\fbox{%
\parbox{\textwidth}{%
\noindent \colorbox{lightgray} {\framebox[#1]{\rule{0pt}{#2}}}
}}
\endgroup
}
%-------------------------------------------------------------------------------
% empty frac
%-------------------------------------------------------------------------------
\newcommand{\emptyfrac}[1][]{\tikz[baseline=-.6ex,#1]{
\noindent\fbox{%
\parbox{\textwidth}{%
\draw (0,0)--
node[above=1pt, fill=lightgray, minimum size=5mm]{}
node[below=1pt, fill=lightgray, minimum size=5mm]{}(.5,0);}}
}}
% \emptyfractwo
\newcommand{\emptyfractwo}[1][]{\tikz[baseline=-.6ex,#1]{
\noindent\fbox{%
\parbox{\textwidth}{%
\draw (0,0)--
% node[above=-6pt, fill=lightgray, minimum size=5mm]{}
node[above=-6pt, fill=lightgray, minimum size=5mm]{}(0,0);}}
}}
%-------------------------------------------------------------------------------------
% for empty circle
\newcommand{\emptycircle}{{
\noindent\fbox{%
\parbox{\textwidth}{%
\tikz \draw[line width=0.6pt] circle(4mm);}}
}}
%----------------------------------------------------------------------------------------------------------------------------------------
\begin{document}
%
\begin{tikzpicture}
\foreach \numerator/\denominator [count=\y] in {3/2}{
\node at (0,-1) {$\emptyfractwo \;\emptyfrac$}; % chnage using \emptyfrac
\pic at (-1.5, 0.3) {circle fraction={\numerator/\denominator}};
}
\end{tikzpicture}
%=========================
\hspace{1mm}
\begin{tikzpicture}
\node at (0,-1) {$ \emptycircle$};
% \node at (0,-1) {$\frac{\emptybox[5mm]{5mm}}{}$};
\end{tikzpicture}
\hspace{1mm}
%=========================
\begin{tikzpicture}
\foreach \numerator/\denominator [count=\y] in { 11/10}{
\node at (0,-1) {$ \emptyfractwo \;\emptyfrac$};
\pic at (-1.5, 0.3) {circle fraction={\numerator/\denominator}};
}
\end{tikzpicture}
%
\end{document}
答案1
修改代码关于矩形的解但使用圆形扇区:
上图的代码是\fraccirc{9}{12}\qquad\fraccirc[fill=blue!30]{3}{4}
。默认填充颜色是orange!70
,但您可以使用可选填充颜色进行调整。您还可以添加其他 tikz 选项,例如scale=
、rotate=
等。
以下是该宏的代码:
\newcommand{\fraccirc}[3][fill=orange!70]{\tikz[baseline, #1]{
\foreach \n in {1,...,#2}{\fill[draw=black, thick] (0,0)--({90-360/#3*(\n-1)}:1) arc ({90-360/#3*(\n-1)}:{90-360/#3*\n}:1)--cycle;}
\foreach \n in {#2,...,#3} {\draw[thick] (0,0)--({90-360/#3*(\n-1)}:1) arc ({90-360/#3*(\n-1)}:{90-360/#3*\n}:1)--cycle;}}}
您还可以制作额外的宏\wholecirc
,\emptybox
并\emptyframe
制作其余的图像
完整代码如下:
\documentclass{article}
\usepackage{tikz,amsmath}
\newcommand{\fracrect}[3][]{\tikz[baseline, #1]{
\foreach \n in {1,...,#2}{\draw[thick, fill=orange!70] ({(\n-1)/#3},0) rectangle (\n/#3,1);}
\foreach \n in {#2,...,#3} {\draw[thick] ({(\n-1)/#3},0) rectangle (\n/#3,1);}}}
\newcommand{\fraccirc}[3][fill=orange!70]{\tikz[baseline, #1]{
\foreach \n in {1,...,#2}{\fill[draw=black, thick] (0,0)--({90-360/#3*(\n-1)}:.75) arc ({90-360/#3*(\n-1)}:{90-360/#3*\n}:.75)--cycle;}
\foreach \n in {#2,...,#3} {\draw[thick] (0,0)--({90-360/#3*(\n-1)}:.75) arc ({90-360/#3*(\n-1)}:{90-360/#3*\n}:.75)--cycle;}}}
\newcommand{\wholecirc}[1][fill=orange!70]{\tikz[baseline, #1]{\fill[draw=black, thick] circle[radius=.75];}}
\newcommand{\emptyfrac}[1][]{\tikz[baseline=-.6ex,#1]{\draw (0,0)--
node[above=1pt, fill=brown!20, minimum size=5mm]{}
node[below=1pt, fill=brown!20, minimum size=5mm]{}(.5,0);}}
\newcommand{\emptybox}[1][]{\tikz[baseline=-.6ex, #1]{\node[fill=brown!20, minimum size=5mm]{}}}
\newcommand{\emptyframe}[1][]{\tikz[baseline=-.6ex, #1]{\node[draw=brown, thick, rounded corners, minimum size=5mm]{}}}
\begin{document}
\[
\wholecirc[fill=blue!30]\quad\wholecirc[fill=blue!30]\quad\fraccirc[fill=blue!30]{7}{8}\hspace{1cm}\wholecirc\quad\wholecirc\quad\fraccirc{5}{8}
\]
\[
\emptybox\,\emptyfrac\hspace{1cm}\emptyframe\hspace{1cm}\emptybox\,\emptyfrac
\]
\end{document}