측정 계산에도 '잘못된 측정 단위(pt 삽입)'?

측정 계산에도 '잘못된 측정 단위(pt 삽입)'?

의 팁을 따른 후이 답변@JasperHabricht님, 저는 다음 매크로를 개선하려고 노력하고 있지만 측정 계산이 이루어졌음에도 불구하고 얻은 것은 뿐입니다. 그리고 다른 매크로에서 Illegal unit of measure (pt inserted)사용하기 전에는 모든 것이 잘 작동했다는 사실도 있었습니다 . 그리고 네, 저는 s와 s를 s로 \pgfmathsetmacro바꾸려고 했습니다 .\newlength\setlength\pgfmathsetmacro

\newcounter{coordinateCounter}
\setcounter{coordinateCounter}{1}
\newlength{\coordinateShift}
\newlength{\leftRightShift}
\newlength{\topBottomShift}
% Parameters
%
% 1: dimension (in cm)
% 2: board size (square)
% 3: step
% 
% Example: A 19x19 board with size 10cm x 10cm: `\coordinates{10}{19}{\step}'
\newcommand{\coordinates}[3]{
  % For some reason, TeX doesn't like dividin by non-integers?
  \setlength{\leftRightShift}{\dimexpr #3 * 10 / 14 \relax}
  \setlength{\topBottomShift}{\dimexpr #3 * 10 / 15 \relax}

  \foreach [count=\i] \l in {A, B, ..., Z} {
    \ifthenelse{\equal{\l}{I} \OR \i > \numexpr #2 + 1 \relax}{}{
      \setlength{\coordinateShift}{\dimexpr #3 * (\thecoordinateCounter - 1) \relax}

      % Top
      \draw[
        xshift = \coordinateShift,
        yshift = #1cm + \topBottomShift,
      ] node {\l};
      % Right
      \draw[
        xshift = #1cm + \leftRightShift,
        yshift = \coordinateShift,
      ] node {\thecoordinateCounter};
      % Bottom
      \draw[
        xshift = \coordinateShift,
        yshift = -(\leftRightShift),
      ] node {\l};
      % Left
      \draw[
        xshift = -(\leftRightShift),
        yshift = \coordinateShift,
      ] node {\thecoordinateCounter};

      \stepcounter{coordinateCounter}
    }
  }
  \setcounter{coordinateCounter}{1}
}

완전한 최소 예:

\documentclass{article}

\usepackage{tikz}
\usepackage{ifthen}

% Parameters
%
% 1: dimension (in cm)
% 2: board size (square)
% 
% Example: A 19x19 board with size 10cm x 10cm: `\gogrid{10}{19}'
\newcommand{\goGrid}[2]{
  \pgfmathsetmacro{\step}{#1 / (#2 - 1)} % chktex 1

  \draw[step=\step] (0, 0) grid (#1, #1);
  
  \boardOutline{#1}
  
  \coordinates{#1}{#2}{\step} % chktex 1
  
  \drawHoshis{#1}{#2}{\step}
}

% Parameters
%
% 1: dimension (in cm)
% 2: board size (square)
% 3: step
% 
% Example: A 19x19 board with size 10cm x 10cm: `\drawHoshis{10}{19}{\step}'
\newcommand{\drawHoshis}[3]{
  \ifnum#2=9\relax
    \foreach \sloc in {{3, 3}, {3, 7}, {7, 3}, {7, 7}, {5, 5}}{
      \pgfmathsetmacro{\hoshiCoordX}{#3 * ({\sloc}[0] - 1)}
      \pgfmathsetmacro{\hoshiCoordY}{#3 * ({\sloc}[1] - 1)}

      \filldraw (\hoshiCoordX, \hoshiCoordY)
        circle [radius=#3 / 10];
    }
  \fi
}

% Parameters
%
% 1: dimension (in cm)
% 
% Example: \boardOutline{10}
\newcommand{\boardOutline}[1]{
  \pgfmathsetmacro{\boardOutlineLineWidth}{#1 * 5 / 1000}
  % Just so the board outline isn't jagged
  \pgfmathsetmacro{\boardOutlinePadding}{\boardOutlineLineWidth / 2}

  % Top
  \draw[black, line width = \boardOutlineLineWidth]
    (-\boardOutlinePadding, #1) -- (#1 + \boardOutlinePadding, #1); % chktex 1 chktex 8
  % Right
  \draw[black, line width = \boardOutlineLineWidth] 
    (#1, 0) -- (#1, #1); % chktex 8
  % Bottom
  \draw[black, line width = \boardOutlineLineWidth]
    (-\boardOutlinePadding, 0) -- (#1 + \boardOutlinePadding, 0); % chktex 1 chktex 8
  % Left
  \draw[black, line width = \boardOutlineLineWidth]
    (0, 0) -- (0, #1); % chktex 8
}

\newcounter{coordinateCounter}
\setcounter{coordinateCounter}{1}
\newlength{\coordinateShift}
\newlength{\leftRightShift}
\newlength{\topBottomShift}
% Parameters
%
% 1: dimension (in cm)
% 2: board size (square)
% 3: step
% 
% Example: A 19x19 board with size 10cm x 10cm: `\coordinates{10}{19}{\step}'
\newcommand{\coordinates}[3]{
  % For some reason, TeX doesn't like dividin by non-integers?
  \setlength{\leftRightShift}{\dimexpr #3 * 10 / 14 \relax}
  \setlength{\topBottomShift}{\dimexpr #3 * 10 / 15 \relax}

  \foreach [count=\i] \l in {A, B, ..., Z} {
    \ifthenelse{\equal{\l}{I} \OR \i > \numexpr #2 + 1 \relax}{}{
      \setlength{\coordinateShift}{\dimexpr #3 * (\thecoordinateCounter - 1) \relax}

      % Top
      \draw[
        xshift = \coordinateShift,
        yshift = #1cm + \topBottomShift,
      ] node {\l};
      % Right
      \draw[
        xshift = #1cm + \leftRightShift,
        yshift = \coordinateShift,
      ] node {\thecoordinateCounter};
      % Bottom
      \draw[
        xshift = \coordinateShift,
        yshift = -(\leftRightShift),
      ] node {\l};
      % Left
      \draw[
        xshift = -(\leftRightShift),
        yshift = \coordinateShift,
      ] node {\thecoordinateCounter};

      \stepcounter{coordinateCounter}
    }
  }
  \setcounter{coordinateCounter}{1}
}

\begin{document}
  \begin{figure}[ht]
    \begin{center}
      \begin{tikzpicture}
        \goGrid{5}{9}
      \end{tikzpicture}
      \caption{Goban 1}\label{my_goban_1}
    \end{center}
  \end{figure}
\end{document}

답변1

예제에서 100줄 정도를 잘라낼 수도 있습니다. 오류 메시지는 오류 위치를 강조 표시합니다.

! Illegal unit of measure (pt inserted).
<to be read again> 
                   *

당신은

\setlength{\leftRightShift}{\dimexpr #3 * 10 / 14 \relax}

이 시점에서 는 본질적으로 다음과 같이 정의됩니다 #3.\step

\def\step{0.625}

따라서 오류 메시지에 표시된 대로 이 표현식에는 단위가 없습니다.

예를 들어 다음 중 하나를 사용할 수 있습니다.

\pgfmathsetmacro{\leftRightShift}{#3 * 10 / 14}

아니면 이거:

\setlength{\leftRightShift}{\dimexpr #3cm * 10 / 15 \relax}

관련 정보