为什么我不能在 LaTeX 中使用 `int`、`mod`、`floor`,即使我添加了定义这些函数的包?

问题描述 投票:0回答:1

我越来越沮丧。我正在尝试在 LaTeX 中使用

int
mod
floor
函数,甚至是
Mod
,但我总是得到一个
undefined control sequence error
。我已经包含以下软件包:

\usepackage{pgfmath}
\usepackage{geometry}
\usepackage[dvipsnames]{xcolor}
\usepackage{xparse}
\usepackage{amsmath}
\usepackage{xstring}
\usepackage{tikz}
\usepackage{ifthen}

我也试过使用:

\usepackage{pgfmath-xfp}

我没有收到任何关于包裹本身的错误。如果我尝试加载一个不存在的包,我会收到以下错误:

\usepackage{foobar}

! LaTeX 错误:找不到文件“foobar.sty”。

键入 X 退出或继续, 或输入新名称。 (默认扩展名:sty)

我尝试使用 Texifier,使用 IntelliJ IDEA TeXiFy 插件,我也安装了 Tex Live。

这是我使用的代码:

% This command is used to display a new job on the timeline. The job is represented by a trapezium.
% #1 - start date (month/year)
% #2 - end date (month/year)
% #3 - level (used in case you want to change the distance from the timeline)
% #4 - trapezium color
% #5 - label (role and company name)
% #6 - opacity of the trapezium
\newcommand\job[6]{
    \setcounter{jobID}{1}

    \StrBefore{#1}{/}[\startMonth] % month in which the job started
    \StrBehind{#1}{/}[\startYear]  % year in which the job started
    \StrBefore{#2}{/}[\endMonth]   % month in which the job ended
    \StrBehind{#2}{/}[\endYear]    % year in which the job ended

    % The start and end dates are expressed as a fraction of the total number of months between the first and last years.
    \pgfmathsetmacro\startAt{(\startYear-\firstYear)+(1/12*(\startMonth-1))}
    \pgfmathsetmacro\endAt{(\endYear-\firstYear)+(1/12*(\endMonth))}

    \pgfmathsetmacro\trapAngle{80}
    \pgfmathsetmacro\maxTrapHeight{35}

    \pgfmathsetmacro\jobDurationMonths{(\endYear - \startYear) * 12 + (\endMonth - \startMonth)}

    % Define the threshold duration (in months) for the two linear segments.
    \pgfmathsetmacro\thresholdDuration{120}

    % Define the scaling factors for the two linear segments.
    \pgfmathsetmacro\shortDurationScale{0.8}
    \pgfmathsetmacro\longDurationScale{0.2}

    % Calculate the scaling factor using the piecewise function.
    \pgfmathsetmacro\scalingFactor{(\jobDurationMonths <= \thresholdDuration) * (\shortDurationScale - (\jobDurationMonths / \thresholdDuration) * (\shortDurationScale - \longDurationScale)) + (\jobDurationMonths > \thresholdDuration) * \longDurationScale}

    % Calculate the trapezium height based on the trapezium width and the duration scaling factor.
    %\pgfmathsetmacro\trapHeight{max(\trapWidth * \scalingFactor, 5)}
    % We set the trapezium width based on the number of months between the start and end dates of the job.
    % The trapezium is rotated 270 degrees, so the width is the height and vice versa.
    % We use a scaling factor to calculate the height of the trapezium. This factor is calculated using a piecewise
    % function, so that the trapeziums never get too wide. I tried using a logarithmic function, and a decay exponential
    % functions but the result wasn't good enough.
    \pgfmathsetmacro\trapWidth{(((\endYear-\startYear)*12)+(\endMonth-\startMonth)+1)}
    \pgfmathsetmacro\trapHeight{max(\trapWidth * \scalingFactor, 5)}

    % Trapezium origin. The trapezium is rotated 270 degrees, so the origin is at the top left corner.
    \pgfmathsetmacro\trapX{(#3)+(\trapHeight/10)}
    \pgfmathsetmacro\trapY{(\startAt+(\endAt-\startAt)/2))}

    % Trapezium middle point. The trapezium is rotated 270 degrees, so the middle point is at the top right corner.
    \pgfmathsetmacro\middleX{\trapX+(\trapHeight/20)-0.1+0.07}
    \pgfmathsetmacro\middleY{\trapY}

    % Draw the trapezium.
    \draw (\trapX,\trapY) node[trapezium, trapezium angle=\trapAngle, trapezium stretches=true, minimum height={\mmtopt{\trapHeight}}, minimum width={\mmtopt{\trapWidth}}, font=\scriptsize, fill=#4!50, opacity={#6}, rotate=270] {};
    \draw[double, fill] (\middleX,\middleY) circle [radius=2pt];

    % Determines the position of the label based on the trapezium height.

    % Calculate the angle based on trapezium height, jobID, and the maximum trapezium height.
    \pgfmathsetmacro\angleForLabelPlacement{70 - 40 * (\trapHeight / \maxTrapHeight) + 20 * (fpeval(int(\jobID) mod 2))}

    % Calculate the length of the first line based on the trapezium height and the maximum trapezium height.
    \pgfmathsetmacro\lineLength{1.5 - (\trapHeight / \maxTrapHeight)}

    % Calculate the offset for the label based on the trapezium height and the maximum trapezium height.
    \pgfmathsetmacro\labelOffset{0.3 * (\trapHeight / \maxTrapHeight)}

    % Calculate the end of the first line based on the adjusted angle, length, and offset.
    \coordinate (startLine) at (\middleX,\middleY);
    \coordinate (endFirstLine) at ([shift=(\angleForLabelPlacement:\lineLength+\labelOffset)]startLine);

    % Draw the label.
    \pgfmathsetmacro\labelPaddingBottom{2pt} % padding between the label and the line
    \node[anchor=south west, font=\tiny,inner sep=0pt, yshift=\labelPaddingBottom] (label) at (endFirstLine) {#5};

    \coordinate (endSecondLine) at (label.east |- endFirstLine);

    \draw (startLine) -- (endFirstLine);
    \draw (endFirstLine) -- (endSecondLine);

    \stepcounter{jobID}
}

调用我使用的函数:

\job{12/1995}{9/1997}{0}{NavyBlue}{Software Developer}{0.8}
latex tikz pgf
1个回答
0
投票

问题是

jobID
不能用作int(\jobID)。正确的语法是 int( alue{jobID}).

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.