我正在使用 blochsphere 包(参见1),我想将其嵌套在另一个 tikzpicture 中,以便与多个 blochspheres 一起使用。手册告诉人们在设置中输入“nested=true” \begin{tikzpicture}
。不幸的是,即使使用手册中给出的 blochsphere 示例也会出现许多错误 - 我使用它来提供 MWE:
\begin{tikzpicture}
\draw (0,0) node [fill=red]{
\begin{blochsphere}[radius=1.5 cm,tilt=15,rotation=-20,nested=true]
\drawBallGrid[style={opacity=0.3}]{30}{30}
\drawGreatCircle[style={dashed}]{-60}{0}{0}
\drawGreatCircle[style={dashed}]{60}{0}{0}
\drawRotationLeft[scale=1.3,style={red}]{-60}{0}{0}{15}
\drawRotationRight[scale=1.3,style={red}]{60}{0}{0}{15}
\node at (-0.8,1.9) {\textcolor{red}{\tiny $J_{12}(t)$}};
\node at (1.1,1.8) {\textcolor{red}{\tiny $J_{23}(t)$}};
\labelLatLon{up}{90}{0};
\labelLatLon{down}{-90}{90};
\node[above] at (up) {{\tiny $\left|1\right>$ }};
\node[below] at (down) {{\tiny $\left|0\right>$}};
\labelLatLon[labelmark=false]{d}{15}{90};
\node at (d) {\color{gray}\fontsize{0.15cm}{1em}\selectfont $60^\circ$};
\labelLatLon[labelmark=false]{d2}{5}{78};
\end{blochsphere}
}
\end{tikzpicture}
我所修改的只是第一行和最后两行代码以及nested=true
第三行。一个错误是(例如)
! Undefined control sequence.\tmp ->\endgroup \draw[current plane,on layer=back,opacity=0.3] (\agamma -\... \drawBallGrid[style={opacity=0.3}]{30}{30}
就我的个人 blochsphere 而言,我遇到了这些以及其他错误,例如missing number treated as zero
等。有人可以帮我使 blochsphere 包能够嵌套在另一个 tikzpicture 中吗?
谢谢你!
答案1
nested=true
使用密钥时出现问题blochsphere
。在正常的 blochsphere 环境中,初始化是在 tikzpicture 启动之前完成的。在嵌套环境中,初始化是在 tikzpicture 启动之后完成的。对于大多数相关代码,这并不重要。但是,有一部分确实需要到位前tikzpicture 已启动,这就是图层。因此,您需要在序言中添加以下几行:
\pgfdeclarelayer{back}%
\pgfdeclarelayer{front}%
\pgfsetlayers{back,main,front}%
一旦完成,blochsphere 环境就可以直接在 tikzpicture 环境中使用。它确实不是需要位于节点内部(实际上,应该不能在节点内使用)。但它可以包含在一个范围内,并且可以重新定位该范围以改变块球的位置。可能简单的翻译就足够了,如下面的代码所示,但如果您想要更复杂的定位语法,那么请考虑开发版本的tikzmark
它允许您以类似于节点的方式在范围内定义“锚点”。
完整代码如下。代码中还有一些其他小问题,我已经修复了。
\documentclass{article}
%\url{https://tex.stackexchange.com/q/653567/86}
\usepackage{tikz}
\usepackage{blochsphere}
% These lines are needed when using the `nested=true` option
\pgfdeclarelayer{back}%
\pgfdeclarelayer{front}%
\pgfsetlayers{back,main,front}%
\begin{document}
\begin{tikzpicture}
\begin{scope}
\begin{blochsphere}[radius=1.5 cm,tilt=15,rotation=-20,nested=true]
% The next line is automatically included when not nesting
% but needs to be here when nesting
\drawBall
\drawBallGrid[style={draw,opacity=0.3}]{30}{30}
% These two commands only take 3 arguments (including the optional style)
\drawGreatCircle[style={dashed}]{-60}{0}%{0}
\drawGreatCircle[style={dashed}]{60}{0}%{0}
\drawRotationLeft[scale=1.3,style={red}]{-60}{0}{0}{15}
\drawRotationRight[scale=1.3,style={red}]{60}{0}{0}{15}
\node at (-0.8,1.9) {\textcolor{red}{\tiny $J_{12}(t)$}};
\node at (1.1,1.8) {\textcolor{red}{\tiny $J_{23}(t)$}};
% There were a few extra ;s in these lines
\labelLatLon{up}{90}{0}
\labelLatLon{down}{-90}{90}
\node[above] at (up) {{\tiny $\left|1\right>$ }};
\node[below] at (down) {{\tiny $\left|0\right>$}};
\labelLatLon[labelmark=false]{d}{15}{90}
\node at (d) {\color{gray}\fontsize{0.15cm}{1em}\selectfont $60^\circ$};
\labelLatLon[labelmark=false]{d2}{5}{78}
\end{blochsphere}
\end{scope}
\begin{scope}[shift={(4,0)}]
\begin{blochsphere}[radius=1.5 cm,tilt=15,rotation=-20,nested=true]
\drawBall
\drawBallGrid[style={draw,opacity=0.3}]{30}{30}
\drawGreatCircle[style={dashed}]{-60}{0}%{0}
\drawGreatCircle[style={dashed}]{60}{0}%{0}
\drawRotationLeft[scale=1.3,style={red}]{-60}{0}{0}{15}
\drawRotationRight[scale=1.3,style={red}]{60}{0}{0}{15}
\node at (-0.8,1.9) {\textcolor{red}{\tiny $J_{12}(t)$}};
\node at (1.1,1.8) {\textcolor{red}{\tiny $J_{23}(t)$}};
\labelLatLon{up}{90}{0}
\labelLatLon{down}{-90}{90}
\node[above] at (up) {{\tiny $\left|1\right>$ }};
\node[below] at (down) {{\tiny $\left|0\right>$}};
\labelLatLon[labelmark=false]{d}{15}{90}
\node at (d) {\color{gray}\fontsize{0.15cm}{1em}\selectfont $60^\circ$};
\labelLatLon[labelmark=false]{d2}{5}{78}
\end{blochsphere}
\end{scope}
\end{tikzpicture}
\end{document}
答案2
我认为该nested
选项还有另一个我不太明白的含义。在上面的代码中,;
在封闭的\node
宏后添加一个,然后删除该nested
选项(或将其设置为false
)。
然而,嵌套并不是一个好主意tikzpictures
(blochsphere
本质上就是一个好主意)。如果你真的想在 Ti 里面放置复杂的东西钾Z 节点,您可能应该使用savebox
用于存储:
\documentclass[border=10pt]{standalone}
\usepackage{blochsphere}
\newsavebox{\blochA}
\begin{lrbox}{\blochA}
\begin{blochsphere}[radius=1.5 cm,tilt=15,rotation=-20]
\drawBallGrid[style={opacity=0.3}]{30}{30}
\drawGreatCircle[style={dashed}]{-60}{0}{0}
\drawGreatCircle[style={dashed}]{60}{0}{0}
\drawRotationLeft[scale=1.3,style={red}]{-60}{0}{0}{15}
\drawRotationRight[scale=1.3,style={red}]{60}{0}{0}{15}
\node at (-0.8,1.9) {\textcolor{red}{\tiny $J_{12}(t)$}};
\node at (1.1,1.8) {\textcolor{red}{\tiny $J_{23}(t)$}};
\labelLatLon{up}{90}{0};
\labelLatLon{down}{-90}{90};
\node[above] at (up) {{\tiny $\left|1\right>$ }};
\node[below] at (down) {{\tiny $\left|0\right>$}};
\labelLatLon[labelmark=false]{d}{15}{90};
\node at (d) {\color{gray}\fontsize{0.15cm}{1em}\selectfont $60^\circ$};
\labelLatLon[labelmark=false]{d2}{5}{78};
\end{blochsphere}
\end{lrbox}
\begin{document}
\begin{tikzpicture}
\node[fill=red!10] at (0,0) {\usebox{\blochA}};
\end{tikzpicture}
\end{document}