7

The following works fine:

\documentclass[a4paper]{memoir}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}

\coordinate (fs-1-2-ne) at (7,8);
\node at (fs-1-2-ne) {Hello};

\end{tikzpicture}
\end{document}

But, this one does not (it said "Package pgf Error: No shape named fs-1-2 is known"):

\documentclass[a4paper]{memoir}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}

\coordinate (fs-1-2-ne) at (7,8);

\pgfmathsetmacro{\prevcoordinate}{3-1};

\node at (fs-1-\prevcoordinate-ne) {Hello};

\end{tikzpicture}
\end{document}

My use-case is to get another existing coordinate by name, and the name is obtained from a mathematical expression.

1
  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format.
    – user11232
    Mar 29, 2014 at 7:46

1 Answer 1

7

You can use \pgfmathparse and then assign \pgfmathresult to a macro.

\documentclass[a4paper]{memoir}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\pgfmathparse{int(3-1)}
\let\prevcoordinate\pgfmathresult
\coordinate (fs-1-2-ne) at (7,8);

\node at (fs-1-\prevcoordinate-ne) {Hello};

\end{tikzpicture}
\end{document}

As noted by percusse, you can use \pgfmathtruncatemacro (like \pgfmathtruncatemacro{\prevcoordinate}{3-1};)to make your approach work. This will ensure that the output is an integer.

2
  • 1
    Use \pgfmathtruncatemacro to make it work!! :)
    – percusse
    Mar 29, 2014 at 9:37
  • @percusse Thanks, and I added a note in the answer. :)
    – user11232
    Mar 29, 2014 at 10:00

You must log in to answer this question.

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