2

I have recently been trying to format my science assignment in LaTeX. I tried to make a flowchart using Tikz, succeeding but only to find that the flowchart went slightly off the right of the page. Please do not be too critical for I picked up LaTeX quickly to do my science assignment.

Code for Tikz Diagram and Preamble:

Preamble:

\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]:

Diagram:

\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
  • Welcome to TeX.SX! Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}.
    – Rmano
    Commented Sep 21, 2016 at 9:31

1 Answer 1

2

You can add align=center to the default style which defines how the text should be aligned (left, right etc. is also possible)

Then either add line breaks manually to the text, or you can define a text width=8cm so that TikZ will break the lines according to that width.

Here is an example

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

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .