I want to autofill the rest of the line with a gray square-pattern in order give students an area to submit their mathimatical thoughts.
My solution is so far:
\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}}
The result of
B\mysquarefill{2.5cm}E
results in
, which is quite nice exept the missing lines.
If I write \hbox{\framebox(5,5){}}
instead of \hbox{\mySE}
the middlelines a drawn twice and thus darkgray.
Does anyone has an idea how to use \leaders
to draw the missing vertical und horizontal line in \mysquarefill
correctly?
Update and refraised:
In the meantime I learned from "How to align consecutive \leaders properly?" that \[x|c]leaders
aren't the optimal solution for my problem, because they somehow align to a global grid. That's why I couldn't find a raggedleft- / raggedright-solution.
Because I would like to measure the remaining space and to calcute how many complete squares to use, I think this is a better way: Is there a way to measure the remaining space of a line of text?
My solution so far:
\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}
My new question is: How could I directly use (current page text area.east)
? If I all do it in one macro, then sometimes the calculations aren't correctly updated, thus producing to small boxes.
It should be possible to use something like
\draw[step=5mm,color=gray](0,0) grid (floor(x((current page text area.east))/#2)*#2,#3);
And does exist an easier solution for the raggedleft/raggedright/center-mechanism?
\doucmentclass{...}
ending with a\end{document}
?