4

I would like have a few fixed nodes of size 1cm x 1cm. However, the text inside these nodes should wrap around.

I used the following questions help to figure out about wrapping text. However it doesn't seem to work.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[node distance=1.75cm,auto   , font=\small]

\tikzstyle{block}=[draw, fill=white, text width=1cm, anchor=west,  minimum height=1cm]

 \node [block] [minimum width=1.5cm, minimum height=1.5cm,align=center] (mb0) {MB};
 \node [block] [right of=mb0] (dmem0) {dmem};
 \node [block] [left of=mb0] (imem0) {imem};
 \node [block] [below of=mb0,align=left] (cmemin0) {cmem\_in};
 \node [block] [right of=cmemin0] (dma0) {DMA};
 \node [block] [right of=dma0] (cmemout0) {cmem\_out};

\end{tikzpicture}
\end{document}

However you can see in the picture that the text flows outside the box instead of wrapping around. enter image description here

How do I resolve this situation?

Thanks !

  • You need some hyphenation points in your text. It doesn't know where to break. For example, if I add the text {sectar-ion} in one of your nodes, it wraps at the hyphen. – Steven B. Segletes Apr 15 '14 at 13:28
  • @T.Verron you will see that I have added this option in cmemin0 node, but still the text flows out. – knowledge_seeker Apr 15 '14 at 13:30
  • Oh, right, I was only seeing it in "MB". Sorry, deleting my comment. – T. Verron Apr 15 '14 at 13:31
  • @StevenB.Segletes It works, but what if I don't want hyphen in the text of my node? – knowledge_seeker Apr 15 '14 at 13:31
  • 2
    You can add hyphenation points with \-. It will break the text at that point if need be, otherwise it will be invisible. Still not 100% automatic of course. – T. Verron Apr 15 '14 at 13:42
3

So, several problems are stacking in your case.

First, the hyphenation engine cannot guess what is a correct hyphenation for a word like cmem_in. I am not even sure there is such a correct hyphenation.

In this case, you need to marks the points where the break is allowed with \-.

Second, even for "not so strange" words, like "averylonglongstring", the hyphenation does not happen. The reason is given in this question: the first word of a paragraph is not hyphenated by design.

A suggested workaround is to use \hspace{0pt} before such words. Note that in the MWE, longstring still flows out of the box, that's because it is a "strange word" again.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[node distance=1.75cm,auto   , font=\small]

  \tikzstyle{block}=[draw, fill=white, text width=1cm, anchor=west,  minimum height=1cm]

  \node [block] [minimum width=1.5cm, minimum height=1.5cm,align=center] (mb0) {MB};
  \node [block] [right of=mb0] (dmem0) {dmem};
  \node [block] [left of=mb0,align=left] (imem0) {averylonglongstring};
  \node [block] [below of=mb0,align=left] (cmemin0) {cmem\-\_in};
  \node [block] [right of=cmemin0,align=left] (dma0) {\hspace{0pt}averylonglongstring};
  \node [block] [right of=dma0,align=left,text width=1.5cm] (cmemout0) {cmem\-\_out};

\end{tikzpicture}
\end{document}

enter image description here

1

The correct code that I finally use would be -

\begin{tikzpicture}[node distance=1.85cm,auto, font=\small]

\tikzstyle{block}=[draw, fill=white, text width=1cm, anchor=west, align=center, minimum height=1cm]

 \node [block] [minimum width=1.75cm, minimum height=1.75cm] (mb0) {MB};
 \node [block] [right of=mb0,align=center] (dmem0) {dme m};
 \node [block] [left of=mb0] (imem0) {imem};
 \node [block] [below of=mb0,align=center] (cmemin0) {cme m\_in};
 \node [block] [right of=cmemin0,align=center] (dma0) {DMA};
 \node [block] [right of=dma0,align=center] (cmemout0) {cme m\_out};
\end{tikzpicture}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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