tikz-rectangle 中的多行文本

tikz-rectangle 中的多行文本

我正在尝试使用 tikz 来(重新)制作下图: 在此处输入图片描述

但似乎无法将多行文本插入矩形。我尝试了 \newline, \\和 数组,但没有成功。还能做什么?

答案1

尝试这个:

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

结果

结果

答案2

@AdamLiter 已经以出色的方式解决了这个问题——https://tex.stackexchange.com/a/124114/197451-- 链接处的讨论显示varwidth这是最佳选择

当然,你可以看看其他可用的选项,例如

文本宽度或者\或者大批或者 表格

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

答案3

在 TikZ 中,包含文本的框称为node。要获得包含多条线的节点,只需使用参数 选择这些线的对齐方式(左、右、居中)align=center。在这里,我已对齐并居中了最右边的节点(descrittivo ...)。我开始制作此图表是为了给您一个起点。如果您有任何疑问,我愿意倾听。

截屏

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

相关内容