例子中,如何显示出R点的坐标值是(2,2)?

发布于 2022-07-28 21:26:17

例子中,如何显示出R点的坐标值是(2,2)?现在是pt长度单位,不太符合习惯。
Q01.jpg

 \documentclass{standalone}
  \usepackage{xeCJK} 
  \usepackage{tikz} 
  \usepackage{color} 
  \usetikzlibrary{calc}
   \newdimen\XCoord \newdimen\YCoord \newcommand*{\ExtractCoordinate}[1]{\path (#1); \pgfgetlastxy{\XCoord}{\YCoord};} \newcommand*{\LabelCurrentCoordinate}[2]{\fill [#1] ($(\XCoord,\YCoord)$) circle (2pt) node [above right] {#2}}
\begin{document} 
\begin{tikzpicture}
\draw[->] (-5.2,0)--(5.2,0);
\draw[->] (0,-5.2)--(0,5.2);
\foreach \x in {0,1,...,8}
{    \draw[xshift=\x cm] (-4,0) -- (-4,0.1);
    \draw[yshift=\x cm] (0,-4) -- (0.1,-4);
};  
\node[below] at (0.2,0){0};
\foreach \x in {-4,-3,...,-1}
\node[below] at(\x,0){\x};
\foreach \y in {1,2,...,4}
\node[below] at(\y,0){\y};
\foreach \y in {-4,-3,...,-1}
\node[left] at(0,\y){\y};
\foreach \y in {1,2,...,4}
\node[left] at(0,\y){\y};
%%%
\node[black](g) at(2,2){R};
\ExtractCoordinate{$(g)$}; 
\LabelCurrentCoordinate{blue}  { (\XCoord,\YCoord) };
\end{tikzpicture}
\end{document} 

查看更多

关注者
0
被浏览
648
芒果不盲
芒果不盲 2022-07-28
学好TiKZ和tcolorbox!

简单回答一下

  • pgf/TiKZ 中有两个尺寸寄存器 \pgf@x \pgf@y 分别用于保存当前的坐标,(类似你的 \pgfgetlastxy)但是“很遗憾”,他们的单位都是 pt,如:
\makeatletter
\begin{tikzpicture}
\path (1,1);
\node[above right] at (1,1) {(\the\pgf@x,\the\pgf@y)};
\end{tikzpicture}
\makeatother

得到
QQ截图20220728222852.png

为此你需要将其转化为 cm, 可以定义一个命令

\def\pttocm#1{\pgfmathparse{#1/28.45274}\pgfmathresult}

pt 转化为 cm
一个完整的 mwe:

\documentclass{article}
\usepackage{tikz} 

\begin{document}
\def\pttocm#1{\pgfmathparse{#1/28.45274}\pgfmathresult}
\makeatletter
\begin{tikzpicture}
\path (1,1);
\node[above right] at (1,1) {(\pttocm{\the\pgf@x},\pttocm{\the\pgf@y})};
\end{tikzpicture}
\makeatother
\end{document}

QQ截图20220728223513.png

  • 此外,你的提问习惯不太好,希望你提问能够好好理解 mwe 一词,不然一大堆代码,没那么多人愿意帮你分析(个人观点)
1 个回答

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览