tikz 코드에서 tex 카운터 사용

tikz 코드에서 tex 카운터 사용

tikz를 사용하여 타임라인 생성을 단순화하기 위해 몇 가지 명령을 작성하는 동안 다음 오류를 발견했습니다.

MWE:

\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{calc}

\usepackage{pgfcalendar}


\begin{document}

\newcount\StartTime
\newcount\EndTime
\begin{tikzpicture}
    \pgfcalendardatetojulian{2021-01-01}{\StartTime}
    \pgfcalendardatetojulian{2022-01-01}{\EndTime}
    \typeout{\the\StartTime}
    \draw let
        \n{length} = (\the\StartTime-\the\EndTime),
    in
        (0,0) -- (\n{length},0);
\end{tikzpicture}

\end{document}

다음 출력을 실행하게 됩니다.

2459216
/media/daten/coding/01_manuals/tex/testing/chrono/mwe.tex:17: Use of \tikz@cc@stop@let doesn't match its definition.
<recently read> \the

l.17            \n{length} = (\the
                       \StartTime-\the\EndTime),

거기에 있는 카운터의 값을 가져오는 데 문제가 있는 것 같습니다. 나는 LaTeX의 확장에 대해 멍청한 사람이기 때문에 슬프게도 이 문제를 스스로 해결할 수 없습니다(그리고 인터넷 조사에서는 유용한 결과를 얻지 못했습니다).

누군가 Tikz에 tex 카운터를 가져오는 것을 도와줄 수 있나요?

답변1

구문 \n{<number register>}은 다음과 같습니다.

\n{<number register>} = {<pgfmath expression>}

\n{length} = {\the\StartTime-\the\EndTime}따라서 (괄호가 아닌 중괄호) 여야 합니다 .

그러나 및 둘 \n{length} = {\the\StartTime-\the\EndTime}다 차원을 유지하기에는 너무 큰 정수이기 때문에 "차원이 너무 큼" 오류가 발생합니다 ( ).\StartTime\EndTimept

해결 방법:

수학 표현식을 구문 분석하기 전과 \StartTime구문 분석 \EndTime하기 전의 차이를 계산합니다 . pgfmath이는 다른 카운트의 도움을 받아 이전에 발생하거나 \draw확장 가능한 방식으로 내부에서 발생할 수 있습니다.

\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{calc}

\usepackage{pgfcalendar}

\begin{document}

\newcount\StartTime
\newcount\EndTime
\begin{tikzpicture}
    \pgfcalendardatetojulian{2021-01-01}{\StartTime}
    \pgfcalendardatetojulian{2022-01-01}{\EndTime}
    \typeout{\the\StartTime}
    \draw let
        \n{length} = {\the\numexpr\StartTime-\EndTime pt},
    in
        % \n{length} is -365pt
        (0,0) -- (\n{length},0);
\end{tikzpicture}

\end{document}

관련 정보