【问题标题】:Incorrect alignment of nodes in subpictures子图片中的节点对齐不正确
【发布时间】:2010-09-27 13:24:29
【问题描述】:

我正在使用 tikz 在 Latex 文档中排版图表。

我有一个“网格图”网格,每个网格图都绘制为单独的 tikz 图片,然后作为节点排列到网格中。

我想在每个网格图的右下角绘制一个圆形节点(最终将包含一个标签)。

我为每个网格图使用完全相同的代码,但每次都在不同的位置绘制圆圈。

我做错了什么,或者这是 tikz 中的错误?特别是,我包含子图片的方法是否允许/标准/良好做法?

请参阅here 获取图片。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning}
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}%
\begin{document}
\begin{tikzpicture}[scale=1, node distance = .5cm]
  \node (a) at (0,0) {
    \begin{tikzpicture}
     \draw[step=.5cm,gray,very thin] (-0.1,-1.6) grid (1.6, 0.1);
      \node at (1.25, -1.25) [fill=white, shape=circle, draw=black] {};
   \end{tikzpicture}
    };
    \node[right=of a] (b) {
    \begin{tikzpicture}
     \draw[step=.5cm,gray,very thin] (-0.1,-1.6) grid (1.6, 0.1);
      \node at (1.25, -1.25) [fill=white, shape=circle, draw=black] {};
     \end{tikzpicture}
    };
    \node[below=of a] (c) {
    \begin{tikzpicture}
     \draw[step=.5cm,gray,very thin] (-0.1,-1.6) grid (1.6, 0.1);
      \node at (1.25, -1.25) [fill=white, shape=circle, draw=black] {};
     \end{tikzpicture}
    };
    \node[right=of b] (d){
    \begin{tikzpicture}
     \draw[step=.5cm,gray,very thin] (-0.1,-1.6) grid (1.6, 0.1);
      \node at (1.2, -1.5) [fill=white, shape=circle, draw=black] {};
     \end{tikzpicture}
    };
    \node[below=of b] (e){
    \begin{tikzpicture}
     \draw[step=.5cm,gray,very thin] (-0.1,-1.6) grid (1.6, 0.1);
      \node at (1.25, -1.25) [fill=white, shape=circle, draw=black] {};
     \end{tikzpicture}
    };
    \node[below = of c] (f) {
    \begin{tikzpicture}
     \draw[step=.5cm,gray,very thin] (-0.1,-1.6) grid (1.6, 0.1);
      \node at (1.25, -1.25) [fill=white, shape=circle, draw=black] {};
      \end{tikzpicture}
    };
\end{tikzpicture}
\end{document}

【问题讨论】:

  • 我不知道可以嵌套 tikzpictures。谢谢你的例子!

标签: latex tikz pgf


【解决方案1】:

我不确定为什么您的示例中的圆圈没有对齐,但这可能与使用 of 的相对定位有关。

我不知道这是否是最佳做法,但您可以使用foreach 来自动构建网格:

\begin{document}
\begin{tikzpicture}[scale=1]
  \foreach \x in {-0.01cm,2.99cm,5.99cm}
    \foreach \y in {-0.01cm,2.99cm,5.99cm} {
      \draw[step=.5cm,gray,thin] (\x,\y) grid +(1.52cm,1.52cm);
      \draw[fill=white, draw=black] (\x,\y) +(1.255cm,0.25cm) circle (0.2cm);
    }
\end{tikzpicture}
\end{document}

【讨论】:

  • 谢谢。导致这种行为的是“of”。当我将上面的每个节点更改为绝对定位(即 \node (b) at (3, 0) )时,图像呈现完美,即使仍然包含 tikz 子图片。 (每个网格图最终都会有所不同,用箭头连接它们,这是我首先采用这种方法而不是使用 \foreach 循环。)
猜你喜欢
  • 1970-01-01
  • 2012-11-17
  • 2018-07-30
  • 2020-08-11
  • 1970-01-01
  • 1970-01-01
  • 2013-05-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多