Code covered by the BSD License  

Highlights from
Printing a formatted table


5.0 | 4 ratings Rate this file 33 Downloads (last 30 days) File Size: 13.8 KB File ID: #33815
image thumbnail

Printing a formatted table



17 Nov 2011 (Updated )

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

| Watch this File

File Information

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.


Display Formatted Text Table Of Data inspired this file.

This file inspired Antoine Equation: Gui, Find Instance, and Rtol/Fund Global.

Required Products MATLAB
MATLAB release MATLAB 7.13 (R2011b)
Other requirements pdflatex for PDF export
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (11)
03 Dec 2013 Daniel Wirtz

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..

07 Nov 2013 Mathias

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) ?

31 Oct 2013 Daniel Wirtz

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

30 Oct 2013 Mathias

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

11 Dec 2012 Daniel Wirtz

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?

11 Dec 2012 arnold

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?

14 Jul 2012 David Hagan  
04 May 2012 Daniel Wirtz

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 :-)

23 Mar 2012 Colin

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'])

14 Dec 2011 Sven

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

14 Dec 2011 Sven  
01 Dec 2011

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

07 May 2012

-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

16 Jul 2012

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

19 Nov 2012

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

11 Dec 2012

Improved automatic TabCharLength computation

22 Jan 2013

Improved compatibility (no more wiggles ~)

15 Feb 2013

-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

20 Feb 2013

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

05 Apr 2013

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

05 Jun 2013

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

31 Oct 2013

Added a simple "sort" function

Contact us