
Я использую 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 width
(не для minimum width
); тогда align=<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}
Я также внес некоторые упрощения в исходный код, удалив некоторые (очевидно ненужные) узлы.