I would like to plot the following figure:
but only that in the nodes x_1,x_2,x_3 the right coordinates of the points displayed. The corresponding MWE is the following - I have included the entire preamble, since this is a part of a larger document:
\documentclass[11pt,a4paper]{article} \usepackage[english,greek]{babel} \usepackage[iso-8859-7]{inputenc} \usepackage[table]{xcolor} \usepackage{amsmath,amsthm,enumitem,amssymb,tikz,graphicx,float,mathtools,mdframed,changepage,ifthen} \usetikzlibrary{decorations.pathreplacing} \usetikzlibrary{decorations.pathmorphing} \usetikzlibrary{arrows.meta} \usetikzlibrary{patterns} \usetikzlibrary{intersections} \usetikzlibrary{calc} \begin{document} \begin{figure} \centering \begin{tikzpicture} \draw[thick,->,name path=x axis] (-4,0) -- (4,0)node[pos=1,below]{$x$}; \draw[thick,->,name path=y axis] (0,-3) -- (0,3)node[pos=1,left]{$y$}; \node[left,yshift=-8pt](O) at (0,0){$O$}; \foreach \i in {-3,-2,...,3}{ \ifthenelse{\i=-3 \OR \i=3}{ \draw (\i,-.1) -- (\i,.1) node[pos=0,below]{}; } { \ifthenelse{\NOT \i=0}{ \draw (\i,-.1) -- (\i,.1) node[pos=0,below]{}; \draw (-.1,\i) -- (.1,\i) node[pos=0,left]{}; }{} } } \draw[thick, name path=curve] (-3,-1.5) .. controls (-1.9,3) and (2.6,-3) .. (3,2); \foreach \i in {1,2,3}{ \node[circle, fill=black, inner sep=1pt, name intersections={of={curve and x axis}}] (A\i) at (intersection-\i){}; } \newdimen\mydim \pgfextractx{\mydim}{(A1)} \pgfmathsetmacro{\res}{\mydim*0.03515} \node at ($(A1)+(0,.5)$){$x_1\approx\res$}; \pgfextractx{\mydim}{(A2)} \pgfmathsetmacro{\res}{\mydim*0.03515} \node at ($(A2)+(.4,.5)$){$x_2\approx\res$}; \pgfextractx{\mydim}{(A3)} \pgfmathsetmacro{\res}{\mydim*0.03515} \node at ($(A3)+(0,-.5)$){$x_3\approx\res$}; \end{tikzpicture} \caption{Οι ρίζες της εξίσωσης $f(x)=0$} \label{fig:zeros} \end{figure} \end{document} I would also like them to be rounded, so, I tried to use \pgfmathroundtozerofill, but the result was as follows:
And the corresponding MWE:
\documentclass[11pt,a4paper]{article} \usepackage[english,greek]{babel} \usepackage[iso-8859-7]{inputenc} \usepackage[table]{xcolor} \usepackage{amsmath,amsthm,enumitem,amssymb,tikz,graphicx,float,mathtools,mdframed,changepage,ifthen} \usetikzlibrary{decorations.pathreplacing} \usetikzlibrary{decorations.pathmorphing} \usetikzlibrary{arrows.meta} \usetikzlibrary{patterns} \usetikzlibrary{intersections} \usetikzlibrary{calc} \begin{document} \begin{figure} \centering \begin{tikzpicture} \draw[thick,->,name path=x axis] (-4,0) -- (4,0)node[pos=1,below]{$x$}; \draw[thick,->,name path=y axis] (0,-3) -- (0,3)node[pos=1,left]{$y$}; \node[left,yshift=-8pt](O) at (0,0){$O$}; \foreach \i in {-3,-2,...,3}{ \ifthenelse{\i=-3 \OR \i=3}{ \draw (\i,-.1) -- (\i,.1) node[pos=0,below]{}; } { \ifthenelse{\NOT \i=0}{ \draw (\i,-.1) -- (\i,.1) node[pos=0,below]{}; \draw (-.1,\i) -- (.1,\i) node[pos=0,left]{}; }{} } } \draw[thick, name path=curve] (-3,-1.5) .. controls (-1.9,3) and (2.6,-3) .. (3,2); \foreach \i in {1,2,3}{ \node[circle, fill=black, inner sep=1pt, name intersections={of={curve and x axis}}] (A\i) at (intersection-\i){}; } \newdimen\mydim \pgfextractx{\mydim}{(A1)} \pgfmathsetmacro{\res}{\mydim*0.03515} \node at ($(A1)+(0,.5)$){$x_1\approx\pgfmathroundtozerofill{\res}\pgfmathresult$}; \pgfextractx{\mydim}{(A2)} \pgfmathsetmacro{\res}{\mydim*0.03515} \node at ($(A2)+(.4,.5)$){$x_2\approx\pgfmathroundtozerofill{\res}\pgfmathresult$}; \pgfextractx{\mydim}{(A3)} \pgfmathsetmacro{\res}{\mydim*0.03515} \node at ($(A3)+(0,-.5)$){$x_3\approx\pgfmathroundtozerofill{\res}\pgfmathresult$}; \end{tikzpicture} \caption{Οι ρίζες της εξίσωσης $f(x)=0$} \label{fig:zeros} \end{figure} \end{document} I cannot figure out what is going wrong, since even when I used \pgfextracty instead of \pgfextractx, only the first coordinate was displayed as 0; the other two where some, seemingly, irrelevant numbers. So, any help/suggestion would be very much appreciated.



\pgfextractxshould be used with PGF (low level) points not with TikZ ones. You can ckeck that if you replace\pgfextractx{\mydim}{(A1)}by\pgfextractx{\mydim}{(A2)}the result is not changing (probably you get the x coordinate of the last used point). You can check the answers of this question to see different methods how to obtain the coordinates of a point.