Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. –  Harish Kumar Mar 29 at 7:46
add comment

1 Answer 1

up vote 10 down vote accepted

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.

share|improve this answer
1  
Use \pgfmathtruncatemacro to make it work!! :) –  percusse Mar 29 at 9:37
    
@percusse Thanks, and I added a note in the answer. :) –  Harish Kumar Mar 29 at 10:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.