0

I am trying do use tikz to (re-)produce the followning figure: enter image description here

But it seems impossible to insert multiline text into a rectangle. I tried \newline, \\, and array without success. What else can be done?

Torbjørn T.
  • 206,688

3 Answers3

2

Try this:

\draw (1, 0) rectangle  ++(2,1) node[pos=.5, text width=1.8cm] {Descrittivo- \\materiale};

Result

Result

Andrea
  • 21
1

This question already has been resolved in an excellent manner by @AdamLiter at -- https://tex.stackexchange.com/a/124114/197451 -- the discussion at the link shows varwidth as the best choice

You could of course have a look at the other options available such as

text width or \ or array or tabular

\documentclass{article}

\usepackage{tikz}
\usepackage{varwidth}
\usepackage{ragged2e}

\begin{document}

\begin{tikzpicture}
\node (example-varwidth-left) [draw, align=left]{\begin{varwidth}{3cm}This is a 
demonstration text for showing how line breaking works.\end{varwidth}};
\end{tikzpicture}

\begin{tikzpicture}
\node (example-varwidth-right) [draw, align=right]{\begin{varwidth}{3cm}This is a 
demonstration text for showing how line breaking works.\end{varwidth}};
\end{tikzpicture}

\begin{tikzpicture}
\node (example-varwidth-ragged) [draw, align=flush right] {\begin{varwidth} 
{3cm}\RaggedLeft This is a demonstration text for showing how line breaking 
works.\end{varwidth}};
\end{tikzpicture}

\end{document} 
js bibra
  • 21,280
1

With TikZ, a box that contains text is called a node. To have a node with several lines, simply choose the alignment of these lines (left, right, centered) with the parameter align=center. Here, I have aligned and centered the rightmost node (descrittivo ...). I started making this graph to give you a starting point. If you have any questions, I'm all ears.

screenshot

\documentclass[border=5mm]{standalone}

\usepackage{tikz}
\usetikzlibrary{positioning,calc}
\begin{document}
\begin{tikzpicture}
\node[draw] (logico-formale) at (0,0) {logico-formale};
\node[draw](Costtrutivo-formale)[right=of logico-formale]  {Costtrutivo-formale};
\node[draw](Costtrutivo-materiale)[right=of Costtrutivo-formale]  {Costtrutivo-materiale};
\node[draw](descrittivo)[right=of Costtrutivo-materiale.south east,anchor=south west,align=center]  {Descrittivo-\\materiale\\ (empirica)};

% auxiliary node 1
\node (aux1) at ($(logico-formale.east)!.5!(Costtrutivo-formale.west)$){};
\node[draw,above= 1.5cm of aux1] (formale){formale};
\draw (formale.south west)--(logico-formale);
\draw (formale.south east)--(Costtrutivo-formale);

% auxiliary node 2
\node (aux2) at ($(Costtrutivo-formale.east)!.5!(Costtrutivo-materiale.west)$){};
\node[draw,above= 10mm of aux2] (Costtrutivo){Costtrutivo};
\draw (Costtrutivo.south west)--(Costtrutivo-formale);
\draw (Costtrutivo.south east)--(Costtrutivo-materiale);

% auxiliary node 3
\node (aux3) at ($(Costtrutivo-materiale.east)!.5!(descrittivo.west)$){};
\node[draw,above= 1.5cm of aux3] (materiale){materiale};
\draw (materiale.south west)--(Costtrutivo-materiale);
\draw (materiale.south east)--(descrittivo);
\end{tikzpicture}

\end{document}
AndréC
  • 24,137