答案1
默认情况下tikz
将节点对齐中心围绕着它们的盒子。
\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}
\node[draw,anchor=center] at (0,0) {d};
\node[draw,anchor=center] at (0.5,0) {s};
\end{tikzpicture}
\end{document}
将节点对齐根据,只需选择节点库作为anchor
。
\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}
\node[draw,anchor=base] at (0,0) {d};
\node[draw,anchor=base] at (0.5,0) {s};
\end{tikzpicture}
\end{document}
\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}
\node[anchor=base] at (0,0) {d};
\node[anchor=base] at (0.5,0) {s};
\end{tikzpicture}
\end{document}
请参阅手册第 227 页。
补充回答@bmv 的问题
使用文本高度参数调整框中文本的高度。
\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node[draw,anchor=base,text height=0pt] at (0,0) {d};
\node[draw,anchor=base,text height=0pt] at (0.5,0) {s};
\end{tikzpicture}
\begin{tikzpicture}
\node[draw,anchor=base,text height=5pt] at (0,0) {d};
\node[draw,anchor=base,text height=5pt] at (0.5,0) {s};
\end{tikzpicture}
\begin{tikzpicture}
\node[draw,anchor=base,text height=10pt] at (0,0) {d};
\node[draw,anchor=base,text height=10pt] at (0.5,0) {s};
\end{tikzpicture}
\end{document}