如何将“局部边界框”(包含一系列路径的范围)定位在节点的“南”锚点下方?

如何将“局部边界框”(包含一系列路径的范围)定位在节点的“南”锚点下方?

将节点置于 a 下方很容易local bounding box(行为是标准的),但反过来就不行了。我认为这是因为范围不“知道”它外面的节点。我尝试使用positioning库将范围的边界框放置在south其上方节点之一的锚点下方,但没有结果。我还尝试为边界框选择一个锚点(anchor=north),但得到了相同的结果(没有结果)。

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
  \begin{tikzpicture}
    \path node
      [ anchor=north west,
        text width=50mm
      ](n1)
      { This is sentence 1. This is sentence 2. This is sentence 3.
      };
    % DRAWING SHOULD BE POSITIONED BELOW FOLLOWING NODE (n2)
    \path node
      [ anchor=north west,
        text width=50mm
      ](n2)at(n1.south west)
      { \[2+2=4\]
      };
    % ------------- %
    % DRAWING BELOW %
    % ------------- %
    \begin{scope}
      [ scale=0.7,
        local bounding box=smiley
      ]
      \path node[anchor=north west](t1){DRAWING TITLE};
      \path
        [ draw,
          radius=30pt
        ]($(t1.south)+(0,-30pt)$)circle;
      \path
        [ draw,
          radius=5pt
        ]($(t1.south)+(-15pt,10pt)+(0,-30pt)$)circle;
      \path
        [ draw,
          radius=5pt
        ]($(t1.south)+(15pt,10pt)+(0,-30pt)$)circle;
      \path
        [ draw,
          line width=1pt
        ]($(t1.south)+(0,0)+(0,-30pt)$)--($(t1.south)+(0,10pt)+(0,-30pt)$);
      \path[draw]($(t1.south)+(-10pt,-15pt)+(0,-30pt)$)rectangle($(t1.south)+(10pt,-5pt)+(0,-30pt)$);
    \end{scope}
  \end{tikzpicture}
\end{document}

在范围(名为“笑脸”的节点,即 )的\usetikzlibrary{positioning}前言和方括号(样式)中添加不起作用。below=0mm of n2.southlocal bounding box

使用shift反复试验的方法,这不是解决方案(我们需要smileynorth锚点精确地定位在n2south锚点处)。

答案1

您可以使用[shift-(coordinate)]来定位范围的原点。然后只需相对于此原点定位范围的内容即可。

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
  \begin{tikzpicture}
    \path node
      [ anchor=north west,
        text width=50mm
      ](n1)
      { This is sentence 1. This is sentence 2. This is sentence 3.
      };
    % DRAWING SHOULD BE POSITIONED BELOW FOLLOWING NODE (n2)
    \path node
      [ anchor=north west,
        text width=50mm
      ](n2)at(n1.south west)
      { \[2+2=4\]
      };
    % ------------- %
    % DRAWING BELOW %
    % ------------- %
    \begin{scope}
      [ shift=(n2.south),
        scale=0.7,
        local bounding box=smiley
      ]
      \path node[anchor=north](t1){DRAWING TITLE};
      \path
        [ draw,
          radius=30pt
        ]($(t1.south)+(0,-30pt)$)circle;
      \path
        [ draw,
          radius=5pt
        ]($(t1.south)+(-15pt,10pt)+(0,-30pt)$)circle;
      \path
        [ draw,
          radius=5pt
        ]($(t1.south)+(15pt,10pt)+(0,-30pt)$)circle;
      \path
        [ draw,
          line width=1pt
        ]($(t1.south)+(0,0)+(0,-30pt)$)--($(t1.south)+(0,10pt)+(0,-30pt)$);
      \path[draw]($(t1.south)+(-10pt,-15pt)+(0,-30pt)$)rectangle($(t1.south)+(10pt,-5pt)+(0,-30pt)$);
    \end{scope}
  \end{tikzpicture}
\end{document}

演示

答案2

我认为您目前还不能以这种方式定位局部边界框。但是,您可以将局部边界框的内容声明为图片,这是可行的(我必须补充一下,这在一定程度上是意外的)。

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,positioning}
\begin{document}
  \begin{tikzpicture}[smiley/.pic={code={
        \path node[anchor=north](t1){DRAWING TITLE};
      \path
        [ draw,
          radius=30pt
        ]($(t1.south)+(0,-30pt)$)circle;
      \path
        [ draw,
          radius=5pt
        ]($(t1.south)+(-15pt,10pt)+(0,-30pt)$)circle;
      \path
        [ draw,
          radius=5pt
        ]($(t1.south)+(15pt,10pt)+(0,-30pt)$)circle;
      \path
        [ draw,
          line width=1pt
        ]($(t1.south)+(0,0)+(0,-30pt)$)--($(t1.south)+(0,10pt)+(0,-30pt)$);
      \path[draw]($(t1.south)+(-10pt,-15pt)+(0,-30pt)$)rectangle($(t1.south)+(10pt,-5pt)+(0,-30pt)$);
}}]
    \path node
      [ anchor=north west,
        text width=50mm
      ](n1)
      { This is sentence 1. This is sentence 2. This is sentence 3.
      };
    % DRAWING SHOULD BE POSITIONED BELOW FOLLOWING NODE (n2)
    \path node
      [ anchor=north west,
        text width=50mm
      ](n2)at(n1.south west)
      { \[2+2=4\]
      };
    % ------------- %
    % DRAWING BELOW %
    % ------------- %
    \pic[below=1ex of n2,scale=0.7] {smiley};
  \end{tikzpicture}
\end{document}

在此处输入图片描述

当然,您可以使用来local bounding box相对于图片定位事物。

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,positioning}
\begin{document}
  \begin{tikzpicture}[smiley/.pic={code={
  \begin{scope}[local bounding box=#1]
        \path node[anchor=north](t1){DRAWING TITLE};
      \path
        [ draw,
          radius=30pt
        ]($(t1.south)+(0,-30pt)$)circle;
      \path
        [ draw,
          radius=5pt
        ]($(t1.south)+(-15pt,10pt)+(0,-30pt)$)circle;
      \path
        [ draw,
          radius=5pt
        ]($(t1.south)+(15pt,10pt)+(0,-30pt)$)circle;
      \path
        [ draw,
          line width=1pt
        ]($(t1.south)+(0,0)+(0,-30pt)$)--($(t1.south)+(0,10pt)+(0,-30pt)$);
      \path[draw]($(t1.south)+(-10pt,-15pt)+(0,-30pt)$)rectangle($(t1.south)+(10pt,-5pt)+(0,-30pt)$);
  \end{scope}     
}}]
    \path node
      [ anchor=north west,
        text width=50mm
      ](n1)
      { This is sentence 1. This is sentence 2. This is sentence 3.
      };
    % DRAWING SHOULD BE POSITIONED BELOW FOLLOWING NODE (n2)
    \path node
      [ anchor=north west,
        text width=50mm
      ](n2)at(n1.south west)
      { \[2+2=4\]
      };
    % ------------- %
    % DRAWING BELOW %
    % ------------- %
    \pic[below=1ex of n2,scale=0.7] {smiley=my smiley};
    \node[below=1ex of my smiley]{I am below my smiley};
  \end{tikzpicture}
\end{document}

在此处输入图片描述

答案3

由于笑脸只是一个里面有一些线条的圆圈,你可以用 将它画成一个圆形节点path picture。这样你就可以把它放在positioning库中,避免与图片相关的问题。

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,positioning}
\begin{document}
  \begin{tikzpicture}
    \node
      [ anchor=north west,
        text width=50mm
      ](n1)
      { This is sentence 1. This is sentence 2. This is sentence 3.
      };
    % DRAWING SHOULD BE POSITIONED BELOW FOLLOWING NODE (n2)
    \node
      [ anchor=north west,
        text width=50mm,
        below= 5pt of n1
      ](n2)
      { \[2+2=4\]
      };
    % ------------- %
    % DRAWING BELOW %
    % ------------- %
    \begin{scope}
      [ scale=0.7, transform shape
      ]
      \node[below=5pt of n2](t1){DRAWING TITLE};
      \node[circle, minimum size=60pt, draw, below=5pt of t1,
        path picture={
            \draw (path picture bounding box.center)+(-15pt,10pt) circle (5pt);
            \draw (path picture bounding box.center)+(15pt,10pt) circle (5pt);
            \draw (path picture bounding box.center)--++(90:10pt);
            \draw (path picture bounding box.center)+(-10pt,-15pt) rectangle ++(10pt,-5pt);
        }
        ](smiley){};
    \end{scope}


  \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容