Take the 2-minute tour ×

I'm trying to make a try, similar to the one visible here.

enter image description here

As it is seen in the example, the writer wrote Bag 1 $4W, 3B$ and got it in two different lines. I don't want that; I want the lines to be complete (I'm having my growing direction upwards, so it's okay). How do I do that?

share|improve this question
Welcome to TeX.SE. If you add text width=<length> and the <length> is large enough to accommodate the text it should show up on one line. –  Peter Grill Dec 29 '11 at 16:36
It would be helpful if you composed a fully compilable MWE that illustrates the problem as opposed to linking to an example that is not very minimal. –  Peter Grill Dec 29 '11 at 16:39
Thank you for your answer. You're right about the MWE, I will keep that in mind. –  Joe Dec 29 '11 at 16:46
add comment

1 Answer

up vote 4 down vote accepted

As you can see, the example uses a text width option for the bag style. Removing this will keep the text on a single line. Then you can also remove the alignment (text centered) because it will be a single line. So there will be no need for the style and it can simply be removed and the bag nodes no longer need bag in their option list.

Edit: To address the issue of not being able to break lines where you desire without the text width being present, consider the following solutions offered by the TikZ manual (on page 180).

  1. Use an environment that allows multi-line aligned text to be produced. The example given in the manual (and, in my opinion, the most useful one) is the tabular environment.
  2. Use the align=... option. You can use align=center or align=left for instance. Then you can use \\ to break lines as you would in regular text.
  3. Use the text width=... option. The problem with this option is, that the node will always have this width, regardless of whether or not the contents actually is this wide. So in order to use this option you need somewhat detailed knowledge in advance of where the breaks are going to be and how big you want your nodes to be.

If all you need is multiple lines, option 2 seems most suited for your purpose, since it will allow you to place linebreaks without having to consider the dimensions of your node. For more complicated situations option 1 might be preferable. When you don't know much about the content and don't really care about how it is presented, as long as it fits in the x cm slot you have allocated for it, option 3 is the way to go.

share|improve this answer
Wow, I'm embarrassed, how could I've missed that ... Thanks! Well there's now one problem: I can't begin a new line if I wanted to... With the text width option I could use `\`, but not here. –  Joe Dec 29 '11 at 16:38
@Joe: You should try to wrap the node contents in a \parbox{<width>}{<stuff>} where <width> is the same as the value of <text width>. –  Werner Dec 29 '11 at 17:03
@Joe: See the updated answer –  Roelof Spijker Dec 29 '11 at 17:15
Thanks, you've helped me a lot! –  Joe Dec 29 '11 at 20:06
add comment

Your Answer


