File Exchange

image thumbnail

Printing a formatted table

version 1.19 (13.8 KB) by

Allows to display and print simple text tables in MatLab. Plain and LaTeX format supported.



View License

I've merged my separate submissions into KerMor/matlabtools (, which contains this submission. Please refer to that package to retrieve the current status.
This class allows to display and print a table with arbitrary number of columns.

The first row can be distinguished from others by a HasHeader flag and the column separator string can be customized.

Basic automatic conversion allows to pass common, easily string-representable data types, and optionally sprintf-compatible format strings or callbacks can be passed for either all entries or entry-specific.

Optionally a caption can be added to the PrintTable upon construction, directly taking sprintf-like arguments.

Allows to save the table in the formats 'txt' (plain text), 'tex' (LaTeX tabular) and 'pdf' (Basically using pdflatex on 'tex' output).

The table can easily be transposed and sorted.

In difference to the submission #33717 I make use of classes and have more possibilities regarding output and appearance.

Now a basic automatic $Math$-Environment detection for LaTeX is available.

Comments and Ratings (14)

Andres Mora

Thanks man! Nice class. Saved me a bunch of time.. Latex included is an excellent bonus. Really easy to use.

Daniel Wirtz

Daniel Wirtz (view profile)

Hey Tintin,
well this case is simple: You need the pdflatex binary available on the PATH environment variable. I'm not a mac user, but i reckon there will be some terminal/shell script or even GUI-enabled way to specify your system's PATH variable.
you can see if it is set up correctly by running "!pdflatex --version" from within matlab.

Tintin Milou


I don't fully understand how the pdf conversion works. I've got the latest version of mactex installed, but apparently, I need something else because I get the following error:
/bin/bash: pdflatex: command not found

Do I have to install something else and put it on the matlab path?

Daniel Wirtz

Daniel Wirtz (view profile)

Hey Mathias,
i dont see the point why you would want to sort data in a table without also moving the line headers to the correct position? correct me if i'm getting you wrong here..


Hello, I just tested the sort function. It worked as expected exept that the Header-Line of the table is sorted too. Can one exclude the first line (if HasHeader == true or something similar) ?

Daniel Wirtz

Daniel Wirtz (view profile)

Hey Mathias,
thanks! I've just submitted a version also allowing simple alphanumeric sorting of specified columns.


I love this Class. Excellent work. Would it be possible to have a sort method for the table (something like sortrows)?

Daniel Wirtz

Daniel Wirtz (view profile)

Hey Arnold,
unfortunately i do not have 2012b yet, so i haven't tested it with that version.
However, i figured that the critical point in formatting is the tab character equivalent in whitespaces, this setting somehow seems to be different amongst platforms/matlab versions.
I've submitted an updated version with improved autodetection of that constant.
see if this solves your issue, and if not, could you send me a private message with the generated output and commands you used?


arnold (view profile)

I must be doing something wrong, the text output I see in the command window is not formatted at all?! Neither 'tex' or 'txt' seems to work.
Updated to 2012b, maybe that has something to do with it?

David Hagan

Daniel Wirtz

Daniel Wirtz (view profile)

Dear Colin,
i've just submitted an updated version with PDF support. Thank you for this suggestion!
Regarding the capitalization: I'm sticking with (what i think to be) the default Java rules for class member names; properties start with captial letter and functions start with small letters, both written in CamelCase.
As i'm programming this style everywhere i probably won't change it anytime soon, sorry :-)


Colin (view profile)

Fantastic tool, latex output is exactly what I was looking for.

Some (extremely minor) suggestions:
i. found the captilisation of the methods a bit hard to predict. e.g.

- t.print vs. t.Format vs t.addRow

which meant I had to keep referring to the help file to find out if it was t.print or t.Print

ii. command to output table straight to pdf:

e.g. if~exist('./TeX/','dir');mkdir('./TeX/');end
fid = fopen('./TeX/main.tex','w+');


! pdflatex -output-directory ./TeX/ main.tex
open([pwd '/TeX/main.pdf'])


Sven (view profile)

Very nice tool! Usage is quite easy and the tex output might save me a lot of time. Well done!


Sven (view profile)



I've merged my separate submissions into KerMor/matlabtools (, which contains this submission. Please refer to that package to retrieve the current status.


Added a simple "sort" function


Bugfix for PrintTable LaTeX Table generation (printTex would throw an error sometimes)


- Stripping newlines automatically
- Soem verbose comments for LaTeX output about creating script


- bugfix for $$ wrapping also in txt mode
- added "append" method to join two tables


-New property "TexMathModeDetection" for cell content wrapping with $$
-New property "StripInsertedTabChars" for automatic stripping of tab chars
- Added a short comment of the applied settings to LaTeX output.
- Smaller improvements


Improved compatibility (no more wiggles ~)


Improved automatic TabCharLength computation


- More datatypes handled for "stringification"
- No more table title for TightPDF LaTeX export (one line)


- Added a ctranspose overload
- TabCharLen now public property
- Small fixes


-Saving to PDF now possible
-Option "TightPDF" for pdf to contain only actual table or be an article page
-HasRowHeader tag for easy formatting of non-first column entries
-Constructor takes caption with sprintf-arguments
-Bugfixes, Demos


Fixed some bugs and added LaTeX format output and optional captions to the PrintTable.

MATLAB Release
MATLAB 7.13 (R2011b)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video