我想要将下划线与 tikz 数组内的其他文本对齐,但它显示在框的中间,如下图所示,并且可能与连字符混淆:
这是我的代码:
\begin{tikzpicture}[
% -{Stealth[length = 2.5pt]},
start chain = going right,
node distance = 0pt,
Array/.style={draw, minimum width=2em, minimum height=2em,
outer sep=0pt, on chain},
]
\node [Array] (1) {\texttt{A}};
\node [Array] (2) {\texttt{\_}};
\node [Array] (3) {\texttt{B}};
\end{tikzpicture}
答案1
作为评论中建议的替代\strut
,您可以设置text height
。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{chains}
\begin{document}
\begin{tikzpicture}[
% -{Stealth[length = 2.5pt]},
start chain = going right,
node distance = 0pt,
Array/.style={draw, minimum width=2em, text height=1.25ex, minimum height=2em,
outer sep=0pt, on chain},
]
\node [Array] (1) {\texttt{A}};
\node [Array] (2) {\texttt{\_}};
\node [Array] (3) {\texttt{B}};
\end{tikzpicture}
\end{document}
答案2
很好的 @CarLaTeX 答案(+1)的(非常)小的变化 - 定义为所有节点的通用(略有不同)样式:
\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{chains}
\begin{document}
\begin{tikzpicture}[
node distance = 0pt,
start chain = going right,
nodes = {draw, minimum width=2em, outer sep=0pt,
text height=1.75ex, text depth=0.25ex,
font=\ttfamily, on chain},
]
\node (1) {A};
\node (2) {\_};
\node (3) {B};
\end{tikzpicture}
\end{document}