1

In learning how to create higher quality diagrams, I came across the tikz package and specifically this example tutorial web page (www.texample.net/tikz/examples/class-diagram/).

I verbatim took the script provided there, and I am able to compile it to make the diagram as shown in the link.

However, I then tried to embed that diagram into my main document using \input and I could not get it to work.


Full Code Details

Parent file (attempting to embed the RDB_diagram_shell.tex file):

% Load necessary packages

\documentclass[pdf]{beamer}

\usetheme{Berkeley} % I like this theme better
\usecolortheme{wolverine} % This gives the orange colorscheme
\usepackage{standalone} % I was trying to use this package to embed diagram files within here.
\usetikzlibrary{positioning,shapes,shadows,arrows}
%

%%%%%%%%%%%%%%%%%%%%%%%%
% Title Slide
\title{Blah}
\author{Mike Williamson}

\begin{document}
%%%
\begin{frame}
\frametitle{RDB Tables Example}

\input{RDB_diagram_shell}
\end{frame}

\end{document}

RDB_diagram_shell.tex:

% DB Layout diagram

\begin{tikzpicture}[node distance=2cm]
%\coordinate (origin) at (50,50);

\node (Order) [facttable, rectangle split, rectangle split parts=2] {
    \textbf{ORDER}
    \nodepart{second}
        order\_num (PK) \\
        customer\_ID (FK) \\
        store\_ID (FK) \\
        clerk\_ID (FK) \\
        date        
};
\node (AuxNodeTop) [text width=0.5cm, above=of Order, shift={(0,-1.5cm)}] {};
\node (Store) [dimtable, rectangle split, rectangle split parts=2, left=of AuxNodeTop] {
    \textbf{STORE}
    \nodepart{second}
        store\_ID (PK) \\
        store\_name \\
        address \\
        district \\
        floor\_type 
};

\node (Clerk) [dimtable, rectangle split, rectangle split parts=2, right=of AuxNodeTop] {
    \textbf{CLERK}
    \nodepart{second}
        clerk\_ID (PK) \\
        clerk\_name \\
        clerk\_grade
};

\node (Customer) [dimtable, rectangle split, rectangle split parts=2, below=of Order, shift={(0,1cm)}] {
    \textbf{CUSTOMER}
    \nodepart{second}
        customer\_ID (PK) \\
        customer\_name \\
        purchase\_profile \\
        credit\_profile \\
        address
};

\draw[rightarrow] (Store.south) -- ++(-0.5, 0) -| (Order.west);
\draw[leftarrow] (Clerk.south) -- ++(0.5, 0) -| (Order.east);
\draw[uparrow] (Customer.north) -| (Order.south);

\end{tikzpicture}

That is the entirety of both scripts.

Error

I am receiving the following error:

...DB_diagram.tex:20: Package pgfkeys Error: I do not know the key '/tikz/rectangle split' and I am going to ignore it. Perhaps you mis-spelled it.

It seems to suggest I cannot have the words rectangle and split separated by a space character. (Note: these key words only exist within the file being embedded, which compiles fine when compiled alone.) But then why does it work when I make the file alone, without embedding it?


Again, to reiterate:

  • I am able to compile the diagram when I compile it alone. But I am not able to compile it when it is embedded in a small, shell file.
    • Why is that? What am I doing wrong?

Edit

Some of the commentors below wanted to see the actual file. The Tex files are both given above, so I presume the commentor wanted to see the rendered file from the smaller Tex file which I could compile. Here it is:

Rendered RBD Diagram Shell file

  • 3
    Welcome to TeX.SE! When you are saying you can compile the file when it is embedded in a small shell file, what is there in the preamble? I suspect the error goes away when you include \usetikzlibrary{shapes.multipart} in the preamble of your main document. – user121799 Aug 24 '18 at 4:34
  • @marmot Thanks! That helped... somewhat. Now instead of the error given above, I received Package PGP Math Error: Unknown function 'of' (in 'of Item'). This is coming from the line \node (AuxNode01) [text width=4cm, below=of Item] {};. Now it seems that line cannot properly be identified. But, can you tell me why this shapes.multipart helped? And also, how could I have found that documentation? I didn't see anything anywhere about multipart (until now, since I know what to search for.) Thanks! – Mike Williamson Aug 24 '18 at 6:08
  • Oh, and @marmot , the pre-amble is exactly what I wrote in the question. That code, plus the code in the provided link, are the entirety of what I wrote. (I had a more complex .tex file at first, but I pared it down to make the example easier.) – Mike Williamson Aug 24 '18 at 6:10
  • 1
    Sorry, not quite. You can certainly not compile RDB_diagram_shell.tex, can you? And what happens if you add \usetikzlibrary{positioning,shapes,shadows,arrows} to your main preamble? – user121799 Aug 24 '18 at 23:19
  • 1
    You definitely can't compile any file which starts \begin{tikzpicture} on its own. Regardless. You must wrap it in a document and provide a preamble. It is that preamble which makes the difference. That preamble sets up things like rectangle split and the of syntax - things which are not defined if you load tikz on its own. – cfr Aug 25 '18 at 3:48
2

you have more issues with your document examples:

  • the package standalone from "standalone" file with your images strip out its preamble, \begin{document} and\end{document} and import to main document only image code. consequently all packages and definitions in standalone are invisible to the main document.
  • if tikzpicture contain some options append to it in square brackets, than the frame in main document had to have option [fragile]
  • as solution of your problems you need add to main file complete preamble of the "standalone" file. so far it seems that you add only a part of its preamble, consequently missing packages and style definitions cause reported errors.
  • since your styles used in your "standalone" file are unknown to us, i reconstruct own styles (try to use mine, it seems that they are shorter and more consistent) and embedded it to tikz picture:

    \documentclass{beamer}
    \usetheme{Berkeley}       % I like this theme better
    \usecolortheme{wolverine} % This gives the orange colorscheme
    \usepackage{standalone}   % I was trying to use this package to embed diagram files within here.
    \usepackage{tikz}
    \usetikzlibrary{arrows.meta,      % <----
                    positioning,
                    shadows, 
                    shapes.multipart}  % <----
    
    \begin{document}
    %%%%
    \begin{frame}[fragile]          % <----
    \frametitle{RDB Tables Example}
    
    % for simplify tests i include the content of the "standalone" file here
        \begin{tikzpicture}[        % <----
    node distance = 5mm and 3mm,
       MPN/.style args = {#1/#2}{% Multi Part Node            % <----
                     rectangle split, rectangle split parts=2,
                     draw, rounded corners,
                     fill=#1,
                     text=#2, font=\footnotesize\linespread{0.9}\selectfont,
                     text width=28mm, align=center, 
                     drop shadow},
       MPN/.default = blue!50/white,                          % <----
       arr/.style = {semithick, -{Triangle[open]}}            % <----
                            ]
    \node (Order) [MPN=green!30/black] {                      % <----
        \textbf{ORDER}
        \nodepart{second}
            order\_num (PK) \\
            customer\_ID (FK) \\
            store\_ID (FK) \\
            clerk\_ID (FK) \\
            date
                        };
    \node (Store) [MPN, above left=of Order.west] {           % <---- 
        \textbf{STORE}
        \nodepart{two}
            store\_ID (PK) \\
            store\_name \\
            address \\
            district \\
            floor\_type
                        };
    \node (Clerk) [MPN, above right=of Order.east] {          % <----
        \textbf{CLERK}
        \nodepart{two}
            clerk\_ID (PK) \\
            clerk\_name \\
            clerk\_grade
                        };
    \node (Customer) [MPN, below=of Order] {                  % <----
        \textbf{CUSTOMER}
        \nodepart{two}
            customer\_ID (PK) \\
            customer\_name \\
            purchase\_profile \\
            credit\_profile \\
            address
                        };
    \draw[arr] (Store) |- (Order);     % <----
    \draw[arr] (Clerk) |- (Order);     % <----
    \draw[arr] (Customer) -- (Order);  % <----
        \end{tikzpicture}
    \end{frame}
    \end{document}
    

which gives

enter image description here

the same result you should obtain with

    \documentclass{beamer}
    \usetheme{Berkeley}       % I like this theme better
    \usecolortheme{wolverine} % This gives the orange colorscheme
    \usepackage{standalone}   % I was trying to use this package to embed diagram files within here.
    \usepackage{tikz}
    \usetikzlibrary{arrows.meta,
                    positioning,
                    shadows, shapes.multipart}

    \begin{document}
    \begin{frame}[fragile]
    \frametitle{RDB Tables Example}
    \input{RDB_diagram_shell}
    \end{frame}
    \end{document}

where RDB_diagram_shell is

    \documentclass[tikz]{standalone}   % diagram "RDB_diagram_shell".
    \usetikzlibrary{arrows.meta,
                    positioning,
                    shadows, shapes.multipart}

    \begin{document}
    % code of `tikzpicture` as is written in complete mwe above
    \end{document}
| improve this answer | |

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.