这里的圆形怎样才能改为大小相似的矩形呢?

这里的圆形怎样才能改为大小相似的矩形呢?
%--------------------------------------------------------------------------------------------------------- %
\documentclass[english]{book}
%--------------------------------------------------------------------------------------------------------- %
%
\usepackage[fleqn]{amsmath} %
\usepackage{amsthm,amssymb} %
\usepackage[explicit]{titlesec} %
\usepackage{tikz} % tikz - essential
\usepackage{newtxtext} %
\usepackage{xcolor} %
\usepackage{colortbl} % changed to just colortbl
\usepackage{array} %
\usepackage[paperwidth=170mm,paperheight=240mm,textwidth=132mm,lmargin=12.5mm,rmargin=12.5mm,bindingoffset=12.5mm,noheadfoot,nomarginpar,showframe,showcrop]{geometry} %
\usepackage[a4,frame,cam,center]{crop} %
\usepackage{layout} %
\usepackage{graphicx}
\usepackage[T1]{fontenc} % added 16_02_2017
\usepackage{mathtools} %
\usepackage{exercise} %
%
% --------------------------------------- START DECLARATIONS --------------------------------------------- %
%
\setlength{\unitlength}{1mm} % 1mm=2.834646pt; 1pt=0.3515mm
%
\newcounter{numofdots}
\setcounter{numofdots}{6} %
\def\myscale{0.25}

\newcommand{\showdots}[3][pink]{ %
  \begin{tikzpicture}
    \foreach \x in {1,...,#2} { %
    \ifnum \x > #3 %
        \draw[fill=pink,thin] {(\x*\myscale,-1)} circle (0.9mm);
% if I change "circle (0.9mm)" to "rectangle {0.9mm,0.9mm)" it gives unexpected results
    \else
        \draw [fill=red,thin] {(\x*\myscale,-1)} circle (0.9mm);
    \fi
  }
  \end{tikzpicture} } %


\begin{document}

\clearpage

\subsection*{Subsection}

\begin{tabular}{ll}

\noindent \hspace{18pt}easy & \showdots[pink]{6}{1} \tabularnewline % {#1} must be {#2} must be 8, {#3} is the early number

\noindent \hspace{18pt}harder & \showdots[pink]{6}{4} \tabularnewline

\noindent \hspace{18pt}hardest & \showdots[pink]{6}{6} \tabularnewline
\end{tabular}

\vspace{9pt}
\noindent Comment: would like the circles to be rectangles (aspect $\approx$ 1.6) and nearly touching.

\begin{Exercise}[label=chap_04_exer_01,title={simple and not so simple sums}]

\Question{Perform the addition $2+5$\hspace{0.6pt}? \showdots[pink]{6}{1}}\vspace{6pt}

\Question{Explain the subtraction $3-7$\hspace{0.6pt}? \showdots[pink]{6}{3} }\vspace{6pt}

\Question{What about $99+36$\hspace{0.6pt}? \showdots[pink]{6}{4} }\vspace{6pt}

\Question{Why is $16\hspace{-1.2pt}-\hspace{-1.2pt}18$ so different from the questions above\hspace{0.6pt}? \showdots[pink]{6}{5} }

\end{Exercise}

\vspace{6pt}
\begin{Exercise}[label=chap_04_exer_01,title={harder sums}]

\Question{Evaluate  $-2+5-9$ \showdots[pink]{6}{5}}\vspace{6pt}

\Question{This is deliberately quite a long lead-in \hspace{1.2pt}$-12-(\hspace{0.6pt}5-9\hspace{0.6pt})$ \showdots[pink]{6}{6}}

\end{Exercise}

\end{document}

答案1

像这样吗?

%--------------------------------------------------------------------------------------------------------- %
\documentclass[english]{book}
%--------------------------------------------------------------------------------------------------------- %
%
\usepackage[fleqn]{amsmath} %
\usepackage{amsthm,amssymb} %
\usepackage[explicit]{titlesec} %
\usepackage{tikz} % tikz - essential
\usepackage{newtxtext} %
\usepackage{xcolor} %
\usepackage{colortbl} % changed to just colortbl
\usepackage{array} %
\usepackage[paperwidth=170mm,paperheight=240mm,textwidth=132mm,lmargin=12.5mm,rmargin=12.5mm,bindingoffset=12.5mm,noheadfoot,nomarginpar,showframe,showcrop]{geometry} %
\usepackage[a4,frame,cam,center]{crop} %
\usepackage{layout} %
\usepackage{graphicx}
\usepackage[T1]{fontenc} % added 16_02_2017
\usepackage{mathtools} %
\usepackage{exercise} %
%
% --------------------------------------- START DECLARATIONS --------------------------------------------- %
%
\setlength{\unitlength}{1mm} % 1mm=2.834646pt; 1pt=0.3515mm
%
\newcounter{numofdots}
\setcounter{numofdots}{6} %
\def\myscale{0.25}

\newcommand{\showdots}[3][pink]{ %
  \begin{tikzpicture}
    \foreach \x in {1,...,#2} { %
    \ifnum \x > #3 %
        \draw[fill=pink,thin] {(\x*\myscale,-1)} circle (0.9mm);
% if I change "circle (0.9mm)" to "rectangle {0.9mm,0.9mm)" it gives unexpected results
    \else
        \draw [fill=red,thin] {(\x*\myscale,-1)} circle (0.9mm);
    \fi
  }
  \end{tikzpicture} } %


\newcommand{\showrects}[3][pink]{ %
  \begin{tikzpicture}
    \foreach \x in {1,...,#2} { %
    \ifnum \x > #3 %
        \draw[fill=pink,thin] (\x*\myscale*1cm-0.9mm,-0.9mm) rectangle ++
        (1.8mm,1.8mm);
% if I change "circle (0.9mm)" to "rectangle {0.9mm,0.9mm)" it gives unexpected results
    \else
        \draw [fill=red,thin] (\x*\myscale*1cm-0.9mm,-0.9mm) rectangle ++
        (1.8mm,1.8mm);
    \fi
  }
  \end{tikzpicture} } %

\begin{document}

\clearpage

\subsection*{Subsection}

\begin{tabular}{ll}

\noindent \hspace{18pt}easy & \showrects[pink]{6}{1} \tabularnewline % {#1} must be {#2} must be 8, {#3} is the early number

\noindent \hspace{18pt}harder & \showrects[pink]{6}{4} \tabularnewline

\noindent \hspace{18pt}hardest & \showrects[pink]{6}{6} \tabularnewline
\end{tabular}

\vspace{9pt}
\noindent Comment: would like the circles to be rectangles (aspect $\approx$ 1.6) and nearly touching.

\begin{Exercise}[label=chap_04_exer_01,title={simple and not so simple sums}]

\Question{Perform the addition $2+5$\hspace{0.6pt}? \showrects[pink]{6}{1}}\vspace{6pt}

\Question{Explain the subtraction $3-7$\hspace{0.6pt}? \showrects[pink]{6}{3} }\vspace{6pt}

\Question{What about $99+36$\hspace{0.6pt}? \showrects[pink]{6}{4} }\vspace{6pt}

\Question{Why is $16\hspace{-1.2pt}-\hspace{-1.2pt}18$ so different from the questions above\hspace{0.6pt}? \showrects[pink]{6}{5} }

\end{Exercise}

\vspace{6pt}
\begin{Exercise}[label=chap_04_exer_01,title={harder sums}]

\Question{Evaluate  $-2+5-9$ \showrects[pink]{6}{5}}\vspace{6pt}

\Question{This is deliberately quite a long lead-in \hspace{1.2pt}$-12-(\hspace{0.6pt}5-9\hspace{0.6pt})$ \showrects[pink]{6}{6}}

\end{Exercise}

\end{document}

在此处输入图片描述

相关内容