2

The below file gives this error when compiled with pdflatex (from TeX Live 2015). How do I fix it, and what have I done wrong?

Error

\pgfmath@dimen@ ...men@@ #1=0.0pt\relax \pgfmath@

l.27 ...e,draw=none] (idx) {index:\hspace*{10pt}};

It seems that using either text height=... or text depth=... induces the error (see commented lines below). This was compiling fine some time ago, but I believe between then and now I have done a tlmgr update --all.

MWE

\documentclass{article}

\usepackage{tikz}
\usepackage{calc}

\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}
\usetikzlibrary{chains}
% Errors
\tikzstyle{tape}=[draw,
  text height=\heightof{$\sum_{i=1}^{n-1} m_i$},
  text depth=\depthof{$\sum_{i=1}^{n-1} m_i$}]

% Errors
% \tikzstyle{tape}=[draw,text height=\heightof{$\sum_{i=1}^{n-1} m_i$}]

% Errors
% \tikzstyle{tape}=[draw,text depth=\depthof{$\sum_{i=1}^{n-1} m_i$}]

% No error
% \tikzstyle{tape}=[draw]

\begin{scope}[start chain=0 going right,node distance=0mm]
    \node [on chain=0,tape,draw=none] (idx) {index:\hspace*{10pt}};
    \node [on chain=0,tape] {$k_1$};
    \node [on chain=0,tape] {$\ldots$};
    \node [on chain=0,tape] {$k_n$};
    \node [on chain=0,tape,draw=none] {$=$};
    \node [on chain=0,tape] {$0$};
    \node [on chain=0,tape] {$\ldots$};
    \node [on chain=0,tape] {$\sum_{i=1}^{n-1} m_i$};
\end{scope}

\end{tikzpicture}
\end{figure}

\end{document}

I have found several questions with similar errors here, but was not able to convert any of the answers to fixes for this situation.

3
  • 1
    \depthof and similar are not expandable, Tikz (too be precise PGFmath) expects a mathematical value here. Just use PGF's own depth("$\sum … $"). Also: Don't use \tikzstyle, use \tikzset instead. Related: Q107227 amongst others. May 11, 2016 at 18:24
  • 1
    Unrelated: Is it possible to load a TikZ library locally? May 11, 2016 at 18:30
  • If you post your solution as an answer, I will accept. Appreciate the additional info, too.
    – Sam
    May 12, 2016 at 12:01

1 Answer 1

3

calc's macros are not expandable, though PGF expects a mathematical value.

PGF does provide its own measurement functions:

  • depth("…"),
  • width("…") and
  • height("…").

The " are needed because they escape the evaluation to text.

If you have ,, = or ] in your text, you have to enclose the value in braces.

For example:

\tikzset{
  text vert/.style={
    text height={height("#1")},
    text depth={depth("#1")}},
  type/.style={draw, text vert={$\sum_{i=1}^{n-1} m_i$}}
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .