원하지 않을 때 소수점을 표시하는 각 루프에 대해

원하지 않을 때 소수점을 표시하는 각 루프에 대해

내 코드는 다음과 같습니다

\documentclass[tikz,border=10pt]{standalone}
\begin{document}
\begin{tikzpicture}[timeSlot/.style={draw, rectangle, minimum size =1cm}]
        \foreach [count=\x] [evaluate=\x as \xx using \x-1] \val in {J1, J2}
        {
            \node (node\x) [timeSlot] at (\x,0) {\val};
            \node[above] at (node\x.north west) {\xx};
        }
        \node[above] at (node2.north east) {2};
        \draw[ultra thick] (node1.south west) rectangle (node2.north east);
\end{tikzpicture}
\end{document}

출력은 다음과 같습니다

분수 출력

위 출력에서 ​​소수점을 원하지 않습니다. 나는 그것들이 단순히 0, 1, 2이기를 원합니다. 내가 뭘 잘못하고 있는 걸까요? 어떻게 해결하나요?

답변1

이 경우 간단한 방법 중 하나는 int()정수를 얻는 데 사용하는 것입니다.

\documentclass[tikz,border=10pt]{standalone}
\begin{document}
\begin{tikzpicture}[timeSlot/.style={draw, rectangle, minimum size =1cm}]
  \foreach [count=\x] [evaluate=\x as \xx using int(\x-1)] \val in {J1, J2}
  {
    \node (node\x) [timeSlot] at (\x,0) {\val};
    \node[above] at (node\x.north west) {\xx};
  }
  \node[above] at (node2.north east) {2};
  \draw[ultra thick] (node1.south west) rectangle (node2.north east);
\end{tikzpicture}
\end{document}

정수

답변2

단순화 할 수 있으며 소수점 이하 자릿수를 피하기 위해 변환이 필요하지 않은 foreach정수( )를 사용할 수 있습니다 .count=\x

\documentclass[tikz,border=10pt]{standalone}
\begin{document}
\begin{tikzpicture}[timeSlot/.style={draw, rectangle, minimum size =1cm}]
        \foreach [count=\x from 0] \val in {J1, J2}
        {
            \node (node\x) [timeSlot] at (\x,0) {\val};
            \node[above] at (node\x.north west) {\x};
        }
        \node[above] at (node1.north east) {2};
        \draw[ultra thick] (node0.south west) rectangle (node1.north east);
\end{tikzpicture}
\end{document}

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

관련 정보