LaTeX – Create tables using array environment

This note will teach us to how to create arrays, specifically when writing articles in an inline mode on microblogging sites. In simple words, it demonstrates how to create arrays in Latex when it is rendered on the Mathjax javascript framework.

Important keywords used in array environment.

  • The begin{array} command indicates the beginning of an array environment. The curly braces after this command hold the parameters for the array’s columns. These parameters are any combination of three letters: l (left-align), c (centre), and r (right-align).
  • The end{array} command indicates the ending of an array environment.
  • The & use for equal spacing.
  • The \\ use for new line.

Example 1: Table using an array environment

We will construct a table using a Latex array environment in this example. There are four columns and four rows. Each column’s data values are assigned at the center. However, we can set data values to left, right, or center using l, r, and c alphabets.

\begin{array}{|c|c|c|c|} \hline n & \text{Left} & \text{Center} & \text{Right} \\ \hline 1 & 0.24 & 1 & 125 \\ \hline 2 & -1 & 189 & -8 \\ \hline 3 & -20 & 2000 & 1+10i \\ \hline \end{array}

\begin{array}{|c|c|c|c|} \hline n & \text{Left} & \text{Center} & text{Right} \\ \hline 1 & 0.24 & 1 & 125 \\ \hline 2 & -1 & 189 & -8 \\ \hline 3 & -20 & 2000 & 1+10i \\ \hline \end{array}

Example 2: Tabular data using an array environment

We will construct a semi table using a Latex array environment in this example. This representation is very useful when we present experimental data in a semi tabular form.

\begin{array}{c|lc|r} n & \text{Left} & \text{Center} & \text{Right} \\ \hline 1 & 0.24 & 1 & 125 \\ 2 & -1 & 189 & -8 \\ 3 & -20 & 2000 & 1 \\ \end{array}

\begin{array}{c|lc|r} n & \text{Left} & \text{Center} & \text{Right} \\ \hline 1 & 0.24 & 1 & 125 \\ 2 & -1 & 189 & -8 \\ 3 & -20 & 2000 & 1 \\ \end{array}

Example 3: Tabular data using an array environment and hline

In this example, observation data is represented in a tabular form.

\begin{array}{|c|c|c|c|c|c|c|} \hline \text{Point (x)} & 1 & 2 & 3 & 4 & 5 & 6 \\ \hline \text{Reward (INR)} & 1 & 2 & 3 & 4 & 5 & 6 \\ \hline \text{P(X=x)} & \text{1/6} & \text{1/6} & \text{1/6} & \text{1/6} & \text{1/6} & \text{1/6} \\ \hline \end{array}

\begin{array}{|c|c|c|c|c|c|c|} \hline \text{Point (x)} & 1 & 2 & 3 & 4 & 5 & 6 \\ \hline \text{Reward (INR)} & 1 & 2 & 3 & 4 & 5 & 6 \\ \hline \text{P(X=x)} & \text{1/6} & \text{1/6} & \text{1/6} & \text{1/6} & \text{1/6} & \text{1/6} \\ \hline \end{array}

Example 4: Combination of Array, Cases and Aligned environments

Suppose we roll a dice and following is the scheme for award based on outcomes.

\begin{array}{|c|c|c|c|c|c|c|} \hline \text{Point (x)} & 1 & 2 & 3 & 4 & 5 & 6 \\ \hline \text{Reward (INR)} & 1 & 2 & 3 & 4 & 5 & 6 \\ \hline \text{P(X=x)} & \text{1/6} & \text{1/6} & \text{1/6} & \text{1/6} & \text{1/6} & \text{1/6} \\ \hline \end{array}

\begin{array}{|c|c|c|c|c|c|c|} \hline \text{Point (x)} & 1 & 2 & 3 & 4 & 5 & 6 \\ \hline \text{Reward (INR)} & 1 & 2 & 3 & 4 & 5 & 6 \\ \hline \text{P(X=x)} & \text{1/6} & \text{1/6} & \text{1/6} & \text{1/6} & \text{1/6} & \text{1/6} \\ \hline \end{array}

The required probability mass function is:

p(X) = \begin{cases} 1/6 & \text{for } 1 \leq x \leq 6 \\ 0 & \text{otherwise} \end{cases}

p(X) = \begin{cases} 1/6 & \text{for } 1 \leq x \leq 6 \\ 0 & \text{otherwise} \end{cases}

Solution: 

\begin{aligned} E[X] &= \sum_{i=1}^{\infty} g(x_i) \times P(X=x_i) \\ &= \sum_{i=1}^{6} g(x_i)p_i \\ &= 1 \times 1/6 + 2 \times 1/6 + 3 \times 1/6 + 4 \times 1/6 + 5 \times 1/6 + 6 \times 1/6 \\ & = Rs. 3.5 \end{aligned}

\begin{aligned} E[X] &= \sum_{i=1}^{\infty} g(x_i) \times P(X=x_i) \\ &= \sum_{i=1}^{6} g(x_i)p_i \\ &= 1 \times 1/6 + 2 \times 1/6 + 3 \times 1/6 + 4 \times 1/6 + 5 \times 1/6 + 6 \times 1/6 \\ & = Rs. 3.5 \end{aligned}

References

 13,245 total views,  1 views today

Scroll to Top
Scroll to Top