Wrong class widths after LaTeX export

0 votes
asked Sep 28, 2017 in Closed feature request by Dresaan (400 points)

This might be a bit tricky. In some cases the classes are rendered to small with LaTeX. As far as I can see from the TikZ output, the boxes are simply to small. Below is a sample to demonstrate it:

class Utility
class Uuuuuuu
class iiiiii
class Licensing

Some parameter to set sizes in Latex would be welcome.

1 Answer

0 votes
answered Sep 29, 2017 by plantuml (257,860 points)
selected Oct 2, 2017 by Dresaan
Best answer
This one is very difficult to solve.
Because box width are computed in Java using standard Java font.
And drawing is done by LaTeX using LaTeX font, which means that size does not match between both.

However, we've made few tests. We've written some heuristic which tries to guess how the font will size in LaTeX.

You can use beta 18 to check it:


Unfortunately the result will never be perfect here.
Tell us if it's somehow better!
commented Oct 2, 2017 by Dresaan (400 points)
It is a lot better now. Some objects become too big, but that is much better than too small.

You might hate me now, but what about the idea of letting TikZ sizing the Boxes?
I tried the following TikZ-Code:

\node at (112.5pt,160pt)[    below right,
                    line width = 1.5pt,    
                    inner sep = 9pt,
                     top color=yellow,
                     bottom color=blue,
                    shading angle=45]   

It reproduces nearly the same output (except the test-colors).
A little problem is that I use classes without anything at the moment. They are just rectangles. For more complex objects, you would need to define shapes. This might probably be the most designated way to do diagrams like this in TikZ.
Another point is that I don’t know how much that will change your layout, but probably not that much.
I have never defined a shape in TikZ before. If you want my help for that, I need to find time.
commented Oct 2, 2017 by plantuml (257,860 points)
No, we don't hate you :-) We thank you for your suggestions and your tests, it's really useful!

However unfortunately, we cannot let Tikz do the size computation. Size computations have to be done in Java because there might have some edges between classes, so Java do have to know the exact box sizes to exactly compute edges position.

Anyway, we are now using two parameters to extrapolate between Java font size and Tikz font size:

The first one (1.2 beeing it's default value) is a simple zoom factor. A value of 1.2 means that we take the Java "Serif" font size and we multiply the result by 1.2 to have the expected Tikz font width.

The second one (4.0 beeing it's default value) is more tricky to explain. We try to detect large characters like "w" which are really different in Tikz and in Java. To do so, we compute Java "Serif" width of the text to be printed using both a slightly smaller font size and a slightly bigger font size. The difference between those two values gives an idea of the quantity of "large" characters in the string to be printed. This difference will be multiply by 4.0 and decrease from the total width. (Ok that's weird, but it seems to give good results).

With last beta (beta20), you can change the default values of those parameters.


Just use the skinparam tikzFont and give two values separated by ;

skinparam tikzFont 1.2;4.0
class Wwwwwwwwwwwwwwww
class Uuuuuuuuuuuuuuuuuuuuuuuu
class iiiiii
class Licensing

Tell us if you find better values than our defaults :-)

commented Oct 4, 2017 by Dresaan (400 points)
I already suspected the rendering.
I will try different values if I notice problems. But I think, the default font even differs whether you compile the LaTeX with windows or linux.

Then another idea. What about to set your used font as the TikZ font?
That might have some disadvantages like a second font in the document but that might fix the size difficulty.
Since not everybody will like that, there should be an option to disable the PlantUML font to use the used latex font.
So that the user can decide between two modes:
1. (default) The export sets the PlantUML font
2. The export ignores the font and uses the 2-paramter trick.
commented Oct 4, 2017 by plantuml (257,860 points)
> What about to set your used font as the TikZ font?
This would mean import theTikZ font so that they could be used in Java.
It sounds like a good idea, but I have no idea about how to do that.
commented Oct 5, 2017 by Dresaan (400 points)
no, I mean the other direction :-D

In TikZ, you can change the font. So you would need to parse the LaTeX-files/-project for the font.

PlantUML is propably using a font, that is known to the system. That would mean that you can use the same font in LaTeX/TikZ. Just export the font that is used by PlantUML to TikZ. The widths should be correct with the same font.
commented Oct 5, 2017 by Dresaan (400 points)
Or you add an option to change the font in TikZ manually. That might also be a nice feature.
Something like:
skinparam font Arial;
commented Oct 5, 2017 by plantuml (257,860 points)
Sure: if Java And LaTeX would use the same fonts, things will be easier.

Basically, Java uses TTF fonts:

In LaTeX, it seems to be somehow more complex:

However, something like "skinparam font Arial" if a good idea, and is easy to do.
We just need help in the LaTeX/TikZ generated text...
When we print text, we generate something like:

\node at (12pt,44pt)[below right,color=black]{foo1};

Any idea how/where to add "Arial" in the LaTeX command ?
commented Oct 10, 2017 by Dresaan (400 points)
I thought it would be possible to just specify a font family and the LaTeX-Engine automatically tries to parse the font and search it in the system fonts. Unfortunately, it does not. I found some information about how to set a font in LaTeX but they use predefined a package to set the font or need the font files. Both ways are not really flexible.
The best of these ways would be to use the predefined packages. But you could also only use these packages and that are just a few. Also, you need a usepackage for every font, which might obfuscating if you export without preamble.
commented Jan 2, 2018 by Jack
edited Jan 2, 2018
What do you mean with edge positions? TikZ handles arrows very fine. You would just have to connect the blocks and TikZ does all the positioning magic. Is that what you need?