4
$\begingroup$

I have discovered the unit for ImageSize is "DesktopPublishingPoints" as setting

ImageSize -> {
 QuantityMagnitude@ UnitConvert[Quantity[10, "Centimeters"], "DesktopPublishingPoints"], 
 Automatic}

produces an image that is 10cm wide. This agrees with the toolbar ruler and printing.

However, the same conversion does not work with either ItemSize nor FieldSize. The results are too wide (confirmed by toolbar ruler) but they are of equal width which indicates they are of the same unit.

What UnitConvert unit should be use for ItemSize and FieldSize options to produce output of a specified size?

Mma 11.0.1 on Win 7 Pro


This produces a Panel that is 10cm wide by toolbar ruler and when printed.

Panel["Select something", Background -> LightBlue, 
 ImageSize -> {
  QuantityMagnitude@UnitConvert[Quantity[10, "Centimeters"], "DesktopPublishingPoints"], 
  Automatic}]

These produce outputs that are much too wide.

Grid[{{Null}}, 
 ItemSize -> 
  QuantityMagnitude@UnitConvert[Quantity[10, "Centimeters"],"DesktopPublishingPoints"],
  Background -> LightBlue]

InputField[Null, 
 FieldSize -> 
  QuantityMagnitude@UnitConvert[Quantity[10, "Centimeters"],"DesktopPublishingPoints"],
  Background -> LightBlue]
$\endgroup$
4
$\begingroup$

UnitConvert will not be of much help to you, since ItemSize and FieldSize are dependent on the metrics of the current font.

The width for FieldSize is measured in ems; the height in line heights.

You will have to do the work yourself, using CurrentValue["FontLineHeight"] and CurrentValue["FontMWidth"].

$\endgroup$
  • $\begingroup$ here is a curious thing ... UnitConvert[Quantity[1., "ems"], "DesktopPublishingPoints"] (*1. pt*) $\endgroup$ – george2079 Jan 31 '17 at 15:45
  • $\begingroup$ I think ItemSize->QuantityMagnitude@ UnitConvert[Quantity[10, "Centimeters"], "DesktopPublishingPoints"] / CurrentValue["FontMWidth"]does the trick. $\endgroup$ – Edmund Jan 31 '17 at 16:02
  • $\begingroup$ @ihojnicki FieldSize does not fully cooperate with the above but it is very close. Any idea why it is a little wider for FieldSize but exact for ItemSize? $\endgroup$ – Edmund Jan 31 '17 at 16:12
  • $\begingroup$ Best guess without looking at the code... The InputField is using a different font. So you would have to spec it using Dynamic or RuleDelayed. $\endgroup$ – ihojnicki Jan 31 '17 at 16:17
  • $\begingroup$ a bit aside but note the "em" width is not literally the width of the capital "M".. en.wikipedia.org/wiki/Em_(typography). Learned something new today.. $\endgroup$ – george2079 Jan 31 '17 at 16:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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