3
$\begingroup$

How can I fix the EMF text spacing in Mathematica 11?

For example

Export["an.emf",
  a = Graphics[{{Yellow, Rectangle[{0, 0}, {240, 30}]},
     {Black,
      Inset[Style["Information table example",
        FontSize -> 20], {0, 15}, {Left, 0}]}},
    BaseStyle -> FontFamily -> "Franklin Gothic Book",
    ImageSize -> 240, PlotRange -> {{0, 240}, {0, 30}}]];
Print[a]

enter image description here

The EMF produced by Mathematica 11 has irregular spacing

enter image description here

On the same PC Mathematica 7 produces the expected result

enter image description here

I am running Mathematica 11.0.1 and 7.0.1 on Windows 10 Pro.

Edit

Here is a better example to further illustrate the problem.

These tables were produced with the code below. Displayed in Mathematica they look fine.

First using the font "Franklin Gothic Book", then "Verdana".

enter image description here

However, when exported to EMF there are spacing problems.

enter image description here

  1. There is a big space between "Information" and "table" in the Franklin Gothic Book version.
  2. big spaces in "Category Item Text".
  3. irregular space between 1,234 and ,567.00
  4. big space between 123.456 and % which shouldn't be there at all
  5. big space between (123.120 and ) which shouldn't be there

  6. In the Verdana version no space in "CategoryItem" and no space in "CategoryText".

  7. the % and closing bracket in (123.12) are squashed to the preceding character.

As I mentioned earlier, the EMF exports from Mathematica 7 look perfect.

Code

a = Graphics[{GrayLevel[1],Rectangle[{-1,-60},{740,25}],
{{GrayLevel[1],Rectangle[{0,0},{739,25}]},
{Black,
Inset[Style["Information table example",FontSize->16,FontSlant->Italic],
{0,43/3},ImageScaled[{0,1/2}]]}},
{{GrayLevel[0.3],Rectangle[{0,0},{739,-35}]},
{GrayLevel[1],
{Inset[Style["Category Heading Text",FontSize->12,FontSlant->Italic],{6,-35/4},ImageScaled[{0,1/2}]],
Inset[Style["",FontSize->12,FontSlant->Italic],{6,-105/4},ImageScaled[{0,1/2}]]},
{{Inset[Style["First Column",FontSize->12,FontSlant->Italic],{190,-35/4}],
Inset[Style["Part One",FontSize->12,FontSlant->Italic],{190,-105/4}]},
{Inset[Style["Column Two",FontSize->12,FontSlant->Italic],{306,-35/4}],
Inset[Style["Part Two",FontSize->12,FontSlant->Italic],{306,-105/4}]},
{Inset[Style["%",FontSize->12,FontSlant->Italic],{404,-35/4}],
Inset[Style["",FontSize->12,FontSlant->Italic],{404,-105/4}]},
{Inset[Style["Column 4",FontSize->12,FontSlant->Italic],{989/2,-35/4}],
Inset[Style["",FontSize->12,FontSlant->Italic],{989/2,-105/4}]},
{Inset[Style["",FontSize->12,FontSlant->Italic],{1199/2,-35/4}],
Inset[Style["Type",FontSize->12,FontSlant->Italic],{1199/2,-105/4}]},
{Inset[Style["",FontSize->12,FontSlant->Italic],{1393/2,-35/4}],
Inset[Style["% Total",FontSize->12,FontSlant->Italic],{1393/2,-105/4}]}},
Inset[Style["Summary",FontSize->12,FontSlant->Italic],{642,-35/4}]}},
{{{GrayLevel[0.9],Rectangle[{0,-35},{739,-57}]},{Black,
Inset[Style["Category Item Text",FontSize->12],{6,-46},ImageScaled[{0,1/2}]],
{Inset[Style["1,234,567.00",FontSize->12],{233,-46},ImageScaled[{1,1/2}]],
Inset[Style["Category Text",FontSize->12],{349,-46},ImageScaled[{1,1/2}]],
Inset[Style["123.456%",FontSize->12],{429,-46},ImageScaled[{1,1/2}]],
Inset[Style["(123.120)",FontSize->12],{530,-46},ImageScaled[{1,1/2}]],
Inset[Style["Category Text",FontSize->12],{639,-46},ImageScaled[{1,1/2}]],
Inset[Style["10.7",FontSize->12],{724,-46},ImageScaled[{1,1/2}]]}}}},{GrayLevel[1],Rectangle[{652.9,-35},{655.1,-123}]},
{{GrayLevel[1],Rectangle[{130.9,0},{133.1,-123}]},
{GrayLevel[1],Rectangle[{246.9,0},{249.1,-123}]},
{GrayLevel[1],Rectangle[{362.9,0},{365.1,-123}]},
{GrayLevel[1],Rectangle[{442.9,0},{445.1,-123}]},
{GrayLevel[1],Rectangle[{543.9,0},{546.1,-123}]}}},
BaseStyle->FontFamily->"Franklin Gothic Book",ImageSize->739,
PlotRange->{{0,739},{-59,25}}]

Export["a.emf", a]
$\endgroup$
6
  • $\begingroup$ Actually, I have difficulties seeing the difference in spacing in the images you provided. I do see a font or magnification difference, but that may be due to different Frontend settings? $\endgroup$ Commented Jan 11, 2017 at 18:05
  • $\begingroup$ @SjoerdC.deVries The space between "Information" and "table" is double-width. It looks pretty poor on a full full table, with irregular spacing all over the place, not to mention other problems with characters fixed by editing FontMap.tr. Not sure how to fix the spacing problem. Seems to be a font substitution error. $\endgroup$ Commented Jan 11, 2017 at 19:16
  • $\begingroup$ Font map edit fixed awful EMF rendering of % and ( ). Link $\endgroup$ Commented Jan 12, 2017 at 13:35
  • $\begingroup$ What version of MS Word do you use? I get much better results with Word 2003 on Windows 7 x64, but when I right-click on the imported figure and choose Edit picture and then close the edit window, I get something very similar to yours. So it may be a problem with your version of Word in the first place. Please try to open your EMF file with EMFexplorer and post the screenshot (here is what I get: screenshot). From the other side, it also may be an OS-dependent issue. $\endgroup$ Commented Jan 13, 2017 at 15:44
  • $\begingroup$ We are using MS Office 2010, Word 14.0.7177.5000 (32-bit) and Mathematica 11.0.1 running on Windows 7 and 10. Attaching EMFexplorer screenshots to my answer. $\endgroup$ Commented Jan 13, 2017 at 16:31

1 Answer 1

1
$\begingroup$

To make the EMF look OK when imported into Word use

Export["a.emf", a, ImageResolution -> 300]

This makes the EMF big, and the increased resolution isn't necessary in Mathematica 7 EMFs, but it fixes the appearance.

Font map editing was also required to fix the EMF rendering of % sign and brackets, as detailed here: Wrong font selection for some characters.

Word screenshot

enter image description here

EMFexplorer images

  1. Default resolution & original font map

  2. Resolution set to 300 & original font map

  3. Resolution set to 300 & edited font map

The % and ( ) font issues don't show up so much in EMFexplorer but they certainly show in Word and Paint (the default app from EMF on Windows).

$\endgroup$
2
  • $\begingroup$ (+1) I have checked this solution with versions 8.0.4, 10.4.1 and 11.0.0 on Windows 7 x64, it works! Obviously the problem is here at least starting from version 8.0.4. $\endgroup$ Commented Jan 14, 2017 at 19:52
  • $\begingroup$ Thanks for checking the other versions Alexey. $\endgroup$ Commented Jan 14, 2017 at 19:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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