
我正在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}
我還對原始程式碼進行了一些簡化,取消了一些(顯然不必要的)節點。