文本未在节点内呈现

文本未在节点内呈现

在我的文档中,我有一个使用 tikzpicture 的图表,它显示几个框,框的边框内有一些描述性文字。到目前为止,我一直遇到格式问题,尤其是当我引入换行符时,格式问题尤其严重:

\documentclass[letterpaper,oneside,10pt]{report}
\usepackage[USenglish]{babel}
\usepackage{tikz}
\usetikzlibrary{calc,positioning,shapes,decorations.pathreplacing}

\tikzset{
myStyle/.style={draw, rectangle, text height=3pt, text depth=13pt,
  align=center,fill=gray!30}
}
\pagestyle{empty}

\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[node distance=-\pgflinewidth]
\node[myStyle] (a) {line one\\line two};
\node[myStyle,right=of a] (b) {command};
\end{tikzpicture}
\end{figure}

\end{document}

我正在尝试使用上述代码渲染在节点框中垂直居中的文本。(如果代码示例可以变得更简洁,请编辑)运行时,文本当前不会在阴影框内渲染:

电流输出

我需要使用什么来使文本在框内垂直居中?阅读完这个问题后TikZ 节点中的手动/自动换行和文本对齐我怀疑问题出在我的风格上,但我不确定该做哪些改变。

答案1

您的text depthtext height值太短。最好设置一个minimum height

\documentclass[letterpaper,oneside,10pt]{report}
\usepackage[USenglish]{babel}
\usepackage{tikz}
\usetikzlibrary{calc,positioning,shapes,decorations.pathreplacing}

\tikzset{
myStyle/.style={draw, rectangle,minimum height=2.5\baselineskip,
  align=center,fill=gray!30}
}
\pagestyle{empty}

\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[node distance=-\pgflinewidth]
\node[myStyle] (a) {line one\\line two};
\node[myStyle,right=of a] (b) {command};
\end{tikzpicture}
\end{figure}

\end{document}

在此处输入图片描述

相关内容