package](https://ftp.fau.de/ctan/macros/latex/contrib/tabularray/tabularray.pdf) for LaTeX is able t

package](https://ftp.fau.de/ctan/macros/latex/contrib/tabularray/tabularray.pdf) for LaTeX is able to do exactly this. The tabularray package also makes it much easier to create more complex LaTeX tables, when compared to the regular tabular enviroment. To add the package simply add the following to your file:`+LATEX_HEADER: \usepackage{tabularray}`# SetupTo start we first need to learn some basics about LaTeX and how emacs handles exporting tables to it. And how we have to adjust this behaviour to our needs. Lets take a look at what the second table looks like once emacs has exported it: \begin{tabular}{|l|lp{10cm}|r|} \hline Exit code & Type & Meaning\\ \hline 0 & External/Internal & Succesfull operation; logical true\\ \hline 1 & Internal & Non successfull operation; logical false\\ \hline 2 & Internal & A reallly long error message that is long enough to not fit on a single sheet of paper\\ \hline \end{tabular}As you can see, the table itself defines each cell using an "&" and adding horizontal lines between them. These lines are being manually added by pressing `C-c RET` in your table. Emacs also used the tabular enviroment (`\begin{tabular}`) for the table, which is the default table enviroment for LaTeX. You also see that our latex argument got directly passed to the enviroment as an additional argument (this part is called the inner specification of the enviroment). This will come in handy later, once we replaced the tabular enviroment with our own one.# Our table styleFirst of all: How do we even insert raw LaTeX into orgmode documents? There is a number of different ways to achieve this. You can add LaTeX headers with `#+LATEX_HEADER:` or insert a single line by using `#+LATEX:`. If we want to include multiple lines with `#+LATEX:`, we can also use the `#+BEGIN_EXPORT` or `#+BEGIN_src` syntax. We can even use a seperate orgfile in which we store all of our table styles and include it with `#+INCLUDE:`, which is what we are going to do here. Dump all the LaTeX into a seperate file, so that we dont have to copy it for all of our documents. The advantage of specifying this on a seperate org file (I will call it `table_style.org` instead of a plain tex file is, that by doing it this way, you can add all packages that you need for your table style in the `table_style.org` file itself and don't have to include them in your main file (you can not use the `\usepackage` command in the body of a document, which is where the included tex file would be included).First of all, lets create our new table enviroment: \NewTblrEnviron{globaltbl} \SetTblrInner[globaltbl]{ }What this does is, that it creates a completely new table enviroment called `globaltbl` and every single table that uses this enviroment will inherit all attributes (which we will set in a second) from it. However we will still be able to override all values for each table.And now lets add some basic attributes to the inner definition: \NewTblrEnviron{globaltbl} \SetTblrInner[globaltbl]{ vlines, hlines, width = 0.9\linewidth, rowsep = 4pt, colsep = 8pt, colspec={X[t,l]X[t,l]X[t,l]X[t,l]}, }https://preview.redd.it/1v62loims3nh1.png?width=487&format=png&auto=webp&s=66382bb15d8c95334a33dec7a587ada7443fa10eThe `hlines` and `vlines` arguments tell tabularray to always draw horizontal and vertical lines between cells, regardless of the appearance of any manually inserted `\hline`. If the `hline` option has been given, inserting a `\hline` into the table will cause tabularray to render a snall gap at the position of the `\hline`. The `width=0.9\linewidth` sets the width of the table to 0.9x the width of a single line. The `rowsep` and `colsep` attributes control how much space between your text input and your `hlines` / `vlines` you have.If you want a deeper understanding of the `colspec` attribute please go and look up [cell