Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to style a bunch of nodes using a complex Tikz style generalStyle, defined as

\tikzstyle{generalStyle}=[draw,... lots of options here..., text width=50pt]

Now, the design of an illustration is never as perfectly regular as a code, and I want to make one exception: One node must be styled exactly like the others, except that its content must be displayed without line-breaks. In other words, I want to locally cancel the text width.

I have tried the usual suspects, including:

\node[generalStyle, text width=none] {A long text};
\node[generalStyle, text width=0]    {A long text};
\node[generalStyle, text width=-1]   {A long text};

but none of them work (1st=>Error, 2nd and 3rd are interpreted literally).

How can I cancel the text width styling option in TikZ?

Update: As pointed out by user4035 below, the following will work perfectly

\node[generalStyle, text width=]   {A long text};

Here is a complete example:

\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}

and the output of its compilation:

Use case for a post-facto cancellation of text width in TikZ

share|improve this question

1 Answer 1

up vote 2 down vote accepted

I used text width= as the property for the node, whose text width you want to disable, and it worked:

\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}
share|improve this answer
    
Ouch! Just when I thought I had tried it all :) Thanks a lot! –  Yann Ponty Jan 7 at 3:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.