Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

My ER Diagram is finally complete. But I need help in making it look complete. I need changes in,
i) Making the diagram centered to the page
ii)Adjusting the node distances (need very badly, not able to do as well)
iii)Giving a label to the diagram.

Here is my code:

\documentclass[12pt]{article}
\usepackage{tikz-er2}
\usepackage{pdflscape}
\usepackage{adjustbox}
\usetikzlibrary{shadows,positioning}
\begin{document}
\tikzset{
    every entity/.style = {top color=white,bottom color=blue!30,draw=blue!50!black!100,drop shadow},
    every attribute/.style = {top color=white, bottom color=yellow!20,
                                  draw=yellow, drop shadow},
    every relationship/.style ={top color=white, bottom color=red!20,
                                  draw=red!50!black!100, drop shadow},
    every edge/.style = {link},
    every isa/.style = {top color=white, bottom color=green!20,
                                  draw=green!50!black!100, drop shadow},
}
\begin{landscape}
\begin{adjustbox}{max height=0.5\textwidth}
\begin{tikzpicture}[node distance=10em]
    \node[entity] (student) at (-2,0) {Student};
    \node[isa] (isa1) [below = 2em of student, node distance=5em] {ISA} edge node [auto,swap] {disjoint} (student);
    \node[entity] (mtech-stud) [below left = 2em of isa1] {MTech$-$student} edge (isa1);
    \node[attribute] (btechproj) [below left = 2em of mtech-stud] {No.-of-BTech-Projects} edge (mtech-stud);
    \node[entity] (btech-stud) [below = 4em of isa1] {BTech$-$student} edge (isa1);
    \node[entity] (phd-stud) [below right = 2em of isa1] {Ph.D.$-$student} edge (isa1);
    \node[attribute] (btechproj1) [below left = 2em of phd-stud] {No.-of-BTech-Projects} edge (phd-stud);
    \node[attribute] (mtechproj) [below right = 2em of phd-stud] {No.-of-MTech-Projects} edge (phd-stud);
    \node[attribute] (stud-id) [left = 0.5cm of student] {\key{student-id}} edge (student);
    \node[attribute] (name) [above left = 0.75cm and 0cm of student] {Name} edge (student);
    \node[attribute] (fname) [above left = 0.75cm and 0cm of name] {First-Name} edge (name);
    \node[attribute] (lname) [above right = 0.75cm and 0cm of name] {Last-Name} edge (name);
    \node[attribute] (cgpa)  [above right = 0.75cm and 0cm of student] {CGPA} edge (student);
    \node[relationship] (joins) [right = 3cm of student] {joins} edge [total] (student);
    \node[entity] (pgroup) [right = 3cm of joins] {Project-Group} edge [<-] (joins);
    \node[attribute] (group-id) [above left = 0.75cm and 0cm of pgroup] {\key{group-id}} edge (pgroup);
    \node[derived attribute] (group-cgpa) [above = 2cm and 0cm of pgroup] {group-CGPA} edge (pgroup);
    \node[multi attribute] (areas) [above right = 0.75cm and 0cm of pgroup] {areas-of-interest} edge (pgroup);
    \node[relationship] (pgroup-guide) [right = 3cm of pgroup] {Project-Group-Guide} edge[<->] (pgroup);
    \node[attribute] (pdomain) [above left = 2.5cm and 0cm of pgroup-guide] {Project-Domain} edge (pgroup-guide);
    \node[attribute] (ptitle) [above right = 2.5cm and 0cm of pgroup-guide] {Project-Title} edge (pgroup-guide);
    \node[entity] (faculty) [right = 3cm of pgroup-guide] {Faculty} edge[<->] (pgroup-guide);
    \node[attribute] (facid) [above left = 0.75cm and 0cm of faculty] {\key{faculty-d}} edge (faculty);
    \node[attribute] (name) [above = 1.5cm and 0cm of faculty] {Name} edge (faculty);
    \node[attribute] (fname) [above left = 0.75cm and 0cm of name] {First-Name} edge (name);
    \node[attribute] (lname) [above right = 0.75cm and 0cm of name] {Last-Name} edge (name);
    \node[multi attribute] (specialisation) [above right = 0.75cm and 0cm of faculty] {Specialisation} edge (faculty);
    \node[attribute] (email) [below left = 0.75cm and 0cm of faculty] {Email} edge (faculty);
    \node[multi attribute] (phoneno) [below right = 0.75cm and 0cm of faculty] {Phone-no} edge (faculty);
\end{tikzpicture}
\end{adjustbox}
\end{landscape}
\end{document} 

enter image description here

share|improve this question
    
i) Try encompassing tikzpicture environment with \begin{center}. ..\end{center}. ii) try defininh an auxiliary node with a fixed text width but leave empty. This will allow you to put in space between nodes. Have an example on work pc. .monday! Also try |- to get horizontal and vertical paths, may help clear it up. iii) thinking about it! –  Leeser Mar 8 at 17:26
    
If I put \begin{center}.. I get error @Leeser –  subham soni Mar 8 at 17:48
    
No pc to test it out. Will look on Monday. –  Leeser Mar 8 at 18:11
    
Why all those manual adjustments of node position? And why do you mix em and cm for node positioning? (a change in the default font size will affect lengths defined using em, but not those using cm). –  Gonzalo Medina Mar 9 at 1:07

2 Answers 2

up vote 4 down vote accepted

If you are going to resize (anyway), those manual distances between nodes are not necessary. Also, it would not be a good idea to mix em and cm. The lengths expressed in em will adopt to font size changes while those in cm are fixed. As a result, if you change the font size, you may end up with inconsistent spacings. I have not fixed them in this answer and you may do it by yourself in case if needed ;).

Here you go. I had a doubt regarding center. If it is vertically centered or horizontally centered was not clear to me. I made it vertically centered (in a landscape page). Also I have changed some topology and adjusted the distances.

\documentclass[12pt]{article}
\usepackage{tikz-er2}
\usepackage{pdflscape}
\usepackage{adjustbox}
\usetikzlibrary{shadows,positioning}
\begin{document}
\tikzset{
    every entity/.style = {top color=white,bottom color=blue!30,draw=blue!50!black!100,drop shadow},
    every attribute/.style = {top color=white, bottom color=yellow!20,
                                  draw=yellow, drop shadow},
    every relationship/.style ={top color=white, bottom color=red!20,
                                  draw=red!50!black!100, drop shadow},
    every edge/.style = {link},
    every isa/.style = {top color=white, bottom color=green!20,
                                  draw=green!50!black!100, drop shadow},
}
\begin{landscape}
\vspace*{\stretch{1}}
\begin{adjustbox}{max height=0.5\textwidth}
\begin{tikzpicture}[node distance=10em]
    \node[entity] (student) at (-2,0) {Student};
    \node[isa] (isa1) [below = 2em of student, node distance=5em] {ISA} edge node [auto,swap] {disjoint} (student);
    \node[entity] (mtech-stud) [below left = 2em of isa1] {MTech$-$student} edge (isa1);
    \node[attribute] (btechproj) [below left = 2em and 0em of mtech-stud] {No.-of-BTech-Projects} edge (mtech-stud);
    \node[entity] (btech-stud) [below = 5em of isa1] {BTech$-$student} edge (isa1);
    \node[entity] (phd-stud) [below right = 2em of isa1] {Ph.D.$-$student} edge (isa1);
    \node[attribute] (btechproj1) [above right = 2em of phd-stud] {No.-of-BTech-Projects} edge (phd-stud);
    \node[attribute] (mtechproj) [below right = 2em of phd-stud] {No.-of-MTech-Projects} edge (phd-stud);
    \node[attribute] (stud-id) [left = 0.5cm of student] {\key{student-id}} edge (student);
    \node[attribute] (name) [above left = 0.75cm and -0.5cm of student] {Name} edge (student);
    \node[attribute] (fname) [above left = 0.75cm and 0cm of name] {First-Name} edge (name);
    \node[attribute] (lname) [above right = 0.75cm and 0cm of name] {Last-Name} edge (name);
    \node[attribute] (cgpa)  [above right = 0.75cm and -0.5cm of student] {CGPA} edge (student);
    \node[relationship] (joins) [right = 1.4cm of student] {joins} edge [total] (student);
    \node[entity] (pgroup) [right = 1.4cm of joins] {Project-Group} edge [<-] (joins);
    \node[attribute] (group-id) [above left = 0.75cm and -0.5cm of pgroup] {\key{group-id}} edge (pgroup);
    \node[derived attribute] (group-cgpa) [above = 2cm of pgroup] {group-CGPA} edge (pgroup);
    \node[multi attribute] (areas) [above right = 0.75cm and -0.5cm of pgroup] {areas-of-interest} edge (pgroup);
    \node[relationship] (pgroup-guide) [right = 2.2cm of pgroup] {Project-Group-Guide} edge[<->] (pgroup);
    \node[attribute] (pdomain) [above = 2cm  of pgroup-guide] {Project-Domain} edge (pgroup-guide);
    \node[attribute] (ptitle) [below = 2cm of pgroup-guide] {Project-Title} edge (pgroup-guide);
    \node[entity] (faculty) [right = 1.9cm of pgroup-guide] {Faculty} edge[<->] (pgroup-guide);
    \node[attribute] (facid) [above left = 0.75cm and -0.5cm of faculty] {\key{faculty-d}} edge (faculty);
    \node[attribute] (name) [above = 1.7cm of faculty] {Name} edge (faculty);
    \node[attribute] (fname) [above left = 0.75cm and 0cm of name] {First-Name} edge (name);
    \node[attribute] (lname) [above right = 0.75cm and 0cm of name] {Last-Name} edge (name);
    \node[multi attribute] (specialisation) [above right = 0.75cm and -0.5cm of faculty] {Specialisation} edge (faculty);
    \node[attribute] (email) [below left = 0.75cm and -0.5cm of faculty] {Email} edge (faculty);
    \node[multi attribute] (phoneno) [below right = 0.75cm and -0.5cm of faculty] {Phone-no} edge (faculty);
\end{tikzpicture}
\end{adjustbox}
\vspace{\stretch{1}}
\end{landscape}
\end{document}

enter image description here

share|improve this answer
    
You could even plan to branch the diagram instead making it to grow to he right. But that is a different question. –  Harish Kumar Mar 9 at 1:41
    
If I branch the diagram, it will grow beyond a single page ? I will try that too. @Harish Kumar –  subham soni Mar 9 at 3:41

I promised I'd give an example of something I had involving empty or auxiliary nodes to help with alignment and spacing. So below for information as you have already accepted an answer. It is setup for A3 paper but may be adjusted and instead of using cm could use em for positioning and widths so scales properly as @GonzaloMedina points out in his comment

The following is a flow chart for looking at which type of reaction occurs under differing conditions and starting materials...

\documentclass{minimal}
\usepackage[a3paper,margin=1cm]{geometry}
\usepackage{tikz}
\usepackage{chemmacros}
\usetikzlibrary{positioning,shapes,shadows,arrows}


\begin{document}
\tikzstyle{sstart}=[rectangle, draw=black, rounded corners, fill=yellow!50!brown, drop shadow,text centered, anchor=north, text=black, text width=3cm]
\tikzstyle{comment}=[rectangle, draw=black, rounded corners, fill=brown!20, drop shadow,
    text centered, anchor=north, text=black, text width=3cm]
\tikzstyle{mech}=[rectangle, draw=black, rounded corners, fill=green!20, drop shadow,
    text centered, anchor=north, text=black, text width=3cm]
\tikzstyle{myarrow}=[->, >=open triangle 90, very thick]
\tikzstyle{line}=[-, thick]

\begin{center}
\begin{tikzpicture}[node distance=2cm]
\node (Item) [sstart]%, rectangle split, rectangle split parts=2]
    {
        \textbf{START}
        \nodepart{second}name
    };
\node (AuxNode01) [text width=5cm, below=of Item] {};% THIS NODE DOES NOT APPEAR BUT ALLOWS NODES TO BE ALIGNED TO IT
\node (GN) [comment, rectangle split, text width =5cm, rectangle split parts=3, left=of AuxNode01]
    {
        \textbf{\textcolor{green!50!black}{Good}\\ Nucleophile}
        \nodepart{second}\ch{RO-}, \ch{R2N-}, \ch{R3N}, \ch{RS-}
\nodepart{third} have lots of electrons or negative charge it wants to give away
    };
\node (BN) [comment, rectangle split, rectangle split parts=3, right=of AuxNode01]
    {
        \textbf{\textcolor{red!80!black}{Poor}\\ Nucleophile}
        \nodepart{second}\ch{ROH} \ch{H2O}
\nodepart{third} have a shortage of electrons or positive charge
    };
\node (Bimo) [comment, rectangle split, rectangle split parts=2, text width=5cm, below=of GN]
    {
        \textbf{Bimolecular}
        \nodepart{second}Good Nucleophiles share the work of the reaction. Nu attacks and Leaving group leaves at the same time
    };

\node (Hind) [comment, rectangle split, rectangle split parts=2, below=of Bimo]
    {
        \textbf{\textcolor{red!80!black}{HINDERED}\\ Electrophile}
        \nodepart{second}Neopentyl C\\ 
3$^{\circ}$ C\\
\
    };
    \node (AuxNode02) [text width=0.25cm, left=of Hind] {};%AGAIN, ALIGNMENT PURPOSES ONLY
\node (Unhind) [comment, rectangle split, rectangle split parts=2, left=of AuxNode02]
    {
        \textbf{\textcolor{green!50!black}{UNHINDERED}\\Electrophile}
        \nodepart{second}
Methyl C\\ 
1$^{\circ}$ C\\
\
    };
\node (AP) [comment, rectangle split, rectangle split parts=2, below left=of Hind, xshift=2cm]
    {
        \textbf{\textcolor{green!50!black}{ANTI-PERIPLANAR} Configuration}
        \nodepart{second}Access to $\sigma^{\star}$ of leaving group\\

    };
\node (NAP) [comment, rectangle split, rectangle split parts=2, right=of AP]
    {
        \textbf{\textcolor{red!80!black}{NO ANTI-PERIPLANAR} Configuration}
        \nodepart{second}No access to $\sigma^{\star}$ of leaving group\\
    };

\node (Unimo) [comment, rectangle split, rectangle split parts=2, text width=5cm, below=of BN]
    {
        \textbf{Unimolecular}
        \nodepart{second}Bad nucleophiles don't like having to do any work leaving the initial step to the loss of leaving group
    };
 \node (Unstab) [comment, rectangle split, rectangle split parts=2, below=of Unimo]
    {
        \textbf{\textcolor{red!80!black}{Unstabilised}\\Carbocation}
        \nodepart{second}Methyl \ch{C^+}\\ 
1$^{\circ}$ \ch{C^+}\\
\ 

    };
 \node (Stab) [comment, rectangle split, rectangle split parts=2, left=of Unstab]
    {
        \textbf{\textcolor{green!50!black}{Stabilised}\\Carbocation}
        \nodepart{second}Resonant \ch{C^+}\\
    3$^{\circ}$ \ch{C^+}\\
    2$^{\circ}$ \ch{C^+}
    };

\node (NAPNR) [mech, fill=red!20,rectangle split, rectangle split parts=2, below=of NAP]
    {
        \textbf{No Reaction}
        \nodepart{second}No access to $\sigma^{\star}$ of leaving group\\
\
    };

\node (E2) [mech, fill=green!10,rectangle split, rectangle split parts=3, below=of AP,text width =5cm,yshift=-2cm]
    {
        \textbf{E2}
         \nodepart{second}Product determined by base\\
\nodepart{third}\includegraphics[width=3cm]{e2_image}
\
    };


\node (SN2) [mech, rectangle split, rectangle split parts=2, left = of NAPNR,xshift=-5.1cm]
    {
        \textbf{S$_N$2}
        \nodepart{second}Inversion of configuration\\
\
    }; 
\node (SN1) [mech, rectangle split, rectangle split parts=2, right=of NAPNR,text width =5cm]
    {
        \textbf{S$_N$1 + E1}
        \nodepart{second}S$_N$1: Racemic Product\\
E1: If adjacent C--H then evaluate (E) vs (Z)
    };
\node (UnstabNR) [mech, fill=red!20,rectangle split, rectangle split parts=2,right=of SN1]
    {
        \textbf{No Reaction}
        \nodepart{second}No reaction\\
\ \\
\
    };
\node (Hoff) [mech, rectangle split, rectangle split parts=4, below left=of E2,xshift=3.5cm,text width =5cm]
    {
        \textbf{Hoffman}
        \nodepart{second}Large Base\\
NaOtBu
\nodepart{third}\includegraphics[width=3cm]{Hof_small}\\
\ \\
\ \\
\ \\
\ \\%THESE LINES ARE TO KEEP NODE HEIGHT THE SAME, PROBABLY A BETTER WAY TO DO THIS
\nodepart{fourth}Less substituted alkene\\
Kinetically Favoured
    };
\node (Zait) [mech, rectangle split, rectangle split parts=4, below right=of E2,xshift=-3.5cm,text width =5cm]
    {
        \textbf{Zaitzev}
        \nodepart{second}Samll Base\\
NaOH
\nodepart{third}\nodepart{third}\includegraphics[width=3cm]{Zait_cis}\\
\includegraphics[width=3cm]{Zait_trans}\\
\nodepart{fourth}More substituted alkene\\
Thermodynamically Favoured
    };

\draw[myarrow] (Item.south) -- ++(0,-0.2) -|(GN.north);
\draw[myarrow] (Item.south) -- ++(0,-0.2) -|(BN.north);
\draw[myarrow] (GN.south) -- (Bimo.north);
\draw[myarrow] (Bimo.south) -- ++(0,-0.4) -| (Unhind.north);
\draw[myarrow] (Bimo.south) -- ++(0,-0.4) -| (Hind.north);
\draw[myarrow] (Unhind.south) -- ++ (0,-3)-|(SN2.north);
\draw[myarrow] (Hind.south) -- ++ (0,-0.75)-|(AP.north);
\draw[myarrow] (Hind.south) -- ++ (0,-0.75)-|(NAP.north);
\draw[myarrow] (NAP.south) -- (NAPNR.north);
\draw[myarrow] (AP.south) -- (E2.north);
\draw[myarrow] (E2.south) -- ++ (0,-0.75)-|(Hoff.north);
\draw[myarrow] (E2.south) -- ++ (0,-0.75)-|(Zait.north);
\draw[myarrow] (Unimo.south) -- ++(0,-0.4) -| (Unstab.north);
\draw[myarrow] (Unimo.south) -- ++(0,-0.4) -| (Stab.north);
\draw[myarrow] (Unstab.south) -- ++(0,-3)-|(UnstabNR.north);
\draw[myarrow] (Stab.south) --++(0,-3)-| (SN1.north);


\draw[myarrow]  (BN.south)--   (Unimo.north);


\end{tikzpicture}
\end{center}
\end{document}

rxnmechanisms

share|improve this answer
    
Yup. I wanted This as well, I need to draw UML diagrams also. Thanks @Leeser –  subham soni Mar 10 at 12:17
    
Credit where credit is due...The above is a TikZ version of flow diagram by Michael Jiang michaeljiang.com/… –  Leeser Mar 12 at 20:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.