0

I just discovered the package pgf-umlcd and I am unable to draw enum types, I tried the obvious:

\begin{enum} 
\begin{enumeration}
\begin{enumclass} 

However none of these work. I did some Google research but was not able to find the correct line of code. Anyone knows?

I add this working code in case it can help.

\documentclass[9pt]{article}
\usepackage{pgf-umlcd}

\begin{document}

\begin{tikzpicture} \begin{class}[text width=7cm]{ClassName}{0,0} \attribute{Attribute1 : Type} \attribute{Attribute2 : Type} \operation{Method1(parameter list) : Returned Type } \operation{Method2(parameter list) : Returned Type } \end{class} \end{tikzpicture}

\end{document}

Kind regards and thank you in advance. Miguel

  • Please add a full example document to your question that can be compiled and that shows a simple diagram with a node in which you want to use an enum type. This would save time for the people interested in answering your questions, and it may prevent compatibility issues. – Marijn Oct 18 '22 at 19:49
  • OK, I added a working example in case it helps. In my opinion it is just misleading because the code I posted is for classess but what I need is an enum type and I just can´t find the right keyword for it, the author does not show any example on the documentation...maybe it does not exist? – Miguel Garcia Oct 22 '22 at 21:15
  • The answer seems to be in the following webpage, however I do not know what to make of this code, where should I put it? Any help is very much appreciated. https://github.com/jcb/these-jcb/blob/master/custom_pgf-umlcd.sty – Miguel Garcia Oct 22 '22 at 21:43

1 Answers1

1

The custom style https://github.com/jcb/these-jcb/blob/master/custom_pgf-umlcd.sty linked by the OP in a comment contains an implementation of enum nodes. This file also contains the original code from pgf-umlcd, so it could be used as a replacement (i.e., \usepackage{custom_pgf-umlcd} instead of \usepackage{pgf-umlcd}) that offers the original functionality of pgf-umlcd together with the additional features like enum nodes. However, the file is based on a version of pgf-umlcd from 2014, so it lacks recent developments to the package. Therefore it is better to load pgf-umlcd normally and copy only the code related to enum classes from the modified package.

The enum functionality consists of a tikzstyle and an environment. In the MWE below these are copied. The environment is used like a normal class, and the enumeration items are listed using \attribute{} (one for each item).

MWE:

\documentclass{article}
\usepackage{pgf-umlcd}
% enum style and environment from
% https://github.com/jcb/these-jcb/blob/master/custom_pgf-umlcd.sty
% Author: Jean-Christophe Bach
\tikzstyle{umlcd style enum}=[rectangle split, rectangle split parts=2, 
every text node part/.style={text centered},
draw, minimum height=2em, umlcolor, minimum width=2cm, text width=4cm,
minimum height=1cm, node distance=2cm]
\newenvironment{enum}[3][]%
{
\begin{classAndInterfaceCommon}{#1}{#2}{#3}
}%
{\node[umlcd style enum, anchor=north] (\umlcdClassName) at (\umlcdClassPos)
    {$<<$enumeration$>>$ \\ \textbf{\umlcdClassName}
\nodepart{second}
\umlcdClassAttributes
};
\end{classAndInterfaceCommon}
}

\begin{document}

\begin{tikzpicture} \begin{class}[text width=7cm]{ClassName}{0,4} \attribute{Attribute1 : Type} \attribute{Attribute2 : Type} \operation{Method1(parameter list) : Returned Type } \operation{Method2(parameter list) : Returned Type } \end{class} \begin{enum}[text width=7cm]{Colors}{0,0} \attribute{Red} \attribute{Green} \attribute{Blue} \end{enum}
\end{tikzpicture}

\end{document}

Result:

enter image description here

Marijn
  • 37,699