为什么这个 \heightof 和 \widthof 停止工作?

为什么这个 \heightof 和 \widthof 停止工作?

以下内容对我来说已经工作了相当长一段时间。

\documentclass[11pt]{book}
\usepackage[margin=1in]{geometry}            
\geometry{letterpaper}                 
\usepackage[parfill]{parskip}   

\usepackage{tikz, pgf, calc}
\usetikzlibrary{matrix, shapes, positioning, calc, decorations.pathreplacing, shapes.geometric, arrows}

\newcounter{Day}

\newcounter{pt}[Day]    % CORRECTNESS POINTS FOR HW RUBRICS
\newcommand{\pt}[2]     % NUMBER OF POINTS, ITEM IN STARBURST
    {#2\begin{tikzpicture}[remember picture, overlay]
        \node (A) [starburst, 
            draw = red, opacity = .8, 
            fill = red!20, fill opacity = .2, 
            xshift = -.5*\widthof{#2},
            yshift = .5*\heightof{#2}
            ]
            {\phantom{#2}};
        \node (B) at (current page.west) {};
        \path let \p1 = (A), \p2 = (B) in node [draw = red, 
            color = red] at (\x2+.625in,\y1) {#1 pt(s)};
    \end{tikzpicture}
    \addtocounter{pt}{#1}
    }

\begin{document}

\pt{1}{lorem}

\end{document}

最近,我用 MikTeX 2.9 更新了几个软件包。下面是更新的软件包的屏幕截图。

Updated packages

自更新以来,\widthof\heightof命令导致错误。如果我将xshift和更改yshift为其他内容,则一切都会顺利编译(但这不是我希望命令工作的方式)。我有两个问题:

  1. 为什么以前可以奏效,现在却不行了?
  2. 我怎样才能更改代码以使其再次正常工作?

提前感谢你的帮助!

答案1

\widthof\heightof\depthof\totalheightof\maxof\minof)是包的功能,增强了,,和calc中的数学表达式。包自带数学引擎。我在 TikZ 手册中没有找到。因此,我得出结论,这些测量宏不受官方支持。另一方面,包含:\setlength\addtolength\setcounter\addtocounterpgf\widthofpgfmathparser.code.tex

% Stuff for calc compatiability.
\let\real=\pgfmath@calc@real
\let\minof=\pgfmath@calc@minof
\let\maxof=\pgfmath@calc@maxof
\let\ratio=\pgfmath@calc@ratio
\let\widthof=\pgfmath@calc@widthof
\let\heightof=\pgfmath@calc@heightof
\let\depthof=\pgfmath@calc@depthof

[...]

% Stuff for compatability with the calc package.
%
\def\pgfmath@calc@real#1{#1}
\def\pgfmath@calc@minof#1#2{min(#1,#2)}
\def\pgfmath@calc@maxof#1#2{max(#1,#2)}
\def\pgfmath@calc@ratio#1#2{#1/#2}
\def\pgfmath@calc@widthof#1{width("#1")}
\def\pgfmath@calc@heightof#1{height("#1")}
\def\pgfmath@calc@depthof#1{depth("#1")}

该示例与pgf函数width和一起使用height

\documentclass[11pt]{book}
\usepackage[margin=1in]{geometry}
\geometry{letterpaper}
\usepackage[parfill]{parskip}

\usepackage{tikz, pgf, calc}
\usetikzlibrary{matrix, shapes, positioning, calc,
  decorations.pathreplacing, shapes.geometric, arrows}

\newcounter{Day}

\newcounter{pt}[Day]    % CORRECTNESS POINTS FOR HW RUBRICS
\newcommand{\pt}[2]     % NUMBER OF POINTS, ITEM IN STARBURST
    {#2 \begin{tikzpicture}[remember picture, overlay]
        \node (A) [starburst,
            draw = red, opacity = .8,
            fill = red!20, fill opacity = .2,
            xshift = {-.5*width("#2")}, % \widthof{#2},
            yshift = {.5*height("#2")}, % \heightof{#2}
            ]
            {\phantom{#2}};
        \node (B) at (current page.west) {};
        \path let \p1 = (A), \p2 = (B) in node [draw = red,
            color = red] at (\x2+.625in,\y1) {#1 pt(s)};
    \end{tikzpicture}
    \addtocounter{pt}{#1}
    }

\begin{document}

\pt{1}{lorem}

\end{document}

Result

因此,找到了一种解决方法。


顺便说一句,示例中的代码似乎不必要地复杂化(或者我没有理解某些构造的目的)。例如,文本没有放在节点中,而是放在前面,用空格隔开。后者在计算中没有被考虑,将星爆节点移离文本的中心。

简化版本:

\documentclass[11pt]{book}

\usepackage{tikz}
\usetikzlibrary{shapes}

\newcounter{Day}
\newcounter{pt}[Day]

\newcommand*{\pt}[2]{%
  \textcolor{red}{\fbox{#1 pt(s)}}\quad
  \tikz[baseline=(A.base)]\node (A) [
    starburst,
    draw=red,
    fill=red!20,
    fill opacity=.2,
    text opacity=1,
  ] {#2};%
  \addtocounter{pt}{#1}%
}

\begin{document}

\pt{1}{lorem}

\pt{1}{$\pi$}

\end{document}

Result

相关内容