Code covered by the BSD License

### Highlights from Printing a formatted table

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

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

File Information
Description

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.

Acknowledgements

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.
Comments and Ratings (13)
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

### Tintin Milou (view profile)

Hi,

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:

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

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

### Mathias (view profile)

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

### Mathias (view profile)

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?
thanks!

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

### David Hagan (view profile)

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+');

fprintf(fid,'\\documentclass{article}\n\\begin{document}\n');
t.print(fid);
fprintf(fid,'\n\n\\end{document}');
fclose('all');

! 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

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

- 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