What's the best way to draw UML class diagrams in LaTeX?
-
5Would 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 StaceyCommented Aug 3, 2010 at 9:19
-
5UML stands for unified modelling language. en.wikipedia.org/wiki/…– Willie WongCommented Aug 3, 2010 at 11:58
8 Answers
- 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
-
6My 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. Commented Aug 3, 2010 at 14:24
-
-
2+1 MetaUML looks really nice both the syntax and the output.– JohanCommented Nov 14, 2010 at 13:47
-
1I 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. Commented Apr 26, 2015 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.
-
Your link is broken, there's some extra text at the end. Commented Oct 28, 2010 at 18:06
-
Try this link instead: loria.fr/~quinson/blog/2010/11/05/UML_class_diagrams_in_tikz– yegor256Commented Feb 24, 2011 at 9:14
-
Correct link is now: loria.fr/~quinson/blog/2010/1105/UML_class_diagrams_in_tikz. TeXample using pgf-umlsd: texample.net/tikz/examples/pgf-umlsd– przemocCommented Jul 12, 2011 at 13:47
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.
-
1The install section says "coming soon" for probably quite a while already. Don't be discouraged, the downloadable archive contains nice examples. Commented Mar 13, 2018 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.
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– OhmenCommented Mar 6, 2020 at 16:59
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 JuckesCommented Oct 3, 2020 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); Commented Jan 2, 2021 at 1:56
-
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.
It is not a native LaTeX solution but PlantText is also a good online editor for creating a lot of different diagramms that can be saved as SVG
.