考虑下面的例子。为什么文本没有垂直居中?
我该如何让它工作?我想让一个分配给绘制对象的节点工作,因为否则我需要修改我的整个图形 ;-)
平均能量损失
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fit}
\makeatletter
\tikzset{
fitting node/.style={
inner sep=0pt,
fill=none,
draw=none,
reset transform,
fit={(\pgf@pathminx,\pgf@pathminy) (\pgf@pathmaxx,\pgf@pathmaxy)}
},
reset transform/.code={\pgftransformreset}
}
\makeatother
\begin{document}
\begin{tikzpicture}[ultra thick]
\draw [rounded corners=15pt] (0,-2.0) rectangle ++(13.5,1.0) node[fitting node] {\strut Test Title};
\end{tikzpicture}
\end{document}
答案1
带有选项的节点fit
不会将内容居中(顶部图像),因此您可以使用您的解决方案来实现这一点label
(中间图像)或使用标准节点(底部图像):
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fit}
\makeatletter
\tikzset{
fitting node/.style={
inner sep=0pt,
fill=none,
draw=none,
reset transform,
fit={(\pgf@pathminx,\pgf@pathminy) (\pgf@pathmaxx,\pgf@pathmaxy)}
},
reset transform/.code={\pgftransformreset}
}
\makeatother
\begin{document}
\begin{tikzpicture}[ultra thick]
\draw [rounded corners=15pt] (0,-2.0) rectangle ++(13.5,1.0) node[fitting node] {Test Title};
\end{tikzpicture}
\bigskip
\begin{tikzpicture}[ultra thick]
\draw [rounded corners=15pt] (0,-2.0) rectangle ++(13.5,1.0)
node[fitting node, label=center: Test Title]{};
\end{tikzpicture}
\bigskip
\begin{tikzpicture}[
titlebox/.style args = {#1/#2}{%
draw, rounded corners=15pt, ultra thick,
text width=#1, minimum height=#2, align=center}
]
\node[titlebox=135mm/10mm] {Test Title};
\end{tikzpicture}
\end{document}