foreach 루프 인쇄 PGF 구문 분석 수학

foreach 루프 인쇄 PGF 구문 분석 수학

원하는 출력: 행 번호와 그 함수(예: 행 번호 + 1)가 있는 테이블입니다.

1 2
2
... ...
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}

라텍스 forloop 매트릭스

질문: 오른쪽 열의 소수 부분을 삭제하는 방법은 무엇입니까?

나는 사용해 보았다.\pgfkeys{/pgf/number format/.cd,int detect,precision=2}나는 에서케이Z의 매뉴얼숫자 인쇄, 그러나 그것은 아무것도 바꾸지 않았습니다. \pgfmathresult로 묶으면 \pgfmathprintnumber{}예상치 못한 결과가 발생합니다.

라텍스 forloop 행렬 오류

답변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}

여기에 이미지 설명을 입력하세요

관련 정보