12.07.2015 Views

Grids Rows And Columns In Mathematica - Wolfram Research

Grids Rows And Columns In Mathematica - Wolfram Research

Grids Rows And Columns In Mathematica - Wolfram Research

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

ContentsThe Basic Constructs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1Grid Family . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2Graphics Grid Family . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3Embedded Constructs Family . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4Classes of Functionality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5Options Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6Using Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7Using Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8Using Both . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10<strong>Columns</strong>, <strong>Rows</strong>, Gutters, and Items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11The World of Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12<strong>Columns</strong>, Then <strong>Rows</strong> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12Gutters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14Items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14Dividers and Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15Styling Dividers and Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17Precedence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17Alignment and Positioning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18Background and Style . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20Common Cases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20Precedence of Overlapping Background Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21Spanning and Nesting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21Sizing and Spacing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23Sizing in Grid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23Line Wrapping in Grid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24Sizing in GraphicsGrid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25


<strong>Grids</strong>, <strong>Rows</strong>, and <strong>Columns</strong> in <strong>Mathematica</strong>The Basic Constructs<strong>Mathematica</strong> provides a broad range of powerful constructs for laying out content on a screenor page. They are designed to be immediately useful for the beginner, yet also allow fine controlover almost every aspect of their appearance.These constructs can be placed into three families: constructs that appear within notebooks astypesetting structures, functions that generate graphics whose contents are arranged on a grid,and constructs that can appear inside grids to adjust details of formatting.Grid, Column, and Row form the first family, referred to in this tutorial as the Grid family. TheGrid family's defining characteristic is that it is a tightly integrated part of <strong>Mathematica</strong>'s typeset -ting system. This means that any expression whatsoever can appear as content, and that theconstruct itself can respond to changes such as window width or even the size of its elements.Like other typesetting constructs, the Grid family's members are inert constructs and do notevaluate to some other form.Examples of the Grid family of formatting constructs.A parallel set of constructs~the Graphics Grid family~supports features particularly usefulwhen dealing with graphics. These constructs are GraphicsGrid, GraphicsColumn, andGraphicsRow. Though graphics can be used in the Grid family, the Graphics Grid family supportssizing and editing behavior more tailored to graphics. The Graphics Grid family has functionsthat take arguments and evaluate them into new graphics expressions, which means it isdifficult to make the generated grid respond to changes in its environment, but easy to interactivelyadd arbitrary annotation and additional graphics.


2 <strong>Grids</strong>, <strong>Rows</strong>, and <strong>Columns</strong> in <strong>Mathematica</strong>GraphicsGrid GraphicsColumn GraphicsRowExamples of the Graphics Grid family of formatting constructs.The final family~the Embedded Constructs family~consists of constructs that are embeddedwithin the grids themselves, and alter the grid's appearance from within. Item can be wrappedaround elements in a grid in order to style the region in which they appear. SpanFromLeft,SpanFromAbove, and SpanFromBoth are used to create regions that span across multiple rowsor columns.Examples of embeddable constructs.Some very basic examples of all of these constructs follow.Grid FamilyGrid@88expr 11 ,expr 12 ,…


<strong>Grids</strong>, <strong>Rows</strong>, and <strong>Columns</strong> in <strong>Mathematica</strong> 3<strong>In</strong>[686]:=Out[686]=A column of elements.Column@8"a", "b", "c", "d"


4 <strong>Grids</strong>, <strong>Rows</strong>, and <strong>Columns</strong> in <strong>Mathematica</strong>Display elements in a graphics row.<strong>In</strong>[691]:= GraphicsRowB: , , >FOut[691]=Embedded Constructs FamilyItem@expr,optionsDSpanFromLeftSpanFromAboveSpanFromBothdisplays with expr as the content, and with the specifiedoptions applied to the region containing exprindicates that the position is occupied by the contents onthe leftindicates that the position is occupied by the contentsaboveindicates that the position is occupied from both above andleftConstructs with special meaning when they are embedded as elements within the Grid and Graphics Gridfamilies.<strong>In</strong>[708]:=Out[708]=Embed styling information around the element "a".Grid@88Item@"a", Background -> Red, Frame -> TrueD, "b", "c"


<strong>Grids</strong>, <strong>Rows</strong>, and <strong>Columns</strong> in <strong>Mathematica</strong> 5Span "a" across the first two columns and rows.<strong>In</strong>[711]:=Out[711]=Grid@88"a", SpanFromLeft, "c"


6 <strong>Grids</strong>, <strong>Rows</strong>, and <strong>Columns</strong> in <strong>Mathematica</strong>† The sizes and spacings in the grid can be adjusted.0 0 00 0 00 0 00 0 00 0 00 0 0<strong>In</strong> addition to these styling features, various forms of interactive editing and dynamic behaviorare possible.Options SyntaxA variety of options exist for adjusting the details of a grid's appearance. This section describesthe common syntax shared by many of these options. This syntax provides a way to assignoption values not only for the entire grid, but also for individual rows, columns, and even items.The overall syntax for many options, such as Background, is based on forms likeBackground -> 8spec x , spec y


<strong>Grids</strong>, <strong>Rows</strong>, and <strong>Columns</strong> in <strong>Mathematica</strong> 7An equivalent list of background values to use for successive columns.<strong>In</strong>[9]:= Grid@881, 2, 3


8 <strong>Grids</strong>, <strong>Rows</strong>, and <strong>Columns</strong> in <strong>Mathematica</strong><strong>In</strong>[27]:=Out[27]=Set the background of the element at position 83, 3


<strong>Grids</strong>, <strong>Rows</strong>, and <strong>Columns</strong> in <strong>Mathematica</strong> 9Additionally, sublists can be used to denote cyclic use of values.<strong>In</strong>[53]:=Out[53]=Specify that the list should be used cyclically.Grid@Table@x, 84


10 <strong>Grids</strong>, <strong>Rows</strong>, and <strong>Columns</strong> in <strong>Mathematica</strong><strong>In</strong>[62]:=Out[62]=Use a rule to directly assign the background.Grid@Table@x, 84


<strong>Grids</strong>, <strong>Rows</strong>, and <strong>Columns</strong> in <strong>Mathematica</strong> 11<strong>Columns</strong>, <strong>Rows</strong>, Gutters, and ItemsAs introduced in the previous section, <strong>Mathematica</strong> provides a flexible syntax for changing anoption's value in different regions of a grid. This section provides context for that language andelaborates on the finer distinctions.first columnitemcontent areagutterfirst rowelementVocabulary for grids.columnrowitemguttervertical sequence of itemshorizontal sequence of itemsthe region containing a grid elementthe border between consecutive rows or columnsDifferent slices of a 2D grid.Grid and GraphicsGrid follow the same conventions for describing the different possible slicesof the grid. Column, GraphicsColumn, and GraphicsRow follow the same general conventions,except that they only deal in one of the two possible dimensions. Finally, Row does notparticipate in this system at all.


12 <strong>Grids</strong>, <strong>Rows</strong>, and <strong>Columns</strong> in <strong>Mathematica</strong>The World of OptionsThe following table identifies the slices each listed option can address. No option is valid for allconstructs; refer to the key below to see which option can occur for a given construct.Out[54]=Out[53]=Note that Row does not take any options.<strong>Columns</strong>, Then <strong>Rows</strong>To remember the syntax for options, the most important step is knowing that specific values forthe columns are specified first, and values for rows are specified second.


<strong>Grids</strong>, <strong>Rows</strong>, and <strong>Columns</strong> in <strong>Mathematica</strong> 13opt->valopt->colspec,rowspec8colspec 8h, v


14 <strong>Grids</strong>, <strong>Rows</strong>, and <strong>Columns</strong> in <strong>Mathematica</strong>Similarly, a different background color can be given at successive horizontal positions.<strong>In</strong>[6]:= Grid@881, 2, 3


<strong>Grids</strong>, <strong>Rows</strong>, and <strong>Columns</strong> in <strong>Mathematica</strong> 15<strong>In</strong>[100]:=Out[100]=c da bItem can be used to explicitly indicate the desired settings.Grid@88Item@a, Background Ø RedD, b


16 <strong>Grids</strong>, <strong>Rows</strong>, and <strong>Columns</strong> in <strong>Mathematica</strong>DividersFrameFrameStyledraw dividers between columns or rowsput a frame around regions of the griduse an overall style for the linesOptions for drawing dividers and frames.<strong>In</strong>[131]:=Out[131]=Use Frame to put lines on all four sides of a region or set of regions.Grid@Table@x, 84


<strong>Grids</strong>, <strong>Rows</strong>, and <strong>Columns</strong> in <strong>Mathematica</strong> 17<strong>In</strong>[150]:=Out[150]=This short form draws the center dividers.Grid@Table@x, 84


18 <strong>Grids</strong>, <strong>Rows</strong>, and <strong>Columns</strong> in <strong>Mathematica</strong>Dividers and frames are added together.<strong>In</strong>[177]:=Out[177]=Grid@Table@x, 84


<strong>Grids</strong>, <strong>Rows</strong>, and <strong>Columns</strong> in <strong>Mathematica</strong> 19It is also possible to give different alignments to the individual items in the grid.Set the element at position 81, 1< to the left, and the element at position 81, 2< to the right.<strong>In</strong>[62]:= Grid@881, 10


20 <strong>Grids</strong>, <strong>Rows</strong>, and <strong>Columns</strong> in <strong>Mathematica</strong>Background and StyleCommon CasesWhen working with a collection of elements, Grid provides a way to set them against a uniformbackground.Though an element can have its own background, awkward gaps result when you put elementstogether.<strong>In</strong>[193]:=Grid@88Style@a, Background Ø BrownD, Style@b, Background Ø BrownD


<strong>Grids</strong>, <strong>Rows</strong>, and <strong>Columns</strong> in <strong>Mathematica</strong> 21<strong>In</strong>[107]:=Embed the background with a particular item inside the grid.Grid@88"The ", "quick ", Item@"brown", Background Ø BrownD," fox ", "jumps ", "over ", "the ", "lazy ", "dog."


22 <strong>Grids</strong>, <strong>Rows</strong>, and <strong>Columns</strong> in <strong>Mathematica</strong><strong>In</strong>[709]:=Out[709]=Span "a" across the first two columns.Grid@88"a", SpanFromLeft, "c"


<strong>Grids</strong>, <strong>Rows</strong>, and <strong>Columns</strong> in <strong>Mathematica</strong> 23Sizing and SpacingSizing in GridGrid will typically not modify the size of its elements. Also, rows and columns are by defaultmade as narrow as possible while accommodating the contents.<strong>In</strong>[275]:= GridB:8a, b>, Frame Ø AllFabOut[275]=Notice in the above example that the second row is much taller than the first, the secondcolumn thinner than the first, and the sizes of the elements were not modified in any way.If elements in the grid are interactively or dynamically changed, the size of the entire grid willautomatically adjust as appropriate.A useful exception is that Button will by default expand to fill the available space.<strong>In</strong>[277]:= GridB:8a, b>, Frame Ø AllFabOut[277]=cItemSize can be used to override the default behavior.


24 <strong>Grids</strong>, <strong>Rows</strong>, and <strong>Columns</strong> in <strong>Mathematica</strong>Make all items the same size.<strong>In</strong>[278]:= GridB:8a, b>, Frame Ø All, ItemSize Ø AllFabOut[278]=cSpecify widths and heights for individual columns and rows.<strong>In</strong>[256]:= Grid@Table@x, 83


<strong>Grids</strong>, <strong>Rows</strong>, and <strong>Columns</strong> in <strong>Mathematica</strong> 25With ItemSize -> Automatic, textual items are wrapped at the page width.<strong>In</strong>[271]:=Out[271]=Grid@88100!


26 <strong>Grids</strong>, <strong>Rows</strong>, and <strong>Columns</strong> in <strong>Mathematica</strong>Compare this with the equivalent Grid example, which does not impose either an overall size oran aspect ratio.<strong>In</strong>[290]:=Grid@randomgrid, Frame Ø AllDOut[290]=GraphicsGrid does not support an ItemSize option, but it does support ImageSize.<strong>In</strong>[294]:=GraphicsGrid@randomgrid, ImageSize Ø 200, Frame Ø AllDOut[294]=

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!