准确地将一个节点放置在另一个节点的左上方

准确地将一个节点放置在另一个节点的左上方

我正在尝试绘制一个定义为节点的框,位于另一个节点旁边。

我的代码是

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}

\tikzset{
  pipe/.style = {
    draw,
    %top color=gray!60, 
    %bottom color=gray!20, 
    minimum width=4cm, 
    minimum height=.1cm, 
    anchor=east,
  },
  source/.style = {
    draw,
    %top color=gray!60, 
    %bottom color=gray!20, 
    minimum width=.8cm, 
    minimum height=.4cm, 
    %anchor=east,
  }
  }

\begin{document}
 \definecolor{tank}{RGB}{98,190,177}
 \begin{tikzpicture}
  %tank
  \coordinate (tank) at (0,0);
  \draw[tank, fill=tank] (-2,0.5)--(-0.5,1)--(0.5,1)--(2,0.5)--(2,-0.5)--(0.5,-1)--(-0.5,-1)--(-2,-0.5)--cycle;
  %pipes
  \coordinate (pipe1) at (-2,0);
  \node[pipe] at (pipe1) (pipe1) {};%left pipe
  \coordinate (pipe2) at (2,0);
  \node[pipe,anchor=west] at (pipe2) (pipe2) {};%right pipe
  \node[pipe, right=0mm of pipe2,rotate=-90] (pipe3) {};
  \node[pipe, right=0mm of pipe3,rotate=-160] (R3) {};
  \node[pipe, right=0mm of pipe3,rotate=-130] (R2) {};
  \node[pipe, right=0mm of pipe3,rotate=-110] (R1) {};
  \node[pipe, right=0mm of pipe3,rotate=-80] (L1) {};
  \node[pipe, right=0mm of pipe3,rotate=-50] (L2) {};
  \node[pipe, right=0mm of pipe3,rotate=-20] (L3) {};
  \node[pipe, left=0mm of pipe1,rotate=-30] (sputter) {};
  \node[pipe, left=0mm of pipe1,rotate=30] (duoplasmatron) {};
  %experimental chamber
  \node[circle,fill=red,right=-1.5mm of L1] {};
  %sources  
  \node[source, above left=3mm of sputter,rotate=45] (spusource) {BOX};
  %\node[source, above=3mm of sputter, left=3mm of sputter,rotate=45] (spusource) {BOX};
 \end{tikzpicture}
\end{document}

我的输出是

在此处输入图片描述

我正在尝试将BOXsputter 放在左侧。我尝试使用,above=3mm of sputter, left=3,, of sputter但似乎只解析了最后一个定位命令。我该怎么做?

答案1

更新:这似乎就是原贴作者真正想要的。

在此处输入图片描述

代码

\documentclass[]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}

\tikzset{
  pipe/.style = {
    draw,    %top color=gray!60, 
    %bottom color=gray!20, 
    minimum width=4cm, 
    minimum height=.1cm, 
    anchor=east,
  },
  source/.style = {
    draw, 
    %top color=gray!60, 
    %bottom color=gray!20, 
    minimum width=.8cm, 
    minimum height=.4cm, 
    %anchor=east,
  },

\begin{document}
 \definecolor{tank}{RGB}{98,190,177}
 \begin{tikzpicture}
  %tank
  \coordinate (tank) at (0,0);
  \draw[tank, fill=tank] (-2,0.5)--(-0.5,1)--(0.5,1)--(2,0.5)--(2,-0.5)--(0.5,-1)--(-0.5,-1)--(-2,-0.5)--cycle;
  %pipes
  \coordinate (pipe1) at (-2,0);
  \node[pipe] at (pipe1) (pipe1) {};%left pipe
  \coordinate (pipe2) at (2,0);
  \node[pipe,anchor=west] at (pipe2) (pipe2) {};%right pipe
  \node[pipe, right=0mm of pipe2,rotate=-90] (pipe3) {};
  \node[pipe, right=0mm of pipe3,rotate=-160] (R3) {};
  \node[pipe, right=0mm of pipe3,rotate=-130] (R2) {};
  \node[pipe, right=0mm of pipe3,rotate=-110] (R1) {};
  \node[pipe, right=0mm of pipe3,rotate=-80] (L1) {};
  \node[pipe, right=0mm of pipe3,rotate=-50] (L2) {};
  \node[pipe, right=0mm of pipe3,rotate=-20] (L3) {};
  \node[pipe, left=0mm of pipe1,rotate=-30] (sputter) {};
  \node[pipe, left=0mm of pipe1,rotate=30] (duoplasmatron) {};

%experimental chamber
\node[circle,fill=red,right=-1.5mm of L1] {};

\node[source, left=0mm  of sputter,rotate=60,anchor=south] (spusource) {BOX};
\node[source, rotate=120,left=0mm of duoplasmatron,anchor=south, ] (spusource1) {BOX};

\end{tikzpicture}
\end{document}

与 OP 讨论过几次后,above left = ...手动摆弄位置非常繁琐,尤其是坐标 (x,y) 值。为了避免这种情况,OP 希望有一种自动放置 的方法box。经过几次尝试,此解决方案无法摆弄anchorrotate,正如我的第二条评论所建议的那样。所需要的只是对象的 left=xx mm 以及对齐。

在此处输入图片描述

代码:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}

\tikzset{
  pipe/.style = {
    draw,    %top color=gray!60, 
    %bottom color=gray!20, 
    minimum width=4cm, 
    minimum height=.1cm, rounded corners=3pt,
    anchor=east,
  },
  source/.style = {
    draw, 
    %top color=gray!60, 
    %bottom color=gray!20, 
    minimum width=.8cm, 
    minimum height=.4cm, 
    anchor=east,
  },

\begin{document}
 \definecolor{tank}{RGB}{98,190,177}
 \begin{tikzpicture}
  %tank
  \coordinate (tank) at (0,0);
  \draw[tank, fill=tank] (-2,0.5)--(-0.5,1)--(0.5,1)--(2,0.5)--(2,-0.5)--(0.5,-1)--(-0.5,-1)--(-2,-0.5)--cycle;
  %pipes
  \coordinate (pipe1) at (-2,0);
  \node[pipe] at (pipe1) (pipe1) {};%left pipe
  \coordinate (pipe2) at (2,0);
  \node[pipe,anchor=west] at (pipe2) (pipe2) {};%right pipe
  \node[pipe, right=0mm of pipe2,rotate=-90] (pipe3) {};
  \node[pipe, right=0mm of pipe3,rotate=-160] (R3) {};
  \node[pipe, right=0mm of pipe3,rotate=-130] (R2) {};
  \node[pipe, right=0mm of pipe3,rotate=-110] (R1) {};
  \node[pipe, right=0mm of pipe3,rotate=-80] (L1) {};
  \node[pipe, right=0mm of pipe3,rotate=-50] (L2) {};
  \node[pipe, right=0mm of pipe3,rotate=-20] (L3) {};
  \node[pipe, left=0mm of pipe1,rotate=-30] (sputter) {};
  \node[pipe, left=0mm of pipe1,rotate=30] (duoplasmatron) {};

%experimental chamber
\node[circle,fill=red,right=-1.5mm of L1] {};

\node[source, left=2mm of sputter] (spusource) {BOX};

\node[source, left=2mm of duoplasmatron] (spusource1) {BOX};

\end{tikzpicture}
\end{document}

相关内容