TikZ 中的节点是否自动换行?

TikZ 中的节点是否自动换行?

我正在TikZ制作一个流程图来逐步演示我的方案。我注意到节点中的自动换行功能不是自动的。也就是说,一行可能非常长,横跨整个页面。

MWE 如下。

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

渲染结果为 在此处输入图片描述

我现在的解决方法是手动插入新行,但是很麻烦。

因此,我希望找到实现节点自动换行的优雅方法TikZ

答案1

您没有获得预期的自动文本换行功能align=<option>,因为您正在设置键。为(而不是)minimum width提供适当的值;然后将提供所需的对齐方式:text widthminimum widthalign=<option>

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

在此处输入图片描述

我还对原始代码做了一些简化,抑制了一些(显然不必要的)节点。

相关内容