我创建了这样的图片。如何将它们沿中间线对齐?
我的代码是这样的:
\begin{center}
\begin{tikzpicture}
%some codes to drat the first picture.
\end{tikzpicture}
\quad $\xrightarrow{\text{stabilization}}$ \quad
\begin{tikzpicture}
%some codes to drat the second picture.
\end{tikzpicture}
\end{center}
当时的画面是这样的:
但我希望第一个和箭头稍微向上,以便它们与第三个的垂直方向的中线对齐。
答案1
看看下面的内容是否能解决您的问题:
\begin{center}
\tikzset{every picture/.append style={baseline=(current bounding box.center)}} % <---
\begin{tikzpicture}
%some codes to drat the first picture.
\end{tikzpicture}
\quad $\xrightarrow{\text{stabilization}}$ \quad
\begin{tikzpicture}
%some codes to drat the second picture.
\end{tikzpicture}
\end{center}
答案2
我建议将所有内容放在 1 个 tikzpicture 中,并使用范围。
\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[->] (-1,0)--(1,0) node[midway,above]{stabilization};
\begin{scope}[xshift=-2.5cm]
\fill (0,0) circle(3pt) node[above=1mm]{$p_i$}
(.5,0) circle(1.5pt)
(-.5,0) circle(1.5pt)
(-1,0) circle(1.5pt);
\draw (-1.5,0)--(1,0);
\end{scope}
\begin{scope}[xshift=3cm]
\fill (45:.5) circle(1.5pt) node[right=1mm]{$p_i$}
+(45:.5) circle(1.5pt) node[right=1mm]{$p_{n+1}$}
(.5,0) circle(1.5pt)
(-.5,0) circle(1.5pt)
(-1,0) circle(1.5pt);
\draw (-1.5,0)--(1,0) (-135:.7)--(45:1.5);
\end{scope}
\end{tikzpicture}
\end{document}
答案3
两个标准选项是用于\vcenter{\hbox{...}}
垂直居中或进行baseline
适当设置。第一个选项要求您将所有内容都设置在同一个数学组中。
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\begin{document}
$\vcenter{\hbox{\begin{tikzpicture}[bullet/.style={circle,fill,inner sep=#1}]
\draw (-1,0) -- (1,0) node[pos=0.2,bullet=1pt]{}
node[pos=0.4,bullet=1pt]{} node[pos=0.6,bullet=2pt]{} node[pos=0.8,bullet=1pt]{};
\end{tikzpicture}}}\quad
\xrightarrow{\text{stabilization}}\quad
\vcenter{\hbox{\begin{tikzpicture}[bullet/.style={circle,fill,inner sep=#1}]
\draw (-1,0) -- (1,0) node[pos=0.2,bullet=1pt]{}
node[pos=0.4,bullet=1pt]{} node[pos=0.8,bullet=1pt]{};
\draw (0,-0.25) -- (1,0.75) node[pos=0.6,bullet=1pt,label=right:$p_i$]{}
node[pos=0.8,bullet=1pt,label=right:$p_{n+1}$]{};
\end{tikzpicture}}}$
$\vcenter{\hbox{\begin{tikzpicture}[bullet/.style={circle,fill,inner sep=#1}]
\draw (-1,0) -- (1,0) node[pos=0.2,bullet=1pt]{}
node[pos=0.4,bullet=1pt]{} node[pos=0.6,bullet=2pt]{} node[pos=0.8,bullet=1pt]{};
\end{tikzpicture}}}\quad
\xrightarrow{\text{stabilization}}\quad
\begin{tikzpicture}[baseline=-0.1cm,bullet/.style={circle,fill,inner sep=#1}]
\draw (-1,0) -- (1,0) node[pos=0.2,bullet=1pt]{}
node[pos=0.4,bullet=1pt]{} node[pos=0.8,bullet=1pt]{};
\draw (0,-0.25) -- (1,0.75) node[pos=0.6,bullet=1pt,label=right:$p_i$]{}
node[pos=0.8,bullet=1pt,label=right:$p_{n+1}$]{};
\end{tikzpicture}$
\end{document}