2

I am creating a graph where a node is placed. I would like to display the coordinates of that node on the axes without manually entering them.

I get Tikz to retrieve those coordinates using let but then the coordinates are stored in TeX points instead of the original number. Is there a way for me to display it "nicely"?

Here the MWE:

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
    \begin{tikzpicture}
    \draw [help lines] (0,0) grid (4,4);
    \coordinate (origin) at (0,0);
    \node[circle,fill]  (d1) at (3,2) {};

    \draw[red,thick] let    \p{1} = (d1)    in (d1|- origin) node[label=below:$\x1$]{} --  (d1) --  (d1 -| origin) node[label=left:\y1]{} ;

    \end{tikzpicture}
\end{document}

which generates this: enter image description here

I would instead like the numbers to read 2 and 3 on the vertical and horizontal axes respectively.

Should I use something like \pgfmathparse? I feel like TeX probably knows the value of 56.90549pt.

1

1 Answer 1

5

You can use a manual conversion

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}
\begin{document}
    \begin{tikzpicture}
    \draw [help lines] (0,0) grid (4,4);
    \coordinate (origin) at (0,0);
    \node[circle,fill]  (d1) at (3,2) {};

    \draw[red,thick] let    \p{1} = (d1)    in (d1|- origin)
        node[label=below:\pgfmathparse{int(round(\x1/28.45274))}$\pgfmathresult$]{} --  (d1)
        --  (d1 -| origin) 
        node[label=left:\pgfmathparse{int(round(\y1/28.45274))}$\pgfmathresult$]{} ;
   \end{tikzpicture}
\end{document}

enter image description here

2
  • Thank you! If I need to do this many times in a graph, is there a way to define a function that does this conversion?
    – Peutch
    Jun 1, 2018 at 22:45
  • 2
    @Peutch Define a custom style mylabel/.style 2 args={label=#1:\pgfmathparse{ int(round(#2/28.45274))}$\pgfmathresult$} then you can use mylabel={left}{\x1} etc.
    – percusse
    Jun 1, 2018 at 23:00

You must log in to answer this question.

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