4

I am drawing Simon Dik's Functional Grammar Model Overview using TikZ, but I have run into a stumbling block. It is a design flaw on my part, and I would rather not redesign everything. The box called Lexicon was created using the fit library to make a box around a few nodes. It must be therefore drawn after those nodes are draw. Unfortunately, I need a pattern to fill the box (see original diagram).

UPDATE: I have solved the issue of the background covering my nodes using layers (see comments below). I am leaving this question open for anybody who could offer improvements to the code below and potentially solve my pattern issue and perhaps other alignment issues (like why the diagram is not centered when using the article class).

Problems:

  • I keep getting a black fill rather than a dotted background
  • The layer covers contained nodes

NOTE: The code I provide below does not include the pattern, because I could not get it to work.

Original Diagram: enter image description here

My Code (updated according using layers see comments):

\documentclass[10pt]{article}
%\documentclass[tikz,border={5pt 5pt}]{standalone}
%SET MARGINS (AND PAGE DIMENSIONS)
%\usepackage[includeheadfoot,head=30pt,foot=30pt,top=1cm,bottom=1cm,left=1cm,right=1cm]{geometry}



\usepackage{fontspec}
\setmainfont{cmunrm.otf}
%\setmainfont{Calibri}

\usepackage{tikz}



\usetikzlibrary{fit,calc,trees,patterns,positioning,backgrounds,arrows,chains,shapes.geometric,%
    decorations.pathreplacing,decorations.pathmorphing,shapes,%
    matrix,shapes.symbols}

\tikzset{%
    join/.style={},
    myarrow/.style={->, thick,shorten >=1pt},
    mybox/.style={draw,rounded corners, minimum height=.7cm,align=center,node distance=1em},
    leftright/.style={outer sep=0,inner sep=0,text width=2cm,draw,align=center,node distance=0em,minimum height=3em},
    mainnode/.style={very thick,fill=red!10},
    spannodes/.style={text depth=-5pt,draw,inner sep=0em,outer sep=0,minimum height=1.5em,align=center,node distance=0em}
}%


\begin{document}
\thispagestyle{empty}

\begin{figure}
\centering
\vspace*{-45pt}
\hspace*{-3cm}\begin{tikzpicture}[remember picture]

% THE MAIN CHAIN THAT GOES STRAIGHT DOWN
\node(placeholder){};
\node[minimum height=1cm,minimum width=5cm,below=of placeholder.south,join] (lexicon) {};
\node[mainnode,mybox,below=2cm of lexicon.south,join] (nuclearpredication) {nuclear predication};
\node[mybox,below=of nuclearpredication,join] (lev1) {π\textsubscript{1} σ\textsubscript{1}};
\node[mainnode,mybox,below=of lev1,join] (corepredication) {core predication};
\node[mybox,below=of corepredication] (lev2) {π\textsubscript{2} σ\textsubscript{2}};
\node[mybox,below=of lev2] (syntacticfunctions) {syntactic functions};
\node[mainnode,mybox,below=of syntacticfunctions] (extendedpredication) {extended predication};
\node[mybox,below=of extendedpredication] (lev3) {π\textsubscript{3} σ\textsubscript{3}};
\node[mainnode,mybox,below=of lev3] (proposition) {proposition};
\node[mybox,below=of proposition] (lev4) {π\textsubscript{4} σ\textsubscript{4}};
\node[mybox,below=of lev4] (pragmaticfunctions) {pragmatic functions};
\node[mainnode,mybox,below=of pragmaticfunctions] (clausestructure) {clause structure};
\node[mybox,below=of clausestructure] (expressionrules) {\textsc{Expression Rules}\\\\form\\order\\prosody};
\node[mainnode,fill=yellow!20,mybox,below=of expressionrules,] (linguisticexpression) {\textsc{Linguistic Expression}};


% THE SECONDARY CHAIN LEFT AND RIGHT
% LEFT OF
\node[xshift=-1.5cm,leftright,left=of lexicon.south] (basicpredicates) {basic predicates};
\node[leftright,left=of basicpredicates] (derivedpredicates) {derived predicates};
\node[xshift=-2em,leftright,left=of derivedpredicates] (predicateformation) {predicate\\formation};
\node[fit={(derivedpredicates.west) (basicpredicates.east)},spannodes,below=of basicpredicates.south] at ($(derivedpredicates.south)!0.5!(basicpredicates.south)$) (predicateframes) {\textsc{Predicate Frames}};

% RIGHT OF
\node[xshift=1.5cm,leftright,right=of lexicon.south] (basicterms) {basic\\terms};
\node[leftright,right=of basicterms] (derivedterms) {derived\\terms};
\node[xshift=2em,leftright,right=of derivedterms] (termformation) {term\\formation};
\node[fit={(basicterms.west) (derivedterms.east)},spannodes,below=of basicterms] at ($(basicterms.south)!0.5!(derivedterms.south)$) (terms) {\textsc{Terms}};


\node [draw, very thick,inner sep=0,fit={%
        (lexicon) (derivedpredicates) (predicateframes) (derivedterms) (terms) (placeholder)
    },label=\textsc{Fund}] (fund){};
\begin{pgfonlayer}{background}
\node [draw=blue!100,anchor=south,dashed,fill=green!20,inner sep=0pt,fit={
        (basicpredicates) (basicterms) (lexicon)
    },label=\textsc{Lexicon}] {};
\end{pgfonlayer}{background}
%\node[above=2cm of basicterms.east] (rightcorner)  {};
%\draw[label=Lexicon] (basicpredicates.south west) rectangle (rightcorner);

% Connect the Lines
\draw[red] (derivedpredicates.north) -| ++(0,1.2) -| (termformation.north);
\draw[blue] (predicateformation.north) -| ++(0,1.4) -| (derivedterms.north);
\draw[red] (predicateformation.east) to (derivedpredicates);
\draw[blue] (predicateformation.south) -| ++(0,-.3) -| (predicateframes.west);
\draw[blue] (termformation.west) to (derivedterms.east);


% Draw Arrows
\draw[myarrow] (fund.south) to (nuclearpredication.north);
\draw[myarrow] (nuclearpredication.south) to (lev1.north);
\draw[myarrow] (lev1.south) to (corepredication.north);
\draw[myarrow] (corepredication.south) to (lev2.north);
\draw[myarrow] (lev2.south) to (syntacticfunctions.north);
\draw[myarrow] (syntacticfunctions.south) to (extendedpredication.north);
\draw[myarrow] (extendedpredication.south) to (lev3.north);
\draw[myarrow] (lev3.south) to (proposition.north);
\draw[myarrow] (proposition.south) to (lev4.north);
\draw[myarrow] (lev4.south) to (pragmaticfunctions.north);
\draw[myarrow] (pragmaticfunctions.south) to (clausestructure.north);
\draw[myarrow] (clausestructure.south) to (expressionrules.north);
\draw[myarrow] (expressionrules.south) to (linguisticexpression.north);




\end{tikzpicture}\hspace*{-3cm}
\caption{Functional Grammar Model Overview}
\end{figure}


\end{document}

My New Output using article class (diagram inside a figure environment) New Article Class FG Diagram Output

My Old Output: FG Diagram Output

  • 1
    I'm not a tikz expert but I think you may be able to tackle this problem by using layers. There is a brief explanation in PGF & Tikz manual 3.13 Using Layers: The Background Rectangles. – Pouya May 30 '13 at 11:31
  • @Pouya, exactly! I will change the question accordingly! I am also not sure how to implement this in my code. I will experiment with your suggestion. – Jonathan Komar May 30 '13 at 11:35
  • Great! It works! One thing though, I cannot get the pattern=dots to work (only showing up as black). fill=blue!10 works. – Jonathan Komar May 30 '13 at 11:44
  • 1
    Maybe this question helps you with the fill. – Pouya May 30 '13 at 12:17
  • 2
    Unfortunately xelatex doesn't support patterns. – Gonzalo Medina May 30 '13 at 12:49
3

To answer the subsidiary question:

The picture doesn't center as it is too wide:

Overfull \hbox (122.19116pt too wide) in paragraph at lines 93--94

in such cases TeX always puts the additional material into the right margin.

It is also too long:

LaTeX Warning: Float too large for page by 42.29073pt on input line 95.

Assuming that you don't mind it overlapping the nominal top and side margins, you can raise it by 45pt and insert (essentially arbitrary) negative space either side so that its effective width is less than text width. (I also switched your font choice as I don't have Calibri)

enter image description here

\documentclass[10pt]{article}
\usepackage{fontspec}
\setmainfont{cmunrm.otf}
%\setmainfont{Calibri}
\usepackage{tikz}
\usetikzlibrary{fit,calc,trees,patterns,positioning,backgrounds,arrows,chains,shapes.geometric,%
    decorations.pathreplacing,decorations.pathmorphing,shapes,%
    matrix,shapes.symbols}

\tikzset{
    join/.style={},
    myarrow/.style={->, thick,shorten >=1pt},
    mybox/.style={draw,rounded corners, minimum height=.7cm,align=center,node distance=1em},
    leftright/.style={outer sep=0,inner sep=0,text width=2cm,draw,align=center,node distance=0em,minimum height=3em},
    mainnode/.style={very thick,fill=red!10},
    spannodes/.style={text depth=-5pt,draw,inner sep=0em,outer sep=0,minimum height=1.5em,align=center,node distance=0em}
}


\begin{document}
\thispagestyle{empty}

\begin{figure}
\centering
\vspace*{-45pt}
\hspace*{-3cm}\begin{tikzpicture}[remember picture]

% THE MAIN CHAIN THAT GOES STRAIGHT DOWN
\node(placeholder){};
\node[minimum height=1cm,minimum width=5cm,below=of placeholder.south,join] (lexicon) {};
\node[mainnode,mybox,below=2cm of lexicon.south,join] (nuclearpredication) {nuclear predication};
\node[mybox,below=of nuclearpredication,join] (lev1) {π\textsubscript{1} σ\textsubscript{1}};
\node[mainnode,mybox,below=of lev1,join] (corepredication) {core predication};
\node[mybox,below=of corepredication] (lev2) {π\textsubscript{2} σ\textsubscript{2}};
\node[mybox,below=of lev2] (syntacticfunctions) {syntactic functions};
\node[mainnode,mybox,below=of syntacticfunctions] (extendedpredication) {extended predication};
\node[mybox,below=of extendedpredication] (lev3) {π\textsubscript{3} σ\textsubscript{3}};
\node[mainnode,mybox,below=of lev3] (proposition) {proposition};
\node[mybox,below=of proposition] (lev4) {π\textsubscript{4} σ\textsubscript{4}};
\node[mybox,below=of lev4] (pragmaticfunctions) {pragmatic functions};
\node[mainnode,mybox,below=of pragmaticfunctions] (clausestructure) {clause structure};
\node[mybox,below=of clausestructure] (expressionrules) {\textsc{Expression Rules}\\\\form\\order\\prosody};
\node[mainnode,mybox,below=of expressionrules] (linguisticexpression) {\textsc{Linguistic Expression}};


% THE SECONDARY CHAIN LEFT AND RIGHT
% LEFT OF
\node[xshift=-1.5cm,leftright,left=of lexicon.south] (basicpredicates) {basic predicates};
\node[leftright,left=of basicpredicates] (derivedpredicates) {derived predicates};
\node[xshift=-2em,leftright,left=of derivedpredicates] (predicateformation) {predicate\\formation};
\node[fit={(derivedpredicates.west) (basicpredicates.east)},spannodes,below=of basicpredicates.south] at ($(derivedpredicates.south)!0.5!(basicpredicates.south)$) (predicateframes) {\textsc{Predicate Frames}};

% RIGHT OF
\node[xshift=1.5cm,leftright,right=of lexicon.south] (basicterms) {basic\\terms};
\node[leftright,right=of basicterms] (derivedterms) {derived\\terms};
\node[xshift=2em,leftright,right=of derivedterms] (termformation) {term\\formation};
\node[fit={(basicterms.west) (derivedterms.east)},spannodes,below=of basicterms] at ($(basicterms.south)!0.5!(derivedterms.south)$) (terms) {\textsc{Terms}};


\node [draw, very thick,inner sep=0,fit={
        (lexicon) (derivedpredicates) (predicateframes) (derivedterms) (terms) (placeholder)
    },label=\textsc{Fund}] (fund){};
\begin{pgfonlayer}{background}
\node [draw=blue!100,anchor=south,dashed,fill=green!10,inner sep=0pt,fit={
        (basicpredicates) (basicterms) (lexicon)
    },label=\textsc{Lexicon}] {};
\end{pgfonlayer}{background}
%\node[above=2cm of basicterms.east] (rightcorner)  {};
%\draw[label=Lexicon] (basicpredicates.south west) rectangle (rightcorner);

% Connect the Lines
\draw[red] (derivedpredicates.north) -| ++(0,1.2) -| (derivedterms.north);
\draw[blue] (predicateformation.north) -| ++(0,1.4) -| (termformation.north);
\draw[blue] (predicateformation.east) to (derivedpredicates);
\draw[blue] (predicateformation.south) -| ++(0,-.3) -| (predicateframes.west);
\draw[blue] (termformation.west) to (derivedterms.east);


% Draw Arrows
\draw[myarrow] (fund.south) to (nuclearpredication.north);
\draw[myarrow] (nuclearpredication.south) to (lev1.north);
\draw[myarrow] (lev1.south) to (corepredication.north);
\draw[myarrow] (corepredication.south) to (lev2.north);
\draw[myarrow] (lev2.south) to (syntacticfunctions.north);
\draw[myarrow] (syntacticfunctions.south) to (extendedpredication.north);
\draw[myarrow] (extendedpredication.south) to (lev3.north);
\draw[myarrow] (lev3.south) to (proposition.north);
\draw[myarrow] (proposition.south) to (lev4.north);
\draw[myarrow] (lev4.south) to (pragmaticfunctions.north);
\draw[myarrow] (pragmaticfunctions.south) to (clausestructure.north);
\draw[myarrow] (clausestructure.south) to (expressionrules.north);
\draw[myarrow] (expressionrules.south) to (linguisticexpression.north);

\end{tikzpicture}\hspace*{-3cm}
\caption{Functional Grammar Model Overview}
\end{figure}


\end{document}
  • Thank you for that great supplemental information! Just to clarify, what exactly do you mean by "nominal" in this context? Do you mean referring to the margins as "top" and "side" rather than their numerical values? (P.S. The Calibri font was chosen to match the font in a Powerpoint presentation) – Jonathan Komar Jun 2 '13 at 11:47
  • 1
    I just mean the specified values. If you place the figure there that space is no longer "margin" in any real sense, although LaTeX will still consider it so of course. – David Carlisle Jun 2 '13 at 12:43
2

In order to draw a background around a group of nodes, you should use the pgfonlayer background environment see page 49 of TikZ Manual 2.10:

\begin{pgfonlayer}{background}
% Whatever you background layer node is
    \node [draw=blue!100,anchor=south,dashed,fill=green!10,inner sep=0pt,fit={
        (basicpredicates) (basicterms) (lexicon)
    },label=\textsc{Lexicon}] {};
\end{pgfonlayer}

Pattern fills currently do not work using xelatex. (as mentioned by Gonzalo Medina in comments above)

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.