I would like to represent a table containing a large amount of information in such a way that I can (a) use scrollbars and (b) have table headings that don't scroll off the screen [just like the Free Panes option in Excel].

headings = Table["Col" <> ToString[i], {i, 1, 10}];
data = Table[RandomReal[], {j, 1, 100}, {i, 1, 10}];
Pane[TableForm[Insert[data, headings, 1]], {400, 300}, Scrollbars -> True]

The code above gives me the scrollbars with an option to adjust the size of the viewing field, but it's not obvious to me how to make the headings stay on the screen. (I'm ignoring rowheadings for the moment, to keep the problem simple, but I would like persistent row headings as well at some point.)

I'm not wedded to Pane or TableForm for that matter. The key components that I'm looking for are an adjustable field size (manipulating the {400,300} in the above example), scrollbars and persistent headings.

  • $\begingroup$ Possible duplicate: mathematica.stackexchange.com/q/3868/5 $\endgroup$
    – rm -rf
    May 14 '13 at 8:15
  • $\begingroup$ @rm-rf I agree. There are some (relevant?) differences with (a) custom headings in this code and (b) decreased complexity due to not needing edit capabilities. Not sure if that's enough to keep the question around. $\endgroup$ May 14 '13 at 14:17
  • $\begingroup$ I think you can add custom headings to those as well if you modify the right parts... For instance, F'x's answer produces A, B, C as the headings, which just need to be replaced with yours. Don't worry, the question won't be removed, but I'll explicitly mark it as a duplicate so that others can follow on for more complex and robust solutions. $\endgroup$
    – rm -rf
    May 14 '13 at 15:23

I'd say it was possible, but some work would be required to make it slick:

    Grid[Insert[data, headings, 1],
     Background -> {None, {LightCyan}}],
    {800, 15}],
    {800, 200}, Scrollbars -> True]


  • $\begingroup$ how about adding ItemSize->All to the Grid definitions. At least they are aligned...albeit do scroll with... $\endgroup$
    – Stefan
    May 13 '13 at 17:16
  • $\begingroup$ I hadn't thought of nested panes. This solution handles the vertical scrollbar nicely but we lose the horizontal bar. Grid doesn't seem to behave nicely with the scrollbars either. I edited the answer with a possible next step. The vertical scrollbar gets hidden, however. $\endgroup$ May 13 '13 at 17:35
  • 1
    $\begingroup$ @bobthechemist one idea could be to make the scrollposition of the first pane dynamic to let it update through the scrollposition of the second pane $\endgroup$
    – Stefan
    May 13 '13 at 17:49
  • $\begingroup$ @bobthechemist maybe this could help mathematica.stackexchange.com/questions/1745/… $\endgroup$
    – Stefan
    May 13 '13 at 17:51
  • $\begingroup$ @Stefan thanks - dynamic sliders do the trick. I've got what I want based on input from this answer and its comments. I don't know the proper Stackexchange etiquette; do I put the final version of my code in a comment and accept this answer? $\endgroup$ May 14 '13 at 0:46

Here's what I've come up with based on the comments and suggestions posted:

cheadings = Table["Col" <> ToString[i], {i, 1, 10}];
rheadings = Table["Row" <> ToString[j], {j, 1, 100}];
data = Table[RandomReal[], {j, 1, 100}, {i, 1, 10}];
    {"", Pane[TableForm[Insert[data, cheadings, 1]], {500, 15}, 
      ScrollPosition -> {x, 0}], ""},
      TableForm[Transpose@Insert[Transpose@data, rheadings, 1]], {50, 
       200}, ScrollPosition -> {0, y}],
     Pane[TableForm[data], {500, 200}, ScrollPosition -> {x, y}],
     VerticalSlider[Dynamic[y], {1400, 0, 5}, AutoAction -> True]},
    {"", Slider[Dynamic[x], {0, 550, 5}, AutoAction -> True, 
      ImageSize -> 500], ""}

I've added row headings as well. The size variables need to be tweaked manually for the size of the table. Also, I don't know if this is machine dependent or not, but the response time of the Sliders improves dramatically if I set AutoAction -> True (which in the end adds a nice effect IMO).

  • $\begingroup$ This freeze my Mathematica 8.0 on Windows 7 for me $\endgroup$
    – William
    Jun 15 '13 at 18:15
  • $\begingroup$ @liam good to know - I don't have M8 to test on so it would be good to know if others have the same issue. $\endgroup$ Jun 15 '13 at 22:45

One day, WRI should get round to implementing and documenting the TableView function properly. It's frustratingly close to what you want:


but its use isn't recommended (and the TableHeadings options are not implemented anyway).



Not the answer you're looking for? Browse other questions tagged or ask your own question.