当将节点彼此相邻放置时,一些节点带有数学符号,一些节点不带有数学符号,文本的垂直对齐最终看起来在两个节点之间不匹配(见下面的示例)。有没有一种简单的方法可以将每行文本的底线彼此对齐?即,好像完整的行是:“带有 [] Text 的文本”和“一些不带有 Math_f [] 的文本”。
示例图片:
最小示例:
\documentclass[]{article}
\usepackage{tikz}
\begin{document}
\tikzset{mystyle/.style={rectangle, text centered, inner sep=5pt, text width=2cm, draw=black}}
\begin{tikzpicture}[node distance=3cm]
\node (node1) [mystyle] {Text with some $Math_f$};
\node (node2) [mystyle, right of=node1] {Text without};
\end{tikzpicture}
\end{document}
答案1
您可以按照您创建的样式为文本添加深度和高度。
\tikzset{mystyle/.style={rectangle, align=center, inner sep=5pt,
text width=2cm,text depth=1.5em,text height=1em, draw=black}}
\documentclass[]{article}
\usepackage{tikz}
\begin{document}
\tikzset{mystyle/.style={rectangle, align=center, inner sep=5pt, text width=2cm,text depth=1.5em,text height=1em, draw=black}}
\begin{tikzpicture}[node distance=3cm]
\node (node1) [mystyle] {Text with some $Math_f$};
\node (node2) [mystyle, right of=node1,] {Text without};
\end{tikzpicture}
\end{document}
答案2
使用 \vphantom
\documentclass[]{article}
\usepackage{tikz}
\begin{document}
\tikzset{mystyle/.style={rectangle, text centered, inner sep=5pt, text width=2cm, draw=black}}
\begin{tikzpicture}[node distance=3cm]
\node (node1) [mystyle] {Text with some $Math_f$};
\node (node2) [mystyle, right of=node1] {Text without \vphantom{$Math_f$}};
\end{tikzpicture}
\end{document}