What's the best way to draw UML class diagrams in LaTeX?

  • 5
    Would you mind adding a little context, or a link to a description or (better still) a picture of the sort of thing that you'd like? Someone may be able to help but not know what a UML diagram is. Thanks! – Andrew Stacey Aug 3 '10 at 9:19
  • 5
    UML stands for unified modelling language. en.wikipedia.org/wiki/… – Willie Wong Aug 3 '10 at 11:58
  • MetaUML is a MetaPost library for typesetting UML diagrams with a human-friendly textual notation. Another useful package is emp. It allows to embed Metapost code and therefore MetaUML inside a LaTeX document
  • pst-uml is a PSTricks package providing support for drawing UML diagrams.
  • uml is another package using PSTricks implementing at least a subset
  • pgf/TikZ is so feature rich that it can be used for typesetting UML diagrams as well
  • tikz-uml is a UML-specialized TikZ package
  • 5
    My guess would be that this is the sort of algorithmic-drawing example where Metapost would be a natural choice, but that fits for GraphViz, too. – Norman Gray Aug 3 '10 at 14:24
  • See Giel's answer for a pgl library. – Kevin Vermeer Aug 5 '10 at 1:41
  • 2
    +1 MetaUML looks really nice both the syntax and the output. – Johan Nov 14 '10 at 13:47
  • 1
    I highly recommend tikz-uml, very flexible, comprehensive and nice looking. Support the author, please. All other packages are very old (last, about 2006) and based on old packages,... pgf-Tikz is too generic. – user14416 Apr 26 '15 at 17:54

For UML class diagrams I'd recommend pgf-umlcd, for sequence diagrams pgf-umlsd (example by the author). Both packages are based on the PGF package collection, which I find very easy to use for drawing vector graphics within TeX & LaTeX.


A nice package I found a while ago is this: TikZ-UML.

It provides:

  • Class diagrams.
  • Use cases.
  • State-transitions.
  • Sequence diagrams.

It works pretty well, at least with the sequence diagrams I used.

  • The install section says "coming soon" for probably quite a while already. Don't be discouraged, the downloadable archive contains nice examples. – BadAtLaTeXProgramming Mar 13 '18 at 14:54

(Lifted from Dima's answer to my question on flowcharts.) You can also use the Dot language and GraphViz. With UMLGraph you can generate GraphViz specs, and use dot2tex or Mark Aufflick's graphviz.sty to embed the graphs into LaTeX.

  • auto-upvote =))))) – Dima Aug 3 '10 at 16:19

While I guess there are nicer ways to do it, I recently came across this example on texample.net on one way to produce UML diagrams with TikZ.

  • The nice thing about this is that it doesn't break TikZ relative positioning .. some of the other solutions appear to require manual positioning of all elements. – M Juckes Oct 3 '20 at 8:28
  • I had problems with \draw{myarrow} trying to replicate the example. I got the error ! Argument of \language@active@arg> has an extra }. <inserted text> \par l.230 \draw[myarrow] (CoolingSystem.north) -- ++(0,0.8) -| (System.south); – rvcristiand Jan 2 at 1:56

For what it's worth, yet another option is PlantUML.

PlantUML takes pseudo-code-y plain-text class descriptors and generates UML diagrams (as PNG, SVG or EPS, possibly others). It's a Java-based program that uses Graphviz on the back-end to determine layouts.

In addition to class/object diagrams, PlantUML can also generate other UML diagrams like sequence, activity, state, use case diagrams.

There's nothing particularly LaTeX-specific about it, and you'll probably need or want to store the class descriptors in an independent file but I've often used PlantUML (or for that matter, ditaa) as part of a LaTeX publishing workflow.

  • i recommend the eps format to export, because its lossless and latex can use it natively – Ohmen Mar 6 '20 at 16:59

Tangentially related to Willie's answer, if you think you might use graphviz to generate the diagrams, you might consider doxygen.

This approach would be especially handy if you have more documentation than just the diagrams to create. Doxygen is intended to document software projects. If you have a set of classes in C++ or java, then you can use doxygen to generate latex from the source code. It can automatically generate several types of diagrams from the source, including UML class diagrams all hyperlinked and integrated with the rest of the documentation and its source code.

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.