# Pretty Print and table

**URL:** <https://scilab.discourse.group/t/pretty-print-and-table/980>\
**Category:** GUI\
**Created:** [June 20, 2025, 6:02am UTC](https://scilab.discourse.group/t/pretty-print-and-table/980 "2025-06-20T06:02:20Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![pascal](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/pascal/32/40_2.png) [@pascal](https://scilab.discourse.group/u/pascal)\
**Post date:** [June 20, 2025, 6:02am UTC](https://scilab.discourse.group/t/pretty-print-and-table/980/1 "2025-06-20T06:02:20Z")

</div>

Hi scilab Team, i have experimented with tables and prettyprint. and have seen, that scilab lates not recognizes table. Would be this not be a nice feature for upcomming milestone?  
An i also have seen, that when you launch JCEF, the whole scilab gui changes to JCEF mode by so.

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

---

<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:** [June 20, 2025, 6:23am UTC](https://scilab.discourse.group/t/pretty-print-and-table/980/2 "2025-06-20T06:23:22Z")

</div>

Hello Pascal,

Did you have a look to the following post (don’t pay attention to the title, it is about LaTeX export of tables): [Export a table to a file - #3 by mottelet](https://scilab.discourse.group/t/export-a-table-to-a-file/855/3) ? You should be able to reuse the code to generate LaTeX markup for an arbitrary table.

S.

---

<div class="post-metadata">

**Author:** ![pascal](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/pascal/32/40_2.png) [@pascal](https://scilab.discourse.group/u/pascal)\
**Post date:** [June 20, 2025, 6:39am UTC](https://scilab.discourse.group/t/pretty-print-and-table/980/3 "2025-06-20T06:39:04Z")

</div>

sorry, no, i did not seen it, it is also a possibility and feasibility, but not so elegant.  
And for the other point, has someone noticed?

---

<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:** [June 20, 2025, 6:44am UTC](https://scilab.discourse.group/t/pretty-print-and-table/980/4 "2025-06-20T06:44:33Z")

</div>

> [@pascal](#):
>
> but not so elegant.

Do you have a more elegant solution 🤣? Moreover, if the feature has to be coded in `prettyprint()` I am affraid that the code will be very similar. Missing features have to be coded, that’s the law !

S.

---

<div class="post-metadata">

**Author:** ![pascal](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/pascal/32/40_2.png) [@pascal](https://scilab.discourse.group/u/pascal)\
**Post date:** [June 20, 2025, 7:16am UTC](https://scilab.discourse.group/t/pretty-print-and-table/980/5 "2025-06-20T07:16:05Z")

</div>

Yeah, but as lazy enduser, it would be nice that table can by simple prettyprint be in Latex 🙂

---

<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:** [June 20, 2025, 12:34pm UTC](https://scilab.discourse.group/t/pretty-print-and-table/980/6 "2025-06-20T12:34:23Z")

</div>

Can you test the following code:

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

```

after defining the function `table2latex`, the Scilab function `prettyprint` should work for tables (default LateX mode):

```auto
t = table(rand(5,3,"normal"), ...
    "VariableNames",["var1Name","var2Name","myLongVarName"])
pp = prettyprint(t)
titlepage(pp)
gce().interpreter = "latex"

```

S.

---

<div class="post-metadata">

**Author:** ![pascal](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/pascal/32/40_2.png) [@pascal](https://scilab.discourse.group/u/pascal)\
**Post date:** [June 23, 2025, 5:32am UTC](https://scilab.discourse.group/t/pretty-print-and-table/980/7 "2025-06-23T05:32:27Z")

</div>

![image](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/fe6ddeb78d36acb9a94b55858007d5d742d14917.png)  
zhat works for the example well, andhas some box arround, but with my exapmle not quite. but i will look further when i have time

---

<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:** [June 23, 2025, 6:03am UTC](https://scilab.discourse.group/t/pretty-print-and-table/980/8 "2025-06-23T06:03:54Z")

</div>

The box is made by `titlepage`, use the latex code as you want…

S.

---

<div class="post-metadata">

**Author:** ![pascal](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/pascal/32/40_2.png) [@pascal](https://scilab.discourse.group/u/pascal)\
**Post date:** [June 23, 2025, 6:04am UTC](https://scilab.discourse.group/t/pretty-print-and-table/980/9 "2025-06-23T06:04:57Z")

</div>

OK, i will try this, thanks

---

<div class="post-metadata">

**Author:** ![pascal](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/pascal/32/40_2.png) [@pascal](https://scilab.discourse.group/u/pascal)\
**Post date:** [June 23, 2025, 9:38am UTC](https://scilab.discourse.group/t/pretty-print-and-table/980/10 "2025-06-23T09:38:23Z")

</div>

![image](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/ec87acd5a5ff8ccfd96cbdd10f03319558ba5225.png)  
doesn’t quite work on every occasion, must look why. maybe because my table are full in string or struct2table is not quite the same as table?

M.f.G. Pascal

---

<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:** [June 23, 2025, 10:05am UTC](https://scilab.discourse.group/t/pretty-print-and-table/980/11 "2025-06-23T10:05:33Z")

</div>

> [@pascal](#):
>
> doesn’t quite work on every occasion

Do you have an example ?

---

<div class="post-metadata">

**Author:** ![pascal](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/pascal/32/40_2.png) [@pascal](https://scilab.discourse.group/u/pascal)\
**Post date:** [June 23, 2025, 10:38am UTC](https://scilab.discourse.group/t/pretty-print-and-table/980/12 "2025-06-23T10:38:25Z")

</div>

WI.school=[“BHF”,“FFHS”,“FHNW”,“HEIG-VD”,“HSLU”,“SUPSI”,“OST”,“ZHAW”];  
WI.place=[“Quellgasse 21 2501 Biel”,“Schinerstrasse 18 3900 Brig”,“Bahnhofstrasse 6 5210 Windisch”,“Route de Cheseaux 1, 1400 Yverdon-les-Bains”,“Technikumstrasse 21 6048 Horw”,“Via la Santa 1 6962 Lugano-Viganello”,“Rosenbergstrasse 59 9000 St.Gallen”,“Technikumstrasse 9 8400 Winterthur”];  
WI.teacher=[“Prof. Dr. Stefan Grösser”,“CAO Simon Ruff”,“Prof. Jörg Lageman”,“Prof. Jean-Michel Schulz”,“Prof. Thomas Schwank”,“Prof. Paolo Pedrazzoli”,“Prof. Sonderegger Urs”,“Prof. Dr. Richard Bödi”];  
Table\_WI=struct2table(WI);

t=table2latex(Table\_WI)  
pp = prettyprint(t)  
titlepage(pp)  
gce().interpreter = “latex”

---

<div class="post-metadata">

**Author:** ![pascal](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/pascal/32/40_2.png) [@pascal](https://scilab.discourse.group/u/pascal)\
**Post date:** [June 23, 2025, 10:39am UTC](https://scilab.discourse.group/t/pretty-print-and-table/980/13 "2025-06-23T10:39:46Z")

</div>

this is my example.

m.f.g. Pascal

---

<div class="post-metadata">

**Author:** ![pascal](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/pascal/32/40_2.png) [@pascal](https://scilab.discourse.group/u/pascal)\
**Post date:** [June 23, 2025, 11:57am UTC](https://scilab.discourse.group/t/pretty-print-and-table/980/14 "2025-06-23T11:57:13Z")

</div>

i have seen, that discourse mismatches the “” scilab string function.  
[Test.sci](https://scilab.discourse.group/uploads/short-url/w8w2yIUYFf4unu8OxJJ8WweM31u.sci) (692 Bytes)

---

<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:** [June 24, 2025, 5:12am UTC](https://scilab.discourse.group/t/pretty-print-and-table/980/15 "2025-06-24T05:12:09Z")

</div>

Please use code blocks, otherwise this is very complicated to copy-paste the code you are posting (see [https://scilab.discourse.group/t/welcome-to-the-scilab-discourse-forum](https://scilab.discourse.group/t/welcome-to-the-scilab-discourse-forum)).

Likely, you didn’t understand the different mechanisms in place: you don’t have to call yourself `table2latex` (it is automatically called by `prettyprint`). So the whole code of your example should be:

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

WI.school=["BHF","FFHS","FHNW","HEIG-VD","HSLU","SUPSI","OST","ZHAW"];
WI.place=["Quellgasse 21 2501 Biel","Schinerstrasse 18 3900 Brig","Bahnhofstrasse 6 5210 Windisch","Route de Cheseaux 1, 1400 Yverdon-les-Bains","Technikumstrasse 21 6048 Horw","Via la Santa 1 6962 Lugano-Viganello","Rosenbergstrasse 59 9000 St.Gallen","Technikumstrasse 9 8400 Winterthur"];
WI.teacher=["Prof. Dr. Stefan Grösser","CAO Simon Ruff","Prof. Jörg Lageman","Prof. Jean-Michel Schulz","Prof. Thomas Schwank","Prof. Paolo Pedrazzoli","Prof. Sonderegger Urs","Prof. Dr. Richard Bödi"];
Table_WI=struct2table(WI);

pp = prettyprint(Table_WI)
titlepage(pp)
gce().interpreter = "latex"

```

The alignment of strings within the columns can be changed, e.g. if you want to center strings just change `"r"` line 6 of `table2latex` by `"c"` (center) or `"l"` (left).

![stuff](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/5c15d715d4965c2453590d605f8ff3d4b9e9ccdd.svg)

---

<div class="post-metadata">

**Author:** ![pascal](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/pascal/32/40_2.png) [@pascal](https://scilab.discourse.group/u/pascal)\
**Post date:** [June 24, 2025, 5:56am UTC](https://scilab.discourse.group/t/pretty-print-and-table/980/16 "2025-06-24T05:56:14Z")

</div>

> [@mottelet](#):
>
> ```auto
> function str = table2latex(t)
> [_,m] = size(t);
> head = strcat(t.props.VariableNames," & ") + " \\ "
> data = strcat(strcat(string(t)," & ","c")," \\ ")
> str = [ sprintf("\\begin{tabular}{%s}",strcat("r"(ones(1,m)),"|"))
> head; "\hline"; data; "\end{tabular}" ];
> str = strcat(str," ");
> endfunction
> 
> WI.school=["BHF","FFHS","FHNW","HEIG-VD","HSLU","SUPSI","OST","ZHAW"];
> WI.place=["Quellgasse 21 2501 Biel","Schinerstrasse 18 3900 Brig","Bahnhofstrasse 6 5210 Windisch","Route de Cheseaux 1, 1400 Yverdon-les-Bains","Technikumstrasse 21 6048 Horw","Via la Santa 1 6962 Lugano-Viganello","Rosenbergstrasse 59 9000 St.Gallen","Technikumstrasse 9 8400 Winterthur"];
> WI.teacher=["Prof. Dr. Stefan Grösser","CAO Simon Ruff","Prof. Jörg Lageman","Prof. Jean-Michel Schulz","Prof. Thomas Schwank","Prof. Paolo Pedrazzoli","Prof. Sonderegger Urs","Prof. Dr. Richard Bödi"];
> Table_WI=struct2table(WI);
> 
> pp = prettyprint(Table_WI)
> titlepage(pp)
> gce().interpreter = "latex"
> 
> ```

Thanks, yes this works. Although the spaces between are not, but i can work around it. many thanks. 🙂

---

<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:** [June 24, 2025, 6:03am UTC](https://scilab.discourse.group/t/pretty-print-and-table/980/17 "2025-06-24T06:03:32Z")

</div>

> [@pascal](#):
>
> Although the spaces between are not

You can tune almost everything from the LaTeX side.
