我最近一直在尝试用 LaTeX 格式化我的科学作业。我尝试使用 Tikz 制作流程图,成功了,但发现流程图稍微偏离了页面的右侧。请不要太挑剔,因为我很快就学会了 LaTeX 来完成我的科学作业。
Tikz 图表和序言的代码:
前言:
\documentclass[titlepage]{report}
\title{Year 9 Science Assignment}
\author{James Balajan}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[
backend=biber,
style=alphabetic,
sorting=ynt
]{biblatex}
\addbibresource{Science.bib}
\usepackage{tikz}
\usepackage{hyperref}
\usetikzlibrary{shapes.geometric, arrows, decorations.pathreplacing, decorations.pathmorphing}
\tikzstyle{arrow} = [thick,->,>=stealth]
\tikzstyle{default} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=white!30]:
图表:
\begin{tikzpicture}[node distance=2cm]
\node (1) [default] {Sodium Potassium mixture comes into contact with water};
\node (2) [default, below of=1] {Electrons released, positively charged atoms remain};
\node (3) [default, below of=2] {Positvely atoms are pushed away from each other due to electrostatic forces, creating spikes, exposing new electrons to the water};
\node (4) [default, below of=3] {Other electrons leave the atoms leaving more positively charged atoms, creating more spikes};
\node (5) [default, below of=4] {The cycle of electrons escaping leaving positively charged atoms continues till it eventually builds up enough heat to ignite the hydrogen gas};
\draw [arrow] (1) -- (2);
\draw [arrow] (2) -- (3);
\draw [arrow] (3) -- (4);
\draw [arrow] (4) -- (5);
\end{tikzpicture}
答案1
您可以添加定义文本如何对齐的样式(左对齐、右对齐等也是可以的align=center
)default
然后可以手动在文本中添加换行符,或者可以定义一个text width=8cm
,以便 TikZ 根据该宽度换行。
以下是一个例子
\documentclass[tikz]{standalone}
\tikzset{arrow/.style = {thick,->,>=stealth},
default/.style = {rectangle, minimum width=3cm, minimum height=1cm, align=center,text width=8cm, draw=black, fill=white!30}
}
\begin{document}
\begin{tikzpicture}[node distance=2cm]
\node (1) [default] {Sodium Potassium mixture comes into contact with water};
\node (2) [default, below of=1] {Electrons released, positively charged atoms remain};
\node (3) [default, below of=2] {Positvely atoms are pushed away from each other due to electrostatic forces, creating spikes, exposing new electrons to the water};
\node (4) [default, below of=3] {Other electrons leave the atoms leaving more positively charged atoms, creating more spikes};
\node (5) [default, below of=4] {The cycle of electrons escaping leaving positively charged atoms continues till it eventually builds up enough heat to ignite the hydrogen gas};
\draw [arrow] (1) -- (2);
\draw [arrow] (2) -- (3);
\draw [arrow] (3) -- (4);
\draw [arrow] (4) -- (5);
\end{tikzpicture}
\end{document}