我如何创建节点,以便节点中的每个单词都放入新行?MWE:
\usepackage{tikz} % used instead of adt_web.sty here
\usetikzlibrary{calc, positioning, shapes.multipart}
\begin{tikzpicture}[
every node/.style = {
draw,
fill = gray!10,
shape = rectangle,
rounded corners,
text width = ,
thick}
]
%Nodes
\node[] (n1) {Some text};
\node[] (n2) at ($(n1) + (9,0)$) {Some more text};
\end{tikzpicture}
我想要的是没有连字符文本的动态大小的多行节点。
答案1
如果您觉得需要手动中断文本行的解决方案可以,那么最简单的解决方案可以是:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[
node distance = 4mm,
every node/.style = {draw, thick, rounded corners, fill = gray!10,
align=flush left}, % <---
]
%Nodes
\node (n1) {Some \\ text};
\node (n2) [right=of n1] {Some more \\ text};
\node (n3) [right=of n2] {Some \\ more \\ text};
\end{tikzpicture}
\end{document}
但是,如果你希望这应该自动完成,那么解决方案就不再那么简单了。对于这样的解决方案,你必须等待 LaTeX 大师,他将编写一个宏,将文本中的每个空白替换为\\
...
答案2
您可以使用tabular
。
\documentclass{article}
\usepackage{tikz} % used instead of adt_web.sty here
\usetikzlibrary{calc, positioning, shapes.multipart}
\newcommand{\split}[1]{\begin{tabular}{@{}l@{}}#1\end{tabular}}
\begin{document}
\begin{tikzpicture}[
every node/.style = {
draw,
fill = gray!10,
shape = rectangle,
rounded corners,
thick
},
]
%Nodes
\node[] (n1) {\split{Some \\ text}};
\node[] (n2) at ($(n1) + (4.5,0)$) {\split{Some more \\ text}};
\node[] (n2) at ($(n1) + (9,0)$) {\split{Some \\ more \\ text}};
\end{tikzpicture}
\end{document}