![グラフ用紙に文字(数字)を収めるにはどうすればいいですか?](https://rvso.com/image/305890/%E3%82%B0%E3%83%A9%E3%83%95%E7%94%A8%E7%B4%99%E3%81%AB%E6%96%87%E5%AD%97%EF%BC%88%E6%95%B0%E5%AD%97%EF%BC%89%E3%82%92%E5%8F%8E%E3%82%81%E3%82%8B%E3%81%AB%E3%81%AF%E3%81%A9%E3%81%86%E3%81%99%E3%82%8C%E3%81%B0%E3%81%84%E3%81%84%E3%81%A7%E3%81%99%E3%81%8B%EF%BC%9F.png)
いくつかの計算結果をグラフ用紙に印刷したいです(数字を足すなどの簡単な計算だけです)。
表形式の(醜い)例:
\begin{tabular}{|*{10}{r|}}\hline
& & & & & & & & & \\\hline
& & 1 & + & & 1 & = & & & 2\\\hline
& 1 & 1 & + & & 1 & = & & 1 & 2\\\hline
& 1 & 1 & + & 1& 1 & = & & 2 & 2\\\hline
& & & & & & & & & \\\hline
\end{tabular}
グラフ用紙/方眼紙を印刷するには、いくつかの解決策があります。
- http://texwelt.de/wissen/fragen/2639/wie-kann-ich-kastchenpapier-zeichnen
- http://www.texample.net/tikz/examples/グラフペーパー/
- レイアウト生成を支援するパッケージですか? 背景にグラフ用紙がありますか?
- http://www.ctan.org/pkg/graphpap
そこでグラフ用紙を使って解決策を見つけようとしましたが、四角いボックスにテキストを書き込むのに問題があります。
これまでの私の解決策:
\documentclass[12pt,a6paper]{scrartcl}
\usepackage{tikz}
\usepackage{ifthen}
\newcounter{gridypos}
\newenvironment{squaredpaper}[2][0.5cm]{%
\setcounter{gridypos}{#2}
\newcommand\gridtext[2][\relax]{
\ifthenelse{\equal{##1}{\relax}}{}{
\setcounter{gridypos}{#2}
\addtocounter{gridypos}{-##1}
\addtocounter{gridypos}{1}
}
\node[anchor=west] at (0,0) [yshift=\value{gridypos}*#1-.5*#1]{##2}; %fixme one box per character(including spaces)
\addtocounter{gridypos}{-1}%Next \gridtext one line lower
}
%Make the grid
%Source: http://texwelt.de/wissen/fragen/2639/wie-kann-ich-kastchenpapier-zeichnen
\begin{tikzpicture}[gray,step=#1]
\pgfmathtruncatemacro\anzahl{(\linewidth-\pgflinewidth)/#1} % maximale Anzahl Kaestchen pro Zeile
\draw (0,0) rectangle (\anzahl*#1,#2*#1) (0,0) grid (\anzahl*#1,#2*#1);
}{
\end{tikzpicture}
}
\begin{document}
\begin{squaredpaper}{20}
%Start on top line and go down.
\gridtext{ 1+ 1= 2}
\gridtext{ 1+ 2= 3}
\gridtext{ 1+ 3= 4}
\gridtext{ 1+10=11}
%Make fix positions
\gridtext[10]{10+10=20} %Start in line 10
\gridtext[15]{15+10=25} %Start in line 15
\gridtext[18]{18+10=28} %Start in line 18
\end{squaredpaper}
\end{document}
結果:
欠けているものが 2 つあります。
- マクロ \gridtext は、x 位置を定義する 2 番目のパラメータを取得する必要があります (他の問題が解決されれば、自分で作成できると思います)
- テキストが四角いボックスに収まりません(ボックスごとに 1 文字(数字、演算子、またはスペース))
それをどうやって行うかというアイデアはいくつかありますが、どうやって行うのか全くわかりません。
- パラメータを解析し、文字ごとにボックスに配置します。
- squaredpaper 環境のオプション パラメータの正確な長さの等幅フォントを使用します。
備考:
- \gridtext パラメータ内のスペースを尊重する必要があります (これが難しい場合は、プレースホルダーとして ~ を使用することもできます)。
- 今のところテキストを追加したくありませんが、テキストを追加するための \gridtext の * バリアントは問題ないかもしれません (ただし、必要な場合は自分で実行できると思います)。
答え1
私は を使って手動で入力にスペースを追加しました~
。マクロは入力内の文字間のスペースを 1 つ取り込むように記述できますが、 以外の LaTeX の解析メカニズムはすべて、verbatim
複数のスペースを 1 つのスペースとして読み取ります。したがって、\
またはを使用するのが、~
ハード スペースの適切な方法として理にかなっています。
の結果は、\gridtext
入力を 1 文字ずつ解析し、それを単位グリッド セルのサイズのボックスに設定することによって実現されます。
マクロ\gridtext
には、水平オフセットを正方形で指定する 2 番目の必須引数が追加されました。
\obeyspaces
議論の中でハードスペースの使用を要求するのではなく、編集されました\gridtext
。
\documentclass[12pt,a6paper]{scrartcl}
\usepackage{tikz}
\usepackage{ifthen}
\newcounter{gridypos}
\newenvironment{squaredpaper}[2][.5cm]{\obeyspaces%
\setcounter{gridypos}{#2}
\newcommand\gridtext[3][\relax]{
\ifthenelse{\equal{##1}{\relax}}{}{
\setcounter{gridypos}{#2}
\addtocounter{gridypos}{-##1}
\addtocounter{gridypos}{1}
}
%\tmp@dim0=#1\relax%
\node[anchor=west] at (-.15,0) [yshift=\value{gridypos}*#1-.5*#1]{%
\hspace{##2\dimexpr#1\relax}\spaceout{#1}{##3}}; %fixme one box per character(including spaces)
\addtocounter{gridypos}{-1}%Next \gridtext one line lower
}
%Make the grid
%Source: http://texwelt.de/wissen/fragen/2639/wie-kann-ich-kastchenpapier-zeichnen
\begin{tikzpicture}[gray,step=#1]
\pgfmathtruncatemacro\anzahl{(\linewidth-\pgflinewidth)/#1} % maximale Anzahl Kaestchen pro Zeile
\draw (0,0) rectangle (\anzahl*#1,#2*#1) (0,0) grid (\anzahl*#1,#2*#1);
}{
\end{tikzpicture}
}
\newcommand\spaceout[2]{\def\charwd{#1}\spaceouthelp#2\relax\relax\relax}
\def\spaceouthelp#1#2\relax{%
\ifx#1\relax\else%
\makebox[\charwd]{#1}%
\spaceouthelp#2\relax%
\fi%
}
\begin{document}
\ttfamily%\scriptsize% WILL WORK IF UNCOMMENTED
\begin{squaredpaper}{19}
%Start on top line and go down.
\gridtext{0}{1+ 1= 2}
\gridtext{0}{1+ 2= 3}
\gridtext{0}{1+ 3= 4}
\gridtext{0}{1+10=11}
%Make fix positions
\gridtext[10]{3}{10+10=20} %Start in line 10
\gridtext[15]{4}{15+10=25} %Start in line 15
\gridtext[18]{5}{18+10=28} %Start in line 18
\end{squaredpaper}
\end{document}
サイズを に変更しても\scriptsize
、引き続き動作します。
グリッド サイズが変更された場合でも (例: \begin{squaredpaper}[.4cm]{19}
)、次のように動作します。