我已经确定了点 (A) 的 x 坐标,并通过以下方式将其打印在 A 旁边
\node[below left] at (A) {%
\pgfgetlastxy{\macrox}{\macroy}
\transformxdimension{\macrox}
\pgfmathprintnumber{\pgfmathresult}};
现在我想进一步使用 \pgfmathresult 并将值存储在变量中(或将其写入文件)
\xdef\xA{\pgfmathresult}
但其不再具有原始值。有没有办法继续使用\pgfmathresult
之前确定的值?
多谢,
克吕尼
附件是一个小例子,进一步说明了这个想法。
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{
compat=1.5,
width=10cm,
}
\usetikzlibrary{intersections}
\tikzset{
crossp/.style={
thick,
draw=gray,
},
}
%----------------------------------------------------------------------------------
\begin{document}
\makeatletter
\newcommand\transformxdimension[1]{
\pgfmathparse{((#1/\pgfplots@x@veclength)+\pgfplots@data@scale@trafo@SHIFT@x)/10^\pgfplots@data@scale@trafo@EXPONENT@x}
}
\makeatother
\begin{tikzpicture}[baseline]
\begin{axis}[
%small,
x=0.5cm, y=0.5cm,
ymajorgrids, xmajorgrids,
ymin=0, ymax=10,
xmin=0, xmax=10,
]
\draw[name path global=lineA] (axis cs:0,0) -- (axis cs:10,10);
\draw[name path global=lineB] (axis cs:0,8) -- (axis cs:10,1);
\path[name intersections={of=lineA and lineB, by=A}];
\node[fill=red, circle, inner sep=1.5pt] at (A) {};
\node[left] at (A) {%
\pgfgetlastxy{\macrox}{\macroy}
\transformxdimension{\macrox}
\pgfmathprintnumber{\pgfmathresult}};
%\pgfmathsetmacro{\xA}{\pgfmathresult}
\end{axis}
\end{tikzpicture}
\end{document}
答案1
你必须保存结果前声明结束。
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{
compat=1.5,
width=10cm,
}
\usetikzlibrary{intersections}
\tikzset{
crossp/.style={
thick,
draw=gray,
},
}
%----------------------------------------------------------------------------------
\begin{document}
\makeatletter
\newcommand\transformxdimension[1]{%
\pgfmathparse{%
((#1/\pgfplots@x@veclength)+\pgfplots@data@scale@trafo@SHIFT@x)/%
10^\pgfplots@data@scale@trafo@EXPONENT@x
}
}
\makeatother
\begin{tikzpicture}[baseline]
\begin{axis}[
%small,
x=0.5cm, y=0.5cm,
ymajorgrids, xmajorgrids,
ymin=0, ymax=10,
xmin=0, xmax=10,
]
\draw[name path global=lineA] (axis cs:0,0) -- (axis cs:10,10);
\draw[name path global=lineB] (axis cs:0,8) -- (axis cs:10,1);
\path[name intersections={of=lineA and lineB, by=A}];
\node[fill=red, circle, inner sep=1.5pt] at (A) {};
\node[left] at (A) {%
\pgfgetlastxy{\macrox}{\macroy}%
\transformxdimension{\macrox}%
\pgfmathprintnumber{\pgfmathresult}%
\xdef\xA{\pgfmathresult}%
};
\end{axis}
\end{tikzpicture}
\show\xA
\end{document}
有了这个我得到
> \xA=macro:
->4.71.
在终端上。