Convert an Excel or csv table into a LaTeX table - LaTeX course

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Hi everyone, my name is Federico Tartarini. And in this video, I just want to show you how you can convert these Excel tables into a LaTeX table. Okay, so this is the table that we have here on the left and is the table that we want to generate in our paper, I will actually show you how to put the different lines. So it's going to look a little bit better than the one that we have here on the screen. First of all, the question that you might ask, why do you need a tool, a specific tool to convert these Excel table into a LaTeX table? Well, we cannot simple simply copy and paste this table into later can because otherwise will not render well. We need to write some code that wraps the table and the data. Okay, so we need for instance to space the numbers with an ampersand symbol, and then we need to begin a table so we need to begin in this environment. So here's requires a little bit of both. Okay, so the scope of this video, I'm going in this video, I'm going to show you three different tools that you can use to copy this table here into LaTeX. Okay, these two have a different levels of complexity and these are CREATE TABLE so from tables generator, they are an extension for Excel to a trick called Accelerate and an extension for Excel, okay that you can install it as an add into your Excel. And finally I'm going to use the one that is the most powerful one requires. However, it requires a little bit more of setup. We just found us the data frame too late. Okay, this is by far the most powerful and I will show you all the benefit of using this one but requires a little bit more of setup. Okay, so let's first start with the simplest one, which is create a latex table. Okay, by now already copied basically here, but let's say that you open this page and you have like some random data, you can just do right click column, remove columns, right-click row, remove rows. And actually let's let's first select everything with the left button and then column. remove columns and then row remove rows. Okay, so we just have one set generator, so we just have an empty folder. We go here we copy our table. So we selected all year on Excel, winter copy. We click on the cell here Ctrl V and we have copied year, I want to use these books. So let me just open a little bit more okay, because it depends on which one to render. So you can have a default style, okay with no lines, but actually prefer to have the book tabs Type tab style table style, because you have a top row meet row here and a bottom row. Okay, it's super simple. You just hit on the generator. This is going to generate your code here, copy to the clipboard, and then we can go in LaTeX. I'm going to show you both how to generate the table locally on your computer, which I think also is much easier. And I will also show you here with overly okay because some of you might be using the organic because it's a little bit simpler. Okay, so let's compile this document. We have a very simple document here with just a document plus article. We have a law. Let's go and copy our table. Just copy and paste from that website. But we got it combined. Okay. And this is going to create our table. However, we can really see that there are two little problems okay, one are all these errors. Okay, why there are all these errors? Well, we need a package called Book tabs in order to have these mid roll, bottom roll and top roll. Okay, let's go and add this package. So use Package tab Sir, let me actually zoom in a little bit so you can see better. Okay, here we are. So we have just added these use packets be combined. And now we can see actually maybe zoom in too much. Okay, so we can see that now we have the roll the lines as we want. If we want the table to appear here next to the text, we can just put that age here in the square bracket after table. Okay, so that's better, and then the table will come year after the tax. Okay, so this is by far the simplest method. If you don't want to use these book dumps, you can actually replace top ruler with each line and then you have to reply me through my replacement rule and bottom rule also with each line is going to be less beautiful because the lines are going to change. But you don't have to you don't require that. It's up to you. Okay, I prefer to use that package, but then we have to revert to top, middle and bottom rule and then you can use the package and then we can see our table that is rendering. Okay, this is by far the simplest way of adding a table and let me hit recompile and I'm going to recompile it. The second method that I want to show you is to the loading these extension to an auditor these are been added to your Excel. So this is called Excel two LaTeX. So let's go back in Excel where we were before we go finds options. Dean's Excel add-ins go browse. Okay, so here we have no add-in so let's go back here download Okay, so we are downloading it here from this page which is see download or we got the package PKG Excel tool attic we open it in the loads, okay, we unzip this file extracted extractor. So we go back to downloads. We go to Excel to LaTeX. We open it again, and we just get this file here. Okay, so we just have to drag this file here into Yeah, so into our Dean's, we just drag this file here into the Excel Excel where we went. Okay, so I didn't before but if I cancel it after so let me show you quickly again, five options addins manage to go. And then we rows. And now we want to see that this file is here so I dragged it here from from the downloads to this folder here. So we click on Cancel because you have already open and we need to enable it here we need to make sure that there is this checkmark as press ok. Now as you can see, these are Dean as appear. So we go here, Dean, actually, let me close Excel and open it again, because it's going to render a little bit better. So let me just go to my downloads folder where I have this example table. Okay. So I open the Excel file again. So now we can go to add ins. Okay, so compare the whole store table to later or convert the table to later Okay, so we just get this table we select the data, convert to to LaTeX. As you can see here, I've already selected the data and the table is already rendering properly. And again, here is asking us if we want to use the book tab package yes or no? Okay. So we copy it to the clipboard and then we go back to Overleaf which we had before here. So we are going to copy this table here. So let's compile again and as you can see, looks very similar to the previous table that we add is just changed how we are centering all the older data into the table. Okay, so first of all, you are we are using a centering commander. So if you remove the centering commander, let's commit let's comment is one putting a ampersand in front. You will see that the table now will not be no more center in the in the center of the paper. And also you can change how these numbers are aligned in the seller by just changing our L or C two armies right alignment see me center alignment and elements left alignment. So let me just change this up the first column should be center aligned, the second column left aligned and the last third column right aligned. Okay. So as you can see here is a little bit different from the previous table. As well, because we are only using the midroll. Why there is Altima rule because when we have exported this table, we already added a line underneath the adding so we can go home. We can add the line now. So let me add the border at the top and a border at the bottom. Okay, let's go back. Let's select all the data that we want to export at insert, convert to table to LaTeX. We have all the data here. We want to have books tab, package, copy to clipboard and we can go back here and we can replace all this table here. So let's just copy and paste. So now we compile. Okay, perfect. Now it looks exactly the one at the top is up to you if you prefer to have it centered or not. If you don't just comment is line of code with control forward slash or just putting an ampersand. Okay, these by far were the two simplest way of adding a table to your Latech document. And these are extremely powerful if you want to stop here while already you know two ways of converting Excel to LaTeX. However, I think these two methods one they are nicer they have a lot of limitations. So if your data change, or if you want to keep them seeing and think about if you have a lot of tables, okay, this is going to become a little bit more annoying because let's say that I want to change the data. Okay. So I realize that here there was an error I want this data to be true. Okay. And let's say that in my paper, I have 15 tables, okay. So every time I will have to go here, open the five, convert to latex and copy and paste it over there. Okay, these can become a little bit of a problem. Okay, so the third way that I want to show you is out to the waiter with Python. The only problem is that you have to just bear with me and I will show you all the steps, but is going to be a little bit more complex, very simple is going to require only three lines of Python code and I will show you actually the line up here. So the Python code that we're going to need is exactly the one that only three lines of code. The only problem that you will need to I mean the only thing is that you will have to use later a lot locally. So you do not have to use Overleaf, which I'm sure a lot of you already do that. So you don't have to worry about too much about that because of a leaf isn't a very nice tool, but I always would recommend it to use later cloud clean. So you can use textmaker or you can use em ik text, or in my case as you can see here, I'm using Python to compile the related code. And Python can also help me to compile the Python code. Okay, so let's go very quickly through all the steps that you need to do in order to set up your experiment in PI charm to open the table with Python and to include it into your data components. Okay, I'm sure you understand but if you want to find out more on how to set up PI charm, which is a fantastic tool, both for your Python and for your Latech and just my look at my video and I will put here on the right side of these video. You should see a car coming up in which you see how to set up by Okay. So let's go File, New Project. We go in the loader Okay, and we create a new LaTeX project. Okay, so we call it user dollars and the Untitled one, and we configure bib tech support. Okay, so we create a new project in a new window. So this is going to open. So let me just hide this one. So er, it's super simple. We have our source file, which inside contain our main text file. Okay, if you have already everything set up, you just need to press Ctrl Shift F then, and your document will compile. Actually we just need to add the text here. So we'll write a law. Let me write Shift F then let's open Sumatra PDF. Hello. These is our document, Shift F 10. And I just want to show you that this is actually our document. Okay? That's actually go from Overleaf and copy a bit this introduction and make title. So we just copy all these packages here just to make it a little bit nicer. So we go here, and then we just put all these packages here. Perfect. So let's do Shift F then again. Let's go here and grab our example My name data introduction. So okay, so exactly as we were before in organic. So if you want to and these of course this file is just a LaTeX file that you can open simply with text maker or an IK text. Okay? If you want to do the same thing that you did before you can go here, convert table to a ticker, copy to clipboard, and paste it inside here. Okay, so let's do that super simple. Shift F 10. And you get your table. Of course, keep in mind that you need this package, use package book. That's okay. Now I just want to show you a great trick, at least in my opinion. So you go here in the file, and we save this file, we save it as browse. So we save it here in our loads example table, but we don't want to save it as an Excel file. We want to save it as a CSV file, comma-delimited. Okay, and we call it an example table, save this file. Yes. And we close this file. Okay. Don't Save and everything is fine. So now we go into our downloads. We have this example table, which is the CSV file, and we drag it over here in sourcer, which we have all our later. Okay, so by charm already showing us all the data that are inside a table. Okay, let's go to source right click new Python file, Python file and we call it code underscore table. You can call it as you want. Okay. Now, you just have to import the one package, which is all import pandas as PD. And of course, you need to have Python installed on your computer. So if you have it already, that's configured by the interpreter. I'm going to select python three data then what I need to do is I need to open the file. Okay, I need to open the table here. Example table, the CSV file. So how can we do that? We can create a data frame and PD dot read CSV and we are going to open the file so the file is in sourcer. And then is called example table. Example. table dot CSV. Okay, let's run these two lines of code CTRL A SHIFT ALT E Okay. And now we can. So I just sorry, I just put today wrong of course, because this underscore table is not stable. So CTRL A Ctrl, Shift D we have opened the file. And now we can explore the file here as view as data frame. We can see our file here as I was showing you before in Excel. Okay, so this is our file that we want. Now we just have to do one last line of code, which is going to be the F to Latech to LaTeX. We just have to specify the name of the file that we want to save it. So we want to say call it the table one dot txt, and then we don't want the index Okay, index equal to false. Okay, so let's run this code again. CTRL A Shift Alt, E. Now if I click here in source reload from disk, now, we have issued a new file. Sorry, I saved it in the wrong source, table one, I need to save it. So let me run the code again. Sorry for that. So also, the load from these people want. Okay, so here we have our table. Actually, now I've saved within this directory. So just let me delete it from here. Fantastic. So we have table one. Table one is exactly what we want is all our later file that we want. Okay? Now we just have to go to main text. We don't have to have all these verbose here, but what we can have here is just input. Input, and then we have a question for the table one. Okay. Shift F, then that's combined PDF. And here is our table, okay. So if I comment this line, Shift F then the table will disappear. Okay. If instead I uncomment this line Shift F then the table appears. Okay, and here we have our table. Of course, you can add the like inside here to Latech. It has a lot of functionalities. And I would actually recommend you to read a little bit more here because you can add a caption. You can add whatever you want. You can have multi column multi rows, you can add a caption. So let's put this let me add a caption just very quickly. I want to show you caption caption and the caption is equal to Hello. And then we run this code Ctrl Shift E and then we go to main and we run Shift F then okay. Now we have also our caption here. Okay, so this is very nicer because now we have our table that is inside our file. And of course, if you want to change that, as I showed you before, it's just because when you have begin table you should put an F 10 At eight years. So now the table is back here at the top. But the advantage of doing these is that if I want to change, for instance, something in the in the file in the source table and now I want to change the value. Okay, let's change this value randomly to true. Okay, I just need to go encode table, run a code table. Okay. So parameter actually, is this because the project director is not set up properly run this code table, then go in main. Run it again. Okay, and now our value as we just changed in the table. Okay. So that's also very good because technically with a python file, you can do a lot of things. You can even run the numbers so round to zero. Okay, lets me run, run this code again. Let's go to mean, so we have to do Shift F, then. Okay, can you see all the numbers around it without having to change the source file and without having to do copy and paste which eventually is could be a little bit it will cause some adverbs. Okay. So I really hope you found this video interesting. And if you did, please consider hitting the like button or subscribing to my channel. Thank you. Very much. for listening.
Info
Channel: Federico Tartarini
Views: 4,125
Rating: undefined out of 5
Keywords: csv to latex, convert csv to latex table, excel to latex, import csv into latex, import excel to latex, how to use excel2latex, excel to latex table converter, excel to latex table, latex table, latex course, overleaf, how to create a table in latex overleaf, overleaf latex tutorial, Convert tables excel to latex, How to Convert an Excel Table to a Latex table, overleaf tutorial, python latex tutorial, How to create a table in latex
Id: F4s1Rnla1r4
Channel Id: undefined
Length: 20min 20sec (1220 seconds)
Published: Sun Feb 14 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.