LaTeX TikZ节点文本垂直对齐问题:如何添加参数修正因下伸字母导致的文字未对齐情况
解决TikZ节点文本垂直对齐问题
遇到这种因字母下伸部分(比如"depot"里的"p")导致的垂直对齐偏差,有两种实用方案可以选择:
方案1:基于文本基线对齐(排版标准对齐)
把节点的锚点从anchor=west改成anchor=base west,这样两个节点会以文本的基线(也就是"o""t"这类无下伸字母的底部)作为对齐基准,完全符合专业排版的规范:
\begin{figure} \centering \begin{tikzpicture} \node[anchor=base west] at (0,0) {depot}; \node[anchor=base west] at (2,0) {satellite}; \end{tikzpicture} \end{figure}
方案2:基于视觉中心对齐
如果希望两个文本的视觉中心处在同一水平线上,可以给两个节点统一设置固定的text height和text depth,强制让它们的文本框尺寸一致,这样anchor=west就能实现完美的中心对齐:
\begin{figure} \centering \begin{tikzpicture} \node[anchor=west, text height=1.2ex, text depth=0.3ex] at (0,0) {depot}; \node[anchor=west, text height=1.2ex, text depth=0.3ex] at (2,0) {satellite}; \end{tikzpicture} \end{figure}
你可以根据当前字体大小调整1.2ex和0.3ex的数值,找到最贴合需求的视觉效果。
内容的提问来源于stack exchange,提问作者Student NL
相关产品推荐
相关产品推荐

