# Export a table to a file

**URL:** <https://scilab.discourse.group/t/export-a-table-to-a-file/855>\
**Category:** Data handling\
**Created:** [March 8, 2025, 7:57pm UTC](https://scilab.discourse.group/t/export-a-table-to-a-file/855 "2025-03-08T19:57:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![philipp](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/philipp/32/53_2.png) [@philipp](https://scilab.discourse.group/u/philipp)\
**Post date:** [March 8, 2025, 7:57pm UTC](https://scilab.discourse.group/t/export-a-table-to-a-file/855/1 "2025-03-08T19:57:34Z")

</div>

Hello,

I am not quite sure, if my question is a double of this:

> [@How to display a Table in GUI or picture](https://scilab.discourse.group/t/how-to-display-a-table-in-gui-or-picture/690):
>
> Lets say i have a table with some currencies on the left side and in the header mean and Deviation. the table is full of values. But now, how do i get the table into a GUI or into a Figure. Table is now shown only in REPL. M.f.G. Pascal

so I rather open a new topic.

I have a table created with `matrix2table()`.

Assume that it is possible to display the full table at the console, because its a rather small one…e.g.: 5 colums and 20 entries / column.

Questions:

1. Is it possible to output the table from the console into a file (PDF) ?

2. Is it possible to display the table as a figure?  
(I guess this is what was already answered in the thread mentioned above.)

The workaround that I can think of would be to use a lot of `xstring()` to create a proper figure and use `xs2pdf()` afterwards.

OR:

Use `writetable()` , save as `.csv`, reopen with EXCEL or OpenOffice and convert here to PDF.

Any other ways to do?

Best regards,  
Philipp

---

<div class="post-metadata">

**Author:** ![philipp](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/philipp/32/53_2.png) [@philipp](https://scilab.discourse.group/u/philipp)\
**Post date:** [March 9, 2025, 9:23pm UTC](https://scilab.discourse.group/t/export-a-table-to-a-file/855/2 "2025-03-09T21:23:15Z")

</div>

I just figured, that it is possible to do something like this:

`xstring(0,1, mTable.props.VariableNames );`  
`xstring(0,0, string(mTable(1:20,:)) );`

Depending on the `figure()` and `axes()`settings the result may look like this:

 ![grafik](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/1a13ec8d6b3f092cea9e79cec79d1f29d56af1d3.png)

Is there any chance to find a parameter for setting the column spacing?  
If not: Ok, just beeing curious.

I am able to position the columns either by a given value or by a for-loop.

A bit more tweeking is necessary, but I guess I go for “creating a figure” and than `xs2pdf()`.

Best Regards,  
Philipp

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [March 10, 2025, 9:17am UTC](https://scilab.discourse.group/t/export-a-table-to-a-file/855/3 "2025-03-10T09:17:50Z")

</div>

Hello Philipp,

For this kind of stuff, a possible way to go is to use LaTeX and the `tabular` environment. Here is a small example:

```auto
t = table(rand(5,3,"normal"), ...
    "VariableNames",["var1Name","var2Name","myLongVarName"])

[n,m] = size(t);
head = strcat("\bf "+t.props.VariableNames,"&") + "\\"
data = strcat(strcat(string(t),"&","c"),"\\")
str = [ sprintf("\\sf\\begin{tabular}{%s}",strcat("r"(ones(1,m)),"|"))
        head; "\hline"; data; "\end{tabular}" ];

h = xstringb(0,0,strcat(str,ascii(10)),1,1,"fill");
h.interpreter = "latex";
xs2pdf(gcf(),"table.pdf")

```

Here is the output in a Scilab figure (the pdf looks strictly the same):  
 ![table](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/43d7e05da73b204b3360154d03062b9b9021d08a.svg)

---

<div class="post-metadata">

**Author:** ![philipp](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/philipp/32/53_2.png) [@philipp](https://scilab.discourse.group/u/philipp)\
**Post date:** [March 10, 2025, 7:22pm UTC](https://scilab.discourse.group/t/export-a-table-to-a-file/855/4 "2025-03-10T19:22:18Z")

</div>

Excellent, Thank you.
