![尽管“居中”命令,tikzpicture 也不在中心](https://linux22.com/image/459472/%E5%B0%BD%E7%AE%A1%E2%80%9C%E5%B1%85%E4%B8%AD%E2%80%9D%E5%91%BD%E4%BB%A4%EF%BC%8Ctikzpicture%20%E4%B9%9F%E4%B8%8D%E5%9C%A8%E4%B8%AD%E5%BF%83.png)
这是我的代码:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}
\usepackage{qcircuit}
\usepackage{physics}
\usepackage{tabularx}
\usepackage{listings}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{tikz}
\usetikzlibrary{decorations.text}
\usepackage[percent]{overpic}
\usepackage{mwe}
\usetikzlibrary{
arrows,
calc,
chains,
decorations,
decorations.text,
decorations.pathmorphing,
matrix,
positioning,
shapes,
tikzmark,
fit
}
\usepackage{circledsteps}
\NewDocumentCommand{\Clock}{O{1cm}O{\large}O{cyan}}{%
\def\radius{#1}%
\begin{tikzpicture}[line cap=rect,line width=0.055*\radius]
\filldraw [fill=#3] (0,0) circle [radius=\radius];
\foreach \angle [count=\xi] in {60,30,...,-270}
{
\draw[line width=1pt] (\angle:0.9*\radius) -- (\angle:\radius);
\node[font=#2] at (\angle:0.68*\radius) {\textsf{\xi}};
}
\foreach \angle in {0,90,180,270}
\draw[line width=0.04*\radius] (\angle:0.82*\radius) -- (\angle:\radius);
\draw (0,0) -- (120:0.4*\radius);
\draw (0,0) -- (90:0.5*\radius);
\end{tikzpicture}%
}
\begin{figure}[H]
\centering
%\begin{equation}
%\begin{aligned}
U =
\begin{tikzpicture}[baseline]{
\node[rectangle,draw=red,anchor=base,text width=2cm, label= below:text]
{$e^{-i \Circled[outer color=green]{\gamma_e B_0} S_z t}$
\quad\Clock[0.9 cm][\footnotesize][green]
};
\hspace{2.3cm}
\node[rectangle,draw=red,anchor=base,text width=2cm, label= below:text2]
{$e^{-i \Circled[outer color=pink]{\gamma_n B_0} I_{z1} t}$
\quad\Clock[0.9 cm][\footnotesize][pink]
};
\hspace{2.3cm}
\node[rectangle,draw=red,anchor=base,text width=2cm, label= below:text2]
{$e^{-i \Circled[outer color=orange]{\gamma_n B_0} I_{z2} t}$
\quad\Clock[0.9 cm][\footnotesize][orange]
};
\hspace{2.3cm}
\node[rectangle,draw=red,anchor=base,text width=2cm, label= below:text2]
{$e^{-i \Circled[outer color=yellow]{A_1} S_zI_{z1} t}$
\quad\Clock[0.9 cm][\footnotesize][yellow]
};
\hspace{2.3cm}
\node[rectangle,draw=red,anchor=base,text width=2cm, label= below:text2]
{$e^{-i \Circled[outer color=cyan]{A_1} S_zI_{z1} t}$
\quad\Clock[0.9 cm][\footnotesize][cyan]
};
}
\end{tikzpicture}
%\end{aligned}
%\end{equation}
\caption{Caption}
\label{fig:trying}
\end{figure}
作为输出,我的图像未居中。它从中心开始,一直到页面的右端。我试图找到一种方法来使整个图像居中,而不是从中心开始。但是,我无法做到。有人知道怎么做吗?
答案1
将 tikzpictures 嵌套到其他 tikzpictures 的节点中几乎从来都不是一个好主意。
相反,您可以使用\fcolorbox
来创建红色框:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.text}
\usepackage[percent]{overpic}
\usepackage{mwe}
\usetikzlibrary{
arrows,
calc,
chains,
decorations,
decorations.text,
decorations.pathmorphing,
matrix,
positioning,
shapes,
tikzmark,
fit
}
\usepackage{circledsteps}
\usepackage{amsmath}
\usepackage{float}
\begin{document}
\NewDocumentCommand{\Clock}{O{1cm}O{\large}O{cyan}}{%
\def\radius{#1}%
\begin{tikzpicture}[line cap=rect,line width=0.055*\radius]
\filldraw [fill=#3] (0,0) circle [radius=\radius];
\foreach \angle [count=\xi] in {60,30,...,-270}
{
\draw[line width=1pt] (\angle:0.9*\radius) -- (\angle:\radius);
\node[font=#2] at (\angle:0.68*\radius) {\textsf{\xi}};
}
\foreach \angle in {0,90,180,270}
\draw[line width=0.04*\radius] (\angle:0.82*\radius) -- (\angle:\radius);
\draw (0,0) -- (120:0.4*\radius);
\draw (0,0) -- (90:0.5*\radius);
\end{tikzpicture}%
}
\begin{figure}[H]
\centering
U =
\parbox{2.5cm}{%
\centering%
\fcolorbox{red}{white}{\parbox{2.3cm}{%
\centering
$e^{-i \Circled[outer color=green]{A1} \text{something} t}$
\Clock[0.9cm][\footnotesize][green]
}}
Text 1
}
\parbox{2.5cm}{%
\centering%
\fcolorbox{red}{white}{\parbox{2.3cm}{%
\centering
$e^{-i \Circled[outer color=pink]{\gamma_n B_0} I_{z1} t}$
\Clock[0.9cm][\footnotesize][green]
}}
Text 2
}
\caption{Caption}
\label{fig:trying}
\end{figure}
\end{document}