我想使用复杂的 Tikz 样式来设置一组节点的样式generalStyle
,定义为
\tikzstyle{generalStyle}=[draw,... lots of options here..., text width=50pt]
现在,插图的设计永远不会像代码那样完美规则,我想做一个例外:一个节点的样式必须与其他节点完全相同,但其内容必须无换行显示。换句话说,我想在本地取消这text width
。
我已经尝试过普通嫌犯, 包括:
\node[generalStyle, text width=none] {A long text};
\node[generalStyle, text width=0] {A long text};
\node[generalStyle, text width=-1] {A long text};
但它们都不起作用(第一个 => 错误,第二个和第三个按字面意思解释)。
如何取消text width
TikZ 中的样式选项?
更新:正如用户4035下面,下面将完美地工作
\node[generalStyle, text width=] {A long text};
这是一个完整的例子:
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{matrix,positioning}
\begin{document}
\begin{tikzpicture}
\tikzstyle{generalStyle}=[draw,rounded corners=3pt, text width=50pt,text centered]
\matrix[matrix of nodes,nodes=generalStyle] (a) {
x & \ldots & |[fill=blue!20]| I'd like to see the complete label of this node over a single line (no wrapping)
\\};
\matrix[matrix of nodes,nodes=generalStyle, below=of a.south west, anchor=north west] (b) {
x & \ldots & |[fill=blue!20, text width=150pt]| I could extend the node width\ldots
\\};
\matrix[matrix of nodes,nodes=generalStyle, below=of b.south west, anchor=north west] (c) {
x & \ldots & |[fill=blue!20, text width=150pt]| \ldots but then it would not work if the text changes. It would be much better to locally {\bfseries unset} the {\ttfamily text width} option: How to do that?
\\};
\end{tikzpicture}
\end{document}
及其编译的输出:
答案1
我将其用作text width=
要禁用其文本宽度的节点的属性,并且它起作用了:
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{matrix,positioning}
\begin{document}
\begin{tikzpicture}
\tikzstyle{generalStyle}=[draw,rounded corners=3pt, text width=50pt,text centered]
\matrix[matrix of nodes,nodes=generalStyle] (a) {
x & \ldots & |[fill=blue!20,text width=]| I'd like to see the complete label of this node over a single line (no wrapping)
\\};
\matrix[matrix of nodes,nodes=generalStyle, below=of a.south west, anchor=north west] (b) {
x & \ldots & |[fill=blue!20, text width=150pt]| I could extend the node width\ldots
\\};
\matrix[matrix of nodes,nodes=generalStyle, below=of b.south west, anchor=north west] (c) {
x & \ldots & |[fill=blue!20, text width=150pt]| \ldots but then it would not work if the text changes. It would be much better to locally {\bfseries unset} the {\ttfamily text width} option: How to do that?
\\};
\end{tikzpicture}
\end{document}