关于坐标问题

关于坐标问题
\documentclass{article}
\usepackage{pgf-umlcd}
\usepackage[a4paper,textwidth=8in,showframe]{geometry}
\begin{document}
\begin{tikzpicture}

  \begin{interface}[text width = 6cm]{SG}{-3,3}
    \attribute{\# vocabulary : String}
    \operation{\# addWord(word: String) : Boolean}
    \operation{\# generateSentence(): String}
  \end{interface}

  \begin{class}{RSG}{-8,-4}
    \implement{SG}
    \attribute{\# vocabulary : String}
    \operation{\# addWord(word: String) : Boolean}
    \operation{\# generateSentence(): String}
  \end{class}

  \begin{class}{IOSSG}{-2,-4}
    \implement{SG}
    \attribute{\# vocabulary : String}
    \operation{\# addWord(word: String) : Boolean}
    \operation{\# generateSentence(): String}
  \end{class}

  \begin{class}{OSG}{4,-4}
    \implement{SG}
    \attribute{\# vocabulary : String}
    \operation{\# addWord(word: String) : Boolean}
    \operation{\# generateSentence(): String}
  \end{class}

  \begin{class}{SentenceGenerator}{6,3}
    \operation{+ main(): void}
  \end{class}
\end{tikzpicture}
\end{document}

对于此代码输出看起来像-

第一张图片 在初始阶段, 的坐标为SentenceGenerator(6,3)SG (-3,3)当我更改 的坐标时SentenceGenerator (6,4)SG会从其初始位置下拉。(即\begin{class}{SentenceGenerator}{6,4})。
现在我的疑问是,为什么会发生这种情况,尽管 的坐标SG没有被修改? 第二张图片

答案1

图片的构造方式是将其放入一个框中,然后将框放置在页面上。当您更改 的坐标时SentenceGenerator,框会变大一点,因为图片会变大一点。具体来说,它的高度会增加。因此,当放置它时,TeX 会在页面上为其留出更多空间,并将框向下移动以腾出空间。坐标不是相对于页面,而是相对于图片中的其他内容(即相对于此框中的其他内容)。

以下是效果的说明:

\documentclass{article}
\usepackage{tikz}
\tikzset{every node/.style={draw}}
\begin{document}
\fbox{%
  \begin{tikzpicture}
    \node at (0,0) {A};
  \end{tikzpicture}%
}
\fbox{%
  \begin{tikzpicture}
    \node at (8,9) {A};
  \end{tikzpicture}%
}
\fbox{%
  \begin{tikzpicture}
    \node at (-5,-10) {A};
  \end{tikzpicture}%
}
\fbox{%
  \begin{tikzpicture}
    \coordinate (o) at (0,0);
    \node at (0,0) {A};
  \end{tikzpicture}%
}
\fbox{%
  \begin{tikzpicture}
    \coordinate (o) at (0,0);
    \node at (8,9) {A};
  \end{tikzpicture}%
}
\fbox{%
  \begin{tikzpicture}
    \coordinate (o) at (0,0);
    \node at (-5,-10) {A};
  \end{tikzpicture}%
}

\fbox{%
  \begin{tikzpicture}
    \coordinate (o) at (0,0) node {.};
    \node at (0,0) {A};
  \end{tikzpicture}%
}
\fbox{%
  \begin{tikzpicture}
    \coordinate (o) at (0,0) node {.};
    \node at (8,9) {A};
  \end{tikzpicture}%
}
\fbox{%
  \begin{tikzpicture}
    \coordinate (o) at (0,0) node {.};
    \node at (-5,-10) {A};
  \end{tikzpicture}%
}
\end{document}

前 6 个tikzpicture是相同的,即使包含“A”的节点的坐标有所不同,即使首先在 处添加了坐标(0,0)。这是因为唯一重要的位是绘制的内容。(这不完全正确,但在这里好像是真的。)

为了使包含“A”的节点的坐标变化有意义,我们需要在图片中添加其他内容,以便从节点到其他内容的距离发生变化,而不仅仅是节点在坐标系中的名义位置发生变化。如果我们在 处添加一个节点以及我们的坐标(0,0),那么我们就会看到改变包含“A”的节点的坐标的效果。这个节点距离在 处添加的附加节点越远(0,0),图片就必须越大才能容纳所有内容。

坐标变化

相关内容