
数学の授業で、線の残りのスペースを正方形のパターンで埋める簡単な方法を探しています。leaders
配置にはいくつかの欠点があります。正方形パターンによる自動入力 (リーダー vs. tikz))なので、テキスト行の残りのスペースを測定する方法はありますか?。
\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}
これにより、次のものが生成されます。
コードを簡素化し、特に2つのマクロを組み合わせたいと思います。次のようなものを使用するにはどうすればよいでしょうか。
\draw[step=5mm,color=gray](0,0) grid (floor((x-coordinate-of(current page text area.east) - x-coordinate-of(0,0))/#2)*#2,#3);
と?#2=size of squares
#3=height of squareblock
また、raggedleft/raggedright/center メカニズムのより簡単な解決策はありますか?
答え1
あなたの実際の質問が何なのかわかりません。(@frougon の回答が満足できないのはなぜですか) (あなたは配置について言及しました。何の配置ですか? 水平ですか、それとも垂直ですか? あなたが何を望んでいるかはあなただけが知っています。)
とにかく、私はTiを使った次の構成を提案する。けZで四角形を描き、\leaders
スペースを埋めるために使用します。四角形をカスタマイズしたい場合は、Tiで遊んでください。けZ. 適切に配置したい場合は、TeX を操作してください。楽しんでください。
\documentclass{article}
\usepackage{tikz}
\begin{document}
\newbox\astackofsquares
\def\mysquarefill#1#2{
\setbox\astackofsquares=\hbox{%
\tikz[x=#1,y=#1,baseline=#1*#2/2-.5ex]{
\path(0,0)(1,#1*#2);
\begin{pgfinterruptboundingbox}
\draw foreach\i in{1,...,#2}{(0,\i-1)rectangle(1,\i)};
\end{pgfinterruptboundingbox}
}%
}
\leaders\copy\astackofsquares\hfill\hbox{}
}
\begin{itemize}
\item $\frac{8}{15}+\frac{7}{12}+\frac{5}{12} +2=$\mysquarefill{5mm}{2}
\item $\frac{3}{4}$ von $\frac{2}{5}=$\mysquarefill{5mm}{3}
\item $\frac{15}{28}\cdot\frac{14}{30}=$\mysquarefill{5mm}{4}
\end{itemize}
\end{document}
中央揃えバージョン
\leaders
を に置き換えます\cleaders
。
左揃えバージョン
計算する代わりにクリップを使うことを提案します。
\documentclass{article}
\usepackage{tikzpagenodes}
\usepackage{showframe}\def\ShowFrameColor{\color{yellow}}
\begin{document}
\def\quarefillleft#1#2{
\tikz[remember picture,x=#1,y=#1,baseline=#1*#2/2-.5ex]{
\path(0,0)(0,#1*#2);
\begin{pgfinterruptboundingbox}
\clip(-1,-1)rectangle(current page text area.north east);
\draw(0,0)grid[step=#1](20cm,#2);
\end{pgfinterruptboundingbox}
}
}
\begin{itemize}
\item $\frac{8}{15}+\frac{7}{12}+\frac{5}{12} +2=\quarefillleft{5mm}{2}$
\item $\frac{3}{4}$ von $\frac{2}{5}=\quarefillleft{4mm}{3}$
\item $\frac{15}{28}\cdot\frac{14}{30}=\quarefillleft{3mm}{4}$
\end{itemize}
\end{document}