8

I am using TikZ to make a flow chart demonstrating my scheme step by step. I notice that the word wrapping is not automatic in a node. That is, the line can be extremely long across the whole page.

The MWE is as follows.

\documentclass[a4paper]{article}

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[colorinlistoftodos]{todonotes}
\usepackage{tikz}

\title{Your Paper}

\begin{document}
\maketitle

\begin{tikzpicture}[block/.style={draw, fill=white, rectangle, minimum width=0.95*\columnwidth, anchor=west}, font=\small]
    \node[block, minimum width=0.95\columnwidth, minimum height=1cm, fill=white, opacity=1, text opacity=1, rounded corners, thick](step1) at (0,0){};
    \node[below=0cm of step1.north, align=left]{\textbf{Step 1}: This is Step one, which is a very very very long sentence. I really hate it when it does not automatically do the wrapping.};
    \node[block, minimum width=0.95\columnwidth, minimum height=1cm, below right=0.9cm and 0cm of step1.south, fill=white, opacity=1, text opacity=1, rounded corners, thick](step2) at (0,0){};
    \node[below=0cm of step2.north, align=left]{\textbf{Step 2}: Step 2 is cute and short.};
    \draw[-stealth](step1.south)--(step2.north)node[pos=0.5, above=0cm]{};
\end{tikzpicture}


\end{document}

which renders as enter image description here

My current workaround is to manually insert new line, which is very troublesome.

I, therefore, wish to find an elegant way to achieve the automatic word wrapping in a node of TikZ.

1
  • 2
    align=left to the node options and set a text width. Mar 27, 2014 at 2:36

1 Answer 1

9

You were not getting the expected automatic text wrapping that one would expect using align=<option>, because you were setting the minimum width key. Provide an appropriate value for text width (not for minimum width); then align=<option> will provide the desired alignment:

\documentclass[a4paper]{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[colorinlistoftodos]{todonotes}
\usepackage{tikz}

\title{Your Paper}

\begin{document}
\maketitle

\begin{tikzpicture}[
block/.style={
  draw, 
  fill=white, 
  text width=0.95*\columnwidth, 
  anchor=west,
  minimum height=1cm,
  rounded corners 
  }, 
font=\small
]
\node[block,align=left]
  (step1)
  {\textbf{Step 1}: This is Step one, which is a very very very long sentence. I really hate it when it does not automatically do the wrapping.};
\node[block,below=2cm of step1.north,align=center]
  (step2)
  {\textbf{Step 2}: Step 2 is cute and short.};
\draw[-stealth]
  (step1.south)--(step2.north)node[pos=0.5, above=0cm]{};
\end{tikzpicture}

\end{document}

enter image description here

I also made some simplifications to the original code, suppressing some (apparently unnecessary) nodes.

3
  • This is so awesome, sir. Exactly what I want. Thank you so much! Mar 27, 2014 at 2:40
  • 1
    @FarticlePilter You're welcome! I updated my answer introducing some simplifications that might be of interest for you. Of course, some of the changes I made were just based on the example posted; you can decide if my changes are what you really need :) Mar 27, 2014 at 2:49
  • I cannot thank you more, sir. It goes far beyond an answer. Thanks!! I should acknowledge you in my paper! LOL Mar 27, 2014 at 3:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .