
望ましい出力: 行番号とその関数 (たとえば、行番号に 1 を加えたもの) を含むテーブル。
1 | 2 |
2 | 3 |
... | ... |
10 | 11 |
試み:
これは私がMWEを改変したものですTikZ マトリックス内の foreach。
\documentclass[tikz,preview]{standalone}
\usetikzlibrary{matrix}
\usepackage{etoolbox}
\begin{document}
\pgfkeys{/pgf/number format/.cd,fixed,int detect,precision=2}
\begin{tikzpicture}
\let\mymatrixcontent\empty
\foreach \myc in {1,...,10}{%
\pgfmathparse{\myc+1}
\xappto\mymatrixcontent{\expandonce{\myc \&}}
\xappto\mymatrixcontent{\expandonce{\pgfmathresult\\}}
}
\matrix [matrix of nodes,ampersand replacement=\&] {
\mymatrixcontent
};
\end{tikzpicture}
\end{document}
質問: 右の列の小数点部分を削除するにはどうすればよいですか?
\pgfkeys{/pgf/number format/.cd,int detect,precision=2}
から使ってみましたティけZのマニュアル番号印刷ですが、何も変わりません。\pgfmathresult
で囲むと\pgfmathprintnumber{}
、予期しない結果になります。
答え1
あなたの目的が何なのかわかりません。行インデックスに応じて値を出力する、かなり一般的な方法を次に示します。
\documentclass{article}
\usepackage{siunitx}
\ExplSyntaxOn
\NewDocumentCommand{\formulatable}{mmm}
{% #1 = number of rows
% #2 = format of the column
% #3 = formula to typeset
\gnusupporter_formulatable:nnn { #1 } { #2 } { #3 }
}
\cs_new:Nn \__gnusupporter_formulatable_do:n {}
\cs_new:Nn \__gnusupporter_formulatable_cycle:n
{
#1 & \__gnusupporter_formulatable_do:n { #1 } \\
}
\cs_new_protected:Nn \gnusupporter_formulatable:nnn
{
\cs_set:Nn \__gnusupporter_formulatable_do:n { \fp_eval:n { #3 } }
\begin{tabular}{rS[table-format=#2]}
\int_step_function:nN { #1 } \__gnusupporter_formulatable_cycle:n
\end{tabular}
}
\ExplSyntaxOff
\begin{document}
\formulatable{10}{2.0}{#1+1}
\qquad
\formulatable{10}{1.6}{round(exp(#1/10),6)}
\qquad
\formulatable{10}{1.4}{round(sind(#1),4)}
\end{document}
2 番目の列の桁数がわかったら、2 番目の引数を調整する必要があります。
開始点も追加できるので、1 度から 45 度までの角度の正弦表をタイプセットできます。これはプトレマイオスにとって非常に役立つものだったでしょう。
\documentclass{article}
\usepackage{siunitx}
\ExplSyntaxOn
\NewDocumentCommand{\formulatable}{mO{1}mm}
{% #1 = number of rows
% #2 = starting point
% #3 = format of the column
% #4 = formula to typeset
\gnusupporter_formulatable:nnnn { #1 } { #2 } { #3 } { #4 }
}
\cs_new:Nn \__gnusupporter_formulatable_do:n {}
\cs_new:Nn \__gnusupporter_formulatable_cycle:n
{
#1 & \__gnusupporter_formulatable_do:n { #1 } \\
}
\cs_new_protected:Nn \gnusupporter_formulatable:nnnn
{
\cs_set:Nn \__gnusupporter_formulatable_do:n { \fp_eval:n { #4 } }
\begin{tabular}{rS[table-format=#3]}
\int_step_function:nnN { #2 } { #1+#2-1 } \__gnusupporter_formulatable_cycle:n
\end{tabular}
}
\ExplSyntaxOff
\begin{document}
\formulatable{15}{1.4}{round(sind(#1),4)}
\quad
\formulatable{15}[16]{1.4}{round(sind(#1),4)}
\quad
\formulatable{15}[31]{1.4}{round(sind(#1),4)}
\end{document}