
所需的輸出:一個包含行號及其函數的表格(例如,行號加一)。
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}
來自鈦kZ 的手冊號碼列印,但這沒有改變任何事情。括起來\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}
一旦您知道第二列中的數字數量,就應該調整第二個參數。
我們還可以添加一個起點,這樣我們就可以排版 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}