我想用灰色方形图案自动填充该行的其余部分,以便为学生提供一个提交数学想法的区域。
我目前的解决方案是:
\newcommand\mySE{\vrule height 1pt width 5mm depth 0pt
\vrule height 5mm width 1pt depth 0pt}
\newcommand\myNW{\vrule height 5mm width 1pt depth 0pt
\raise5mm\hbox{\vrule height 0pt width 5mm depth 1pt}}
\newcommand\mysquarefill[1]{{\color{black!50}%
\mbox{}\leaders\hbox{\vbox to #1{\cleaders\hbox{\mySE}\vfil}}\hfill}}
的结果
B\mysquarefill{2.5cm}E
结果是
,除了缺少一些线条外,其余都非常好。
如果我写的\hbox{\framebox(5,5){}}
不是\hbox{\mySE}
中间线,而是画两次,因此是深灰色。
有人知道如何正确\leaders
绘制缺失的垂直线和水平线吗\mysquarefill
?
更新并重申:
与此同时,我从“如何正确对齐连续的\leaders?“这\[x|c]leaders
不是我的问题的最佳解决方案,因为它们以某种方式与全局网格对齐。这就是为什么我找不到不规则左/不规则右解决方案。
因为我想测量剩余空间并计算要使用多少个完整的方块,所以我认为这是更好的方法:有没有办法测量一行文本的剩余空间?
我目前的解决方案:
\documentclass{article}
\usepackage{tikzpagenodes}
\usepackage{etoolbox}
\usetikzlibrary{calc}
\newlength{\whatsleft}
\newcommand{\measureremainder}[2]{%
\begin{tikzpicture}[overlay,remember picture]
% Measure distance to right text border
\path let \p0 = (0,0), \p1 = (current page text area.east) in
[/utils/exec={\pgfmathsetlength#1{floor((\x1-\x0)/#2)*#2}\global#1=#1}];
\end{tikzpicture}%
}
\newcommand{\mysquarefill}[4][r]{%
\measureremainder{\whatsleft}{#2}%
\ifstrequal{#1}{l}{}{\hfill}%
\lower#4\hbox{\begin{tikzpicture}%
\draw[step=5mm,color=gray](0,0) grid (\whatsleft,#3);
\end{tikzpicture}}%
\ifstrequal{#1}{c}{\hfill\mbox{}}{}%
}
\begin{document}
\begin{itemize}
\item $\frac{8}{15} + \frac{7}{12}+ \frac{5}{12} +2=$\mysquarefill[l]{5mm}{10mm}{4mm}
\item $\frac{3}{4}$ von $ \frac{2}{5}=$\mysquarefill[r]{5mm}{15mm}{7mm}
\item $\frac{15}{28}\cdot\frac{14}{30}=$\mysquarefill[r]{5mm}{10mm}{4mm}
\end{itemize}
\end{document}
我的新问题是:我怎么能直接使用(current page text area.east)
?如果我在一个宏中完成所有操作,那么有时计算结果无法正确更新,从而产生小框。
应该可以使用类似
\draw[step=5mm,color=gray](0,0) grid (floor(x((current page text area.east))/#2)*#2,#3);
和是否存在更简单的解决方案来解决 raggedleft/raggedright/center 机制?
答案1
我建议如下:
\documentclass{article}
\usepackage{xcolor}
\makeatletter
\newcommand*{\mysquarefill}[3]{%
\begingroup
\color{black!50}\mbox{}%
\cleaders\vbox to #1{%
\cleaders\hbox to #2{%
\vrule height #2 width #3 depth \z@
\kern -#3\relax
\vbox to #2{\hrule width \dimexpr #2+#3 height #3\vfil
\hrule width \dimexpr #2+#3 height #3%
\kern -#3}%
\kern -#3\relax
\vrule height #2 width #3 depth \z@
\hss}%
\vfil
\kern #3\relax
}\hfill\kern #3\relax
\endgroup
}
\makeatother
\newcommand*{\test}[1]{%
\makebox[0pt][r]{B}% protrudes to the left, takes no space
#1%
\makebox[0pt][l]{E}% protrudes to the right, takes no space
}
\setlength{\parindent}{0pt}
\begin{document}
Exactly 10 squares of size $5\,$mm and border width one point fit in
an \verb|\hsize| of $5\,$cm plus one point (this is not the \verb|plus|
keyword of \TeX!):
\smallskip \hsize=\dimexpr 5cm+1pt\relax
\test{\mysquarefill{\dimexpr 2.5cm+1pt\relax}{5mm}{1pt}}
\bigskip \hsize=5.3cm
\test{\mysquarefill{2.8cm}{5mm}{1pt}}
\bigskip \hsize=5.6cm
\test{\mysquarefill{3.1cm}{5mm}{1pt}}
\bigskip \hsize=5.9cm
\test{\mysquarefill{3.4cm}{5mm}{1pt}}
\bigskip \hsize=\textwidth
\mysquarefill{\dimexpr 2.8cm+10pt\relax}{2.8cm}{10pt}%
\end{document}