Tag Info

Hot answers tagged

16

Here's my go at it. This tells you if two line segments intersect (unless they lie on the same line, in which case it fails horribly): ClearAll[segmentsIntersect]; segmentsIntersect[{a_, b_}, {p_, q_}] := Module[{s, t, soln}, soln = NSolve[a + t (b - a) == p + s (q - p), {s, t}]; If[Length@soln == 0, False, (0 <= s <= 1 && 0 <= t ...


15

If you can put your schedule into a list like this: schedule = { {"Lundi", "09:30", 1, "Inorg 1", "N-515", Lighter[Orange, 0.5]}, {"Lundi", "10:30", 1, "Physique 4", "N-515", Lighter[Cyan, 0.5]}, {"Mardi", "9:30", 2, "Macromol 2", "G-815", Lighter[Green, 0.3]}, {"Mardi", "14:30", 1, "Inorg 1", "répet N-515", Lighter[Orange, 0.5]}, ...


13

This is my implementation using Graphics primitives and rules. Here's the final result; the implementation details and edge cases follow. 1. General approach First, we start with a single square and build up a test grid: square = Polygon[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}]; grid = Graphics[{EdgeForm[Black], FaceForm[None], Table[Transpose@First@square ...


9

The Pane construct is quite flexible. I cannot imagine not using it with table for fluid sizes control and features. Here are your data: data={{"000000000\n111111111\n222222222","000000000"},{"000000000","000000000"}} This will fix the cell size and cut off the content if it won't fit: Grid[Map[Pane[#, ImageSize -> {80, 30}] &, data, {2}], Frame ...


5

It would appear that Column by default is setting the integral in the InlineFormula style. If you force it to use the DisplayFormula style, the integral will be set larger. Column[{Row[{"An integral:"}], Row[{Style[Integrate[f[x], x], "DisplayFormula"]}]}] // TraditionalForm


5

Update 3: Dealing with subgrids with different number of columns: The main difficulty with differing number of columns is that both Spacings and ItemSizes in the subgrids have to be taken into account to get the same total width for all the subgrids. With $m$ subgrids indexed $i=1, ..., m$, where subgrid $g_i$ has $n_i$ columns with column widths $w_{i ...


5

You can explicitly frame only those elements and not frame the rest. For example: Grid[tab, Frame -> {None, None, {{1, 1} -> True, {1, 2} -> True}}] To extend this to grids with $n$ columns in the header, you could replace the last element of the RHS of the Frame option with Table[{1, i} -> True, {i, n}] where n is an integer.


5

You can play with ItemSizes to make sure that the itemsizes in the two sub-grids are in alignment. For example: Grid[{{"12", Grid[{{"1", "2"}, {Item["foo", ItemSize -> {5, 3}], Item["bar", ItemSize -> {10, 3}]}}, Dividers -> All, Alignment -> {Center, Center}]}, {"xxxx", Grid[{{"1", "2"}, {Item["foo", ItemSize -> {10, ...


4

Maybe using sub-grids in the second column will more be like what you want. I tried it out and got something that was close to the TableForm layout. color = RGBColor[0., .5, 1.]; dots = Graphics[{color, Disk[]}, ImageSize -> #] & /@ {40, 60, 50, 60, 40}; data = {{"Angel Falls", "17.7 m", "0.82", "9.2"}, {"Bridalveil Fall", "6.9 m", "0.94", ...


4

You could try defining myGrid = Grid[..., ImageSize -> All]. Consider for example the following test data headings = Range[20]; countryList = Cases[CountryData["Countries"], c_ /; CountryData[c, "BorderingCountries"] =!= {}, 1, 8]; salesTrend[c_, p_] := With[{t = CountryData[c, "BorderingCountries"]}, {t, RandomReal[1, {20, Length[t]}]}] Then ...


4

Does this work as you need? Manipulate[eq, Dynamic@Grid[{{"eq", SetterBar[Dynamic[eq], {1, 2}], Dynamic[eq]}, {If[eq == 1, {"v1", Manipulator[Dynamic[v1, {v1 = #} &], {0, 2, .1}], Dynamic[v1]}, {"v2", Manipulator[Dynamic[v2, {v2 = #} &], {0, 2, .1}], Dynamic[v2]}], SpanFromLeft} /. (lst : {x_String, _, _}) :> ...


3

This certainly doesn't provide an answer, but I thought it might prompt some more ideas. dotSizes = {20, 40, 20, 60, 30}; dots = Graphics[{Pink, Disk[]}, ImageSize -> #] & /@ dotSizes; dat = {{"Angel Falls", "17.7 m", "0.82", "9.2"}, {"Bridalveil Fall", "6.9 m", "0.94", "9.8"}, {"Cascata delle Marmore", "8.25 m", "0.87", "6.3"}, ...


3

Let's use a Column of Rows rather than a Grid. Manipulate[eq, Column[{ Row[{"eq", SetterBar[Dynamic[eq], {1, 2}], Dynamic[eq]}, StringJoin@@Table[" ",{52}]], Dynamic[If[eq == 1, Row[{"v1", Manipulator[Dynamic[v1, {v1 = #} &], {0, 2, .1}], Dynamic[v1]}, " "], Row[{"v2", Manipulator[Dynamic[v2, {v2 = #} &], {0, 2, ...


3

A couple of references that might help you explore this topic: From the demonstration project: http://demonstrations.wolfram.com/ACycleIndexSpreadsheet/ you can download the source code. Also: http://www.wolfram.com/products/mathematica/analysis/content/Spreadsheets.html Pronto analytics did some work in this area: ...


2

Maybe I've missed something, but why not just this? testdata = FoldList[0.99 #1 + #2 &, 1., RandomVariate[NormalDistribution[0, 0.5], {100}]]; title = Column[{Style["This is a test", 24, Bold, FontFamily -> "Arial", Black], Style["And so is this", 20, FontFamily -> "Arial", Black]}, Center, 0.3, BaselinePosition -> Top]; ...


2

To get both the full control over the line spacing and over the margins around the label, it seems you have to wrap the whole title in a couple of layers. It's not pretty, but gives you total control: title = Graphics[Inset[ (* the original title: *) Column[{Style["This is a test", 24, Bold, FontFamily -> "Arial", Black], Style["And so is ...


2

Add a Frame -> All option to both plots and you'll see why excluding SpanFromLeft has such an effect. The SpanFromLeft is causing the cell height to adapt to the plot on its right. With code: {4, "xxx", SpanFromLeft, plot, SpanFromLeft} and with code: {4, "xxx", "", plot, SpanFromLeft}


2

Quite a long saga but as an FYI this is what I have learned from tech support: Firstly the documentation for ItemSize, under more information, says In Grid, w is measured in ems, and h in line heights. I'd overlooked that. With that information some control should be possible: magicRatio = CurrentValue["FontMWidth"]/CurrentValue["FontLineHeight"]; ...


2

I think the first issue is related to the fact that (docs >> Item >> Possible Issues) "If Item is not the top-most item in the child of a function that supports Item, it will not work. So a partial answer for the row selection problem can be obtained by moving Item outside EventHandler and using Framed with FrameStyle->None inside the EventHandler ...


2

The usual quick-and-dirty workaround when ItemSize does not do what is expected is to wrap contents into an invisible frame. One can use Framed with FrameStyle->None to hide the frame or Pane. In both cases, a magic number is required to convert between line-height of Grid and printers points of Framed/Pane - it is highly platform-specific (see here). The ...


2

It is not clear to me from your question what you need. You say: I want to be able to accurately place the control objects without messing the sizes and have perfect predictable appearance on the front end. Perhaps what you want can be done with Inset in Graphics, along with Deploy: mygrid = ConstantArray["\[FilledSmallCircle]", {10, 10}]; mybutton1 ...


2

There is a known-difficult problem in this: How to convert between various ItemSize/ImageSize units? Nevertheless: ItemSize: In Grid, w is measured in ems, and h in line heights. In GraphicsGrid, w and h are both measured in absolute printer's points. Pane: Pane[expr,{w,h}] makes the pane be w points wide, and h points high, shrinking the ...


1

Here are a few things I have learnt trying to find work arounds -- they may or may not be useful to others. As I indicated in my final edit to the question Wolfram tech support have indicated that the behaviour is a bug. 1: Test items size for "M" width The font family setting for ItemStylehas no effect on how the grid cell size is determined. It is solely ...


1

I don't have a real answer, but here are two work-arounds. I don't have any real expectation that you will like either ;-) Work-around 1 The idea here is that since there are actually two Spec values, the lengend should also have two fileds, each telling the viewer what one of each of the parameters represents. dot = Graphics[{Pink, Disk[]}, ImageSize ...


1

how about using GraphicsGrid? color = RGBColor[0., .5, 1.]; dots = Graphics[{color, Disk[]}, ImageSize -> #] & /@ {40, 60, 50, 60, 40} data = {{"Angel Falls", "17.7 m", "0.82", "9.2"}, {"Bridalveil Fall", "6.9 m", "0.94", "9.8"}, {"Cascata delle Marmore", "8.25 m", "0.87", "6.3"}, {"Cumberland Falls", "182.0 m", "0.87", "6.3"}, ...


1

Too long for a comment but I want to point out some observations. I don't think, that Grid is the bad guy here. It is the use of Scaled in this context where it does not seem to be clear, what exactly it means. When we use Scaled inside a Graphics, than the situation seems clear and predictable. We can draw a Rectangle exactly from bottom to top, no ...


1

Row[] takes a list as the argument. In your first case, you failed to provide a list. While in your second case: row = (Row@{##}) &; Grid[{{row[1, " a"], row[2, " b"]}, {row[3, " c"], row[4, " d"]}}] // FullForm (* Grid[List[List[Row[List[1," a"]],Row[List[2," b"]]], List[Row[List[3," c"]],Row[List[4," d"]]]]] *)


1

This is messy: If made the numbers strings and padded with whitespace: padded[x_, cutoff_: 6] := Module[{tmp1, tmp2}, tmp1 = StringSplit[ToString[x], "."]; If[Length[tmp1] == 2, tmp2 = StringTake[tmp1[[2]] <> " ", cutoff]; tmp1[[1]] <> "." <> tmp2, tmp1[[1]] <> StringTake[" ", cutoff + 1] ] ] I've made ...


1

It is definitely a bug in Grid. Here is a workaround: format[x_?NumericQ, spaces : {left_: 5, right_: 5}] := MapAt[Row[{Spacer[left], #, Spacer[right]}] &, SciForm[x, 4, -2, Align -> "."], 1] Module[{x}, x = {{1.234, 12.34}, {123.4, 1234.}, {1234, 1.234}}; x = Map[format[#, {7, 7}] &, x, {2}]; x = Prepend[x, {Item["Title", Alignment -> ...


1

Give items more space on the right, set Spacings explicitly: gridIt[itemopts__] := Module[{x}, x = {{1.234, 12.34}, {123.4, 1234.}, {1234, 1.234}}; x = Map[Item[#, itemopts] &, x, {2}]; x = Prepend[x, {"Title", SpanFromLeft}]; Grid[x, Alignment -> {Center, Center}, Dividers -> All, Spacings -> {{2 -> 6, 3 -> 6}, Automatic}]] ...



Only top voted, non community-wiki answers of a minimum length are eligible