我想垂直对齐尖括号内的 TikZ 图像。我无法通过向环境或或命令添加yshift
参数来实现此目的。knot
\draw
\strand
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes, decorations, arrows.meta, decorations.markings, bending, knots, hobby, spath3, intersections}
\newcommand{\KP}[1]{%
\begin{tikzpicture}[baseline=-\dimexpr\fontdimen22\textfont2\relax]
#1
\end{tikzpicture}%
}
\newcommand{\KPthirtyoneone}{
\KP{
\begin{knot}[flip crossing=2, consider self intersections = true, clip width = 5, ignore endpoint intersections=false]
\draw[scale=0.6, line width=0.6pt] (0,1) .. controls (0.5,0.8) .. (1,1);
\strand[scale=0.6, line width=0.6pt, looseness=1.4] (0,0) to [out=0,in=0] (0.5,0.7) to [out=180,in=180] (1,0);
\end{knot}
}
}
\begin{document}
\[\Bigl\langle\hspace{-6pt}\vcenter{\hbox{\KPthirtyoneone}}\hspace{-6pt}\Bigr\rangle\]
\end{document}
我从中摘取了一些代码https://tex.stackexchange.com/a/306010/128462。它产生以下输出:
如何让图像在括号内垂直居中?
答案1
这里的一个问题是,tikzpicture 的边界框可能比其所有内容都大,这仅仅是因为 TikZ 计算边界框的方式 - 它采用“快速简便”的算法,而不是精确的算法。这与 knots 库无关。knots 库所做的加剧了这种影响,因为它对曲线进行了大量修改,而这些修改都会增加边界框的大小。通常这无关紧要,但由于您的图表非常小,因此会产生影响。
处理这个问题最简单的方法是明确告诉 TikZ 边界框应该是什么。这里,这很简单,因为有一个明显的包含矩形。一旦我们完成了这一点,TikZ 就会忽略边界框方面的所有其他内容,然后您可以使用任何您喜欢的方法将图片居中,无论是通过键baseline
还是仅使用vcenter
原始代码中的命令。这vcenter
很简单,因为不必明确计算,而选项baseline
为您提供了更多控制。
\documentclass{article}
%\url{https://tex.stackexchange.com/q/684222/86}
\usepackage{tikz}
\usetikzlibrary{
shapes,
% decorations, % <-- loaded by decorations.markings
arrows.meta,
decorations.markings,
bending,
knots,
hobby,
% spath3, % <-- loaded by knots
% intersections % <-- loaded by knots
}
\newcommand{\KP}[1]{%
\begin{tikzpicture}%[baseline=-\dimexpr\fontdimen22\textfont2\relax]
#1
\end{tikzpicture}%
}
\newcommand{\KPthirtyoneone}{
\KP{
\useasboundingbox (0,0) rectangle (.6,.6);
\begin{knot}[
flip crossing=2,
consider self intersections = true,
clip width = 5,
ignore endpoint intersections=false,
]
\draw[scale=0.6, line width=0.6pt] (0,1) .. controls (0.5,0.8) .. (1,1);
\strand[scale=0.6, line width=0.6pt, looseness=1.4] (0,0) to [out=0,in=0] (0.5,0.7) to [out=180,in=180] (1,0);
\end{knot}
}
}
\begin{document}
\[\Bigl\langle\vcenter{\hbox{\KPthirtyoneone}}\Bigr\rangle\]
\end{document}
答案2
像这样?
(\alpha
并\beta
添加可以看到基线)
- 我认为的内容
\KP
可以是任何具有不同基线位置的图片,我建议添加tikzpicture
基线设置的选项 - 我会删除
\hspace{-6pt}\vcenter{\hbox{
在\hspace{-6pt}\vcenter{\hbox{
方程中插入的内容,而是使用\KPthirtyoneone
基线定位的手动设置:
\documentclass[margin=3mm, varwidth]{standalone}
%\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
bending,
decorations, decorations.markings,
hobby,
intersections,
knots,
shapes, spath3}
\newcommand{\KP}[2]{%
\begin{tikzpicture}[baseline=#1,
]
#2
\end{tikzpicture}%
}
\newcommand{\KPthirtyoneone}%
{
\KP{1.4ex}{%
\begin{knot}[flip crossing=2, consider self intersections = true,
clip width = 3, ignore endpoint intersections=false]
\draw[scale=0.6, line width=0.6pt]
(0,1) .. controls (0.5,0.8) .. (1,1);
\strand[scale=0.6, line width=0.6pt, looseness=1.4]
(0,0) to [out=0,in=0] (0.5,0.7) to [out=180,in=180] (1,0);
\end{knot}
}
}
\begin{document}
\[
\alpha
\Bigl\langle
\beta
\KPthirtyoneone
\Bigr\rangle
\]
\end{document}