> For the complete documentation index, see [llms.txt](https://overleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://overleaf-pro.ayaka.space/latex/more-topics/36-latex-video-tutorial-for-beginners-video-6.md).

# LaTeX video tutorial for beginners (video 6)

[Video 1](/latex/more-topics/31-latex-video-tutorial-for-beginners-video-1.md) | [Video 2](/latex/more-topics/32-latex-video-tutorial-for-beginners-video-2.md) | [Video 3](/latex/more-topics/33-latex-video-tutorial-for-beginners-video-3.md) | [Video 4](/latex/more-topics/34-latex-video-tutorial-for-beginners-video-4.md) | [Video 5](/latex/more-topics/35-latex-video-tutorial-for-beginners-video-5.md) | Video 6 | Video 7

This seven-part series of LaTeX tutorial videos was first published in 2013; consequently, today's editor interface has changed considerably due to the development of ShareLaTeX and the subsequent merger of ShareLaTeX and Overleaf. However, the video content is still relevant and teaches you the basics of LaTeX—skills and expertise that will apply across all platforms. You don’t need any previous background knowledge, and by the end of these LaTeX guides you will be able to create and write basic LaTeX documents and have the knowledge to start learning how to create more complicated documents. Each video is accompanied by a transcript (listed below the video)—these in-situ transcripts replace the URLs shown at the start of each tutorial.

### Tables and matrices in LaTeX

**Note:** You can open the project used in the video by [following this link](https://www.sharelatex.com/project/51f1324bc00460011608ea5c).

{% embed url="<https://www.youtube.com/embed/1cEdqTMtHZQ>" %}

### Video transcript

In the [previous video](/latex/more-topics/35-latex-video-tutorial-for-beginners-video-5.md) we looked at using BibTeX to add bibliographies into our documents. In this video we’ll look at inserting tables and matrices.

To insert tables in LaTeX we use the `tabular` environment. So let’s add in our begin and end commands. Immediately following the `\begin{tabular}` command we need to tell LaTeX the column specifications. There are a few key characters we use to do this. Firstly, a lower case `l` specifies a left justified column, a lower case `r` specifies a right justified column and a lower case `c` specifies a centred column. In my example I’m going to specify six columns, the first and last will be left-justified and the rest will be centred. To put vertical lines between the columns we can use the bar symbol and place it between the letters where we want the lines to appear. When entering the tables’ contents we start each row on a new line, separate column entries using an ampersand and finish each row, except the last, with a double backslash.

Now to add horizontal lines we use the `\hline` command. To make a double horizontal line simply use the command twice. One potential problem with this table is that if I add a long line of text into one of the cells in the final column it will sprawl off the page. To fix this there is another option we can use when declaring column specifications. It is a lower case `p` followed by a width in centimetres in curly brackets. So if I change the final `l` in the declaration to a `p` with `5cm` you will see the text has been wrapped so that the final column’s width is 5cm.

So that’s the basics of writing tables. However, just like with images, we often want more control over positioning and we may want to add a caption and label. To do this we use an environment called `table` which is similar to the `figure` environment we used for images. To put our existing table in the `table` environment we simply enclose the code in `\begin{table}` and `\end{table}` commands. We can then set the position specifier using a combination of `h`, `t`, `b`, `p` and exclamation mark (`!`). I can also add a caption and label.

We will now briefly look at matrices as they use similar syntax as tables. At this point make sure you’ve loaded the `amsmath` package. Before we add a matrix we need to tell LaTeX that we are about to add some maths by opening an environment. We could use the equation environment as we did a few videos ago, however here we’ll use the `displaymath` environment as it has nice LaTeX shorthand. This means instead of using a `\begin` command we can use a backslash and open square bracket and instead of an end command we can use a backslash and close square bracket. Matrices can be inserted using the `matrix` environment. With matrices we don’t need to declare how many columns we use, we can simply start adding the entries. Again we enter each row on a new line, separate entries using an ampersand and separate rows using a double backslash. To change the brackets surrounding the matrix, we change the environment. The `pmatrix` environment uses parenthesis, `bmatrix` uses square brackets, `Bmatrix` (with a capital `B`) uses curly brackets, `vmatrix` uses vertical lines and `Vmatrix` (with a capital `V`) uses double vertical lines.

Finally we’ll finish this video with a more interesting matrix. What we are doing in this example is nesting matrices inside another matrix. So what we actually have here is a two by two matrix built with the `pmatrix` environment, where the top left and bottom right entries are also matrices, this time built with the `matrix` environment to avoid multiple brackets.

This concludes our discussion on tables and matrices. In the final video of this series we’ll look at composing larger documents.

[Video 1](/latex/more-topics/31-latex-video-tutorial-for-beginners-video-1.md) | [Video 2](/latex/more-topics/32-latex-video-tutorial-for-beginners-video-2.md) | [Video 3](/latex/more-topics/33-latex-video-tutorial-for-beginners-video-3.md) | [Video 4](/latex/more-topics/34-latex-video-tutorial-for-beginners-video-4.md) | [Video 5](/latex/more-topics/35-latex-video-tutorial-for-beginners-video-5.md) | Video 6 | Video 7


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://overleaf-pro.ayaka.space/latex/more-topics/36-latex-video-tutorial-for-beginners-video-6.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
