TikZ:无法裁剪边界框

TikZ:无法裁剪边界框

我为 TikZ 编写了此代码,以绘制 Stern Gerlach 实验的草图。由于图像的权重由绘图本身决定,而不是由注释(节点)决定,所以我认为我可以使用这个命令[use as bounding box],以便\centering将绘图主体居中,而不是绘图及其所有注释。(我希望在居中时忽略节点)

我在想要居中的位置周围画了一个框,并使用命令[use as bounding box] 确保这将是边界框。似乎有些不对劲,因为考虑到节点,图形仍然居中。

这非常令人沮丧,因为我已经在一个更简单的绘图中尝试了这个[use as bounding box]命令,看看它是否真的有效(而且确实有效!)。

这是我的代码:

 \documentclass[a4paper]{article}

 \usepackage{tikz}
 \usepackage{tikz-3dplot}

 \tikzset{
  vlak/.style={fill=lightgray!80,draw=none,opacity=1},
  obj/.style={fill=lightgray,draw=none},
  opp/.style={fill=lightgray,opacity=0.6,draw=none},
  rand/.style={thick,draw=gray},
  vector/.style={>=stealth',draw=black,line width=0.55pt}
  }



 \begin{document}

 \tdplotsetmaincoords{75}{140}

 \begin{figure}[htp]
 \centering
 \begin{tikzpicture}[tdplot_main_coords,scale=0.7]
  \newcommand{\nodin}[1]{coordinate(#1)node{#1}}%draw nodes on coordinates, I alter           
                                                   %this later to hide the nodes


  \draw[vlak,rand](0,-2,0)--(0,2,0)\nodin{A}--(0,2,2)\nodin{B}--(0,1,2)\nodin{C}--(0,1,1)\nodin{Q}--(0,-1,1)\nodin{D}--(0,-1,2)\nodin{E}--(0,-2,2)\nodin{F}--cycle;

  \draw[vlak,rand](F)++(-6,0,0)--(F)--(E)--++(-6,0,0)--cycle;
  \draw[vlak,rand](D)++(-6,0,0)--(D)--(E)--++(-6,0,0)--cycle;

  \draw[vlak,rand](0,-1,3)--(0,0,2)\nodin{G}--(0,1,3)\nodin{H}--(0,1,4)\nodin{I}--(0,-1,4)\nodin{J}--cycle;
  \draw[vlak,rand](G)++(-6,0,0)--(G)--(H)--++(-6,0,0)--cycle;
  \draw[vlak,rand](H)++(-6,0,0)--(H)--(I)--++(-6,0,0)--cycle;
  \draw[vlak,rand](J)++(-6,0,0)--(J)--(I)--++(-6,0,0)--cycle;
  \draw[vlak,rand](Q)++(-6,0,0)--(Q)--(D)--++(-6,0,0)--cycle;

  \foreach \x in{0,2,4,6}{
   \draw[vector,->] (-\x,0,2)--(-\x,1,1);
   \draw[vector,->] (-\x,0,2)--(-\x,0.5,1);
   \draw[vector,->] (-\x,0,2)--(-\x,0,1);
   \draw[vector,->] (-\x,0,2)--(-\x,-0.5,1);
   \draw[vector,->] (-\x,0,2)--(-\x,-1,1);
   }


  \draw[vlak,rand](0,-2,0)--(0,2,0)\nodin{A}--(0,2,2)\nodin{B}--(0,1,2)\nodin{C}--(0,1,1)\nodin{Q}--(0,-1,1)\nodin{D}--(0,-1,2)\nodin{E}--(0,-2,2)\nodin{F}--cycle;

  \draw(-9,0,1.8)\nodin{R};


  \draw[vlak,rand](R)++(0,-0.5,-0.5)--++(0,0,1)\nodin{R3}--++(0,1,0)\nodin{R2}--++(0,0,-1)\nodin{R1}--cycle;
  \draw[vlak,rand](R1)++(-1,0,0)--(R1)--(R2)--++(-1,0,0)--cycle;
  \draw[vlak,rand](R3)++(-1,0,0)--(R3)--(R2)--++(-1,0,0)--cycle;

  \tdplotsetrotatedcoords{0}{90}{0}
  \tdplotdrawarc[tdplot_rotated_coords,fill=black,rand]{(R)}{0.1}{0}{360}{}{}
  \draw[thick](R)--(-5,0,1.8)\nodin{M};

  \draw[thick](M)--(5,0,2)\nodin{M1};
  \draw[thick](M)--(5,0,1.6)\nodin{M2};

  \draw[vlak,rand](C)++(-6,0,0)--(C)--(B)--++(-6,0,0)--cycle;
  \draw[vlak,rand](A)++(-6,0,0)--(A)--(B)--++(-6,0,0)--cycle;


  \draw(5,0,0)\nodin{S};
  \draw[opp,rand](S)--++(0,2,0)--++(0,0,3.6)--++(0,-4,0)--++(0,0,-3.6)--cycle;

  \draw(5,0,1.8)\nodin{K};

  \foreach \x in{0.025,0.05,...,1}{
   \tdplotdrawarc[tdplot_rotated_coords,fill=black!80,opacity=0.15*\x,draw=none]{(K)}{1-     \x}{0}{360}{}{}
   }

  \tdplotdrawarc[tdplot_rotated_coords,fill=black]{(M1)}{0.03}{0}{360}{}{}
  \tdplotdrawarc[tdplot_rotated_coords,fill=black]{(M2)}{0.03}{0}{360}{}{}
  \draw[->](S)++(3,0,4)node[left]{klassiek}to[out=0,in=130](5,-0.6,2.4);

  \draw[->,shorten >=0.8pt](S)++(3,0,2)node[left]{kwantummechanisch}to[out=0,in=150](M1);
  \draw[->,shorten >=0.8pt](S)++(3,0,2)to[out=0,in=220](M2);

  \draw(R1)++(-1,0,2.5)\nodin{R4};
  \draw(S)++(2,0,0)\nodin{S1};

  \draw[use as bounding box](S1)rectangle(R4);

 \end{tikzpicture}\caption{Het Stern-Gerlach Experiment}\label{}\end{figure}
 \end{document}

 \tikzend{}{}
 \end{document}

对于为什么会发生这种情况,任何帮助都将不胜感激。

答案1

您需要先设置边界框。TikZ/PGF 图片中的边界框只能增加,不能缩小。因此,当您使用use as bounding box“计算边界框时忽略所有后续构造”选项时,它对任何先前的组件都没有影响。

相关内容