View License

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

» Watch video

Highlights from
Printing a formatted table

5.0 | 5 ratings Rate this file 29 Downloads (last 30 days) File Size: 13.8 KB File ID: #33815 Version: 1.19
image thumbnail

Printing a formatted table


Daniel Wirtz (view profile)


17 Nov 2011 (Updated )

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

| Watch this File

File Information

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.


Display Formatted Text Table Of Data inspired this file.

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

Required Products MATLAB
MATLAB release MATLAB 7.13 (R2011b)
MATLAB Search Path
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 (14)
25 Nov 2016 Andres Mora

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

26 Jan 2015 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.

Comment only
19 Jan 2015 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?

Comment only
03 Dec 2013 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..

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

Comment only
31 Oct 2013 Daniel Wirtz

Daniel Wirtz (view profile)

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

Comment only
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

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?

Comment only
11 Dec 2012 arnold

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?

Comment only
14 Jul 2012 David Hagan

04 May 2012 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 :-)

Comment only
23 Mar 2012 Colin

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

14 Dec 2011 Sven

Sven (view profile)

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

Comment only
14 Dec 2011 Sven

Sven (view profile)

01 Dec 2011 1.4

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

07 May 2012 1.5

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

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

19 Nov 2012 1.9

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

11 Dec 2012 1.12

Improved automatic TabCharLength computation

22 Jan 2013 1.13

Improved compatibility (no more wiggles ~)

15 Feb 2013 1.14

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

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

05 Apr 2013 1.16

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

05 Jun 2013 1.18

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

31 Oct 2013 1.19

Added a simple "sort" function

27 Jul 2015 1.19

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

Contact us