LaTeX/C2/Tables-and-Figures/English
Welcome to this tutorial on tables and figures. We have two objectives in this tutorial. The first is to explain how to create tables using the tabular environment; the second objective is to explain how to include tables in latex documents using the table environment. A similar technique can be used to include figures also. We have seen how to create the title page, this one has title, author information, and creative commons, copyright information as explained in the tutorial on equations. Today’s date appears in the last column created by this command. Let us go to the second page. I will now explain to you how to create this table in a step-by-step fashion. Let us start with a clean slate. Let me delete these commands. Ill compile this and start with a clean slate. The tabular environment is created using begin tabular and end tabular commands. Let me do that here.
The ‘r r’ characters within the braces next to the begin tabular say that there are two columns and that they are right aligned. In the first line, the entries are mango and mixed. Two reverse slashes indicate next line. Let me enter the next line. Jackfruit. Kolli hills. Banana. Green. Let me end this tabular environment. Let me compile this. And this has appeared here. We get the 3 by 2 table, there are three rows and 2 columns. The two columns are right aligned as indicated by the r r character. To separate the two columns, we introduce a vertical line between the column alignment characters. So let me put that vertical line. Save it. Compile it. You see that a vertical line has come. If you want vertical lines at the end also, put them at appropriate places. Let me put them, save them, compile them. So these have come. As a matter of fact, we can put more vertical lines. Let me put one more vertical line at the beginning. There you are! A second line has come. See there are two vertical lines. We will now try different alignments. Lets put a ‘c’ here, to say that the second column should be center aligned. This is center aligned now. Let us make the first column left aligned. Right now it is right aligned let me make them left aligned. L, Save, Compile. Now it is left aligned.
We will now separate the rows with horizontal lines as follows. Lets put a h-line here. Let us see what happens when we do that. It puts a top line. If I put another h-line here, see a line has come. So let me complete this. Let me put h-line. Here I have to put a break line with two reverse slashes and then h-line. H-line begins from the beginning of the sentence. So now I have completed the horizontal lines.
Now let us add three more columns and one more row. So what I do is, I come here, and C , C, R. So I have added three more columns, first two of them are center aligned the third one is right aligned. And then here I want to say: fruit, type, number of units, cost per unit, cost rupees, h-line. So mixed, 20, 75 rupees, 1500 rupees. Jackfruit, 10 of them, 50 rupees, 500 rupees. Banana green, 10 dozens, 20 rupees a dozen and 200 rupees total. So let’s see whether we can compile this. So it has created the table. See the need for right alignment, this is so that we can add these numbers.
Suppose that we want to split the column in two. For example, here these two columns have fruit details and these three have cost calculations. So this is done with the help of, what is known as multi-column command. Let me do it as follows. Multi-column, take 2, center-aligned, Fruit Details. First two are over then I put a tab to indicate the next column. Go to the next line. Multi-column, three, also to be center-aligned. Cost within braces – cost calculations, slash h-line. So there you are. The first two have the title fruit details, the next three have the title cost calculations. I don’t have the vertical lines that’s because I didn’t tell latex to do that. So let’s do that. Here I want two vertical lines, here I want 1 vertical line. Before this I already have the line here so let me just put this here. See what happens. So now the vertical lines have also come. Because these 2 and 3 are single character arguments its possible to write them without braces. Okay, Same thing works.
Sometimes it is necessary to draw horizontal lines between only a few columns. So we explain this as follows. Let me split this mango, instead of mixed let me call this Malgoa, and then 18 kilograms, 50 kilograms, let me delete this okay. And here let me say that it is Alfanso, 2 dozens, 300 rupees a dozen, and a total of 1500. Let’s see what happens when I save this. Compile this. So I’ve got this, what happens is this line comes here and as well as here and I don’t want this and this. So this is taken care of by saying instead of this horizontal line, I want a C line and between the columns 2 and 4. So I should have done this here. So let me put this back here. H-line here. C-line 2 to 4. Okay, so now I have the line between columns two and four only. So this central line has split the mangoes into two of the most popular mangoes in India. We will conclude this example, conclude this table with a last row. Let me total up as follows. Multi-column four, 2 vertical lines, right-aligned, vertical separator, Total cost, Rupees. Close this. Next tab, 2200, h-line. So there you are. So this was the table that we started with at the beginning of this tutorial. How do we work with the tables created using the tabular environment? Latex treats the entire table created using the tabular environment as a single object. For example, if you write, this is an example table. What happens is this table gets sandwiched between these two. This is an example to, example table. This table appears in a running sentence. It is possible to include tables using a centre environment. A more common approach is to include it in the table environment. As we show now. Begin. Table. Close this. So what happens is now ‘this is an example table’. This sentence comes separately and whatever that appears between this ‘begin’ and ‘end’ table have been placed separately as a table. In other words, even though the table appear in between some text, it has been put separately. This is not centered. What I can do is give a command here called ‘centering’. To place this at the center of the document.
Let us now create a caption. Table caption is put before the table. Let me put a caption here, Caption – cost of fruits in India. So the caption has come. This is too close; I want to leave a small space. Let me do that by giving through this v-space command – 1 ex. That is the space equivalent of the ‘x’ character. So I have left this vertical space. So now it looks okay. By default, Latex places tables at the top of the page. This placement is done automatically. The table is ‘floated’ to the next available slot. To explain this, let me cut and paste some text from the bottom of this document. Let me delete this. Let me delete this, Alright. Now there is some write up about these fruits. Go to the top of this. Paste it here. Compile it. So as before the table got placed at the top of this page. Let me put some more text here. Four copies. So now what has happened is this table has been floated to the second page and there is nothing else here so it has been placed at the middle of this page. Let me put one more copy of this, some more text. So now what has happened is – this is the title page, this is the text page, the table has been floated, it has gone to the top of this page.
As in equations, we can also create labels and use them for referencing. For example, you give this command below the caption command. You have to give it below the caption command because it is the caption command that creates the table number. For example, here table 1 has been created automatically by this caption command. If you put the label after this, this label will refer to the number created using the caption command. So label – fruits. So let me just got back and say, let me add this line here. The cost of these fruits is shown in Table reference, you have to give the label, it should be the same as this – ‘tab fruits’. Let me compile it. So there it is. On first compilation, this variable is not assigned. So let me re-compile it, so now I have got this. We can create a list of tables automatically. As we explain now. After the ‘make title’, suppose we want this ‘list of tables’ - one word, is the command. So what has happened is , it has created a list of tables. Typically one would have to compile twice to make sure the table number comes correct. Here it comes, the table according to this list is in page two but we know that it is in page 3. So this is in page 3. So lets go back and compile it once more, so there you are, it is in page 3. So this has been explained before. Alright, this comes to the end of this part in which we explained tables. We will now explain how to create figures using the command called ‘include graphics’. So for this we need to include this package called ‘graphicx’. Okay! Suppose I go to the bottom of this, and say, the command is as follows. Begin, figure, include graphics, width equals. I have a file called iitb.pdf. There you are. I include it here with the width of this figure coming out to be equal to that of the line width. Let me end this figure. Compile this. There you are. So it has also been put at the top of this page. Alright! What I will do is, so let me just, this is for if I want to use the entire line width . Suppose I want to use point 5, that is half a line width, then it has been made small. And note that it has been left aligned. And as in the table I can say ‘centering’, which will center this at the middle.
I can also create a caption, figure captions are created after the figure is included. ‘Golden Jubilee logo of IIT Bombay. Okay, as before I can create a label and refer to it using the ‘ref’ command. I can also make this list of figures appear along with the list of tables. So suppose I want list of figures also. Ill compile it. I will compile it twice and there it is. List of figures also comes automatically. All the figure captions will appear here.
There is one last thing that I want to show you here. That is how to rotate these figures. This is done by the angle option. Suppose angle, I want to rotate by 90 degrees. So lets go to this figure. Let’s compile this. So this has been rotated by 90 degrees. Rotate it by minus 90, alright. So this is the way to include figures. Here I am assuming that iitb.pdf is available. This brings us to the end of this tutorial. The beginners of latex should compile after every few changes to the source document and make sure that what they have entered is correct. Thank you for listening to this tutorial. This is Kannan Moudgalya signing off. Good-bye.