如何强制 TikZ 背景图案位于节点下方?(使用图层)

如何强制 TikZ 背景图案位于节点下方?(使用图层)

我正在使用 TikZ 绘制 Simon Dik 的功能语法模型概述,但遇到了一个障碍。这是我的设计缺陷,我宁愿不重新设计一切。名为词汇表是使用 来fit library制作一个围绕几个节点的框。因此,必须在绘制这些节点后绘制它。不幸的是,我需要一个图案来填充框(参见原始图表)。

更新:我已经解决了使用图层覆盖节点的背景问题(请参阅下面的评论)。我将这个问题留给任何可以改进以下代码并可能解决我的模式问题和其他对齐问题(例如为什么使用文章类时图表不居中)的人。

问题:

  • 我一直得到黑色填充,而不是点状背景
  • 层覆盖包含的节点

注意:我下面提供的代码不包含模式,因为我无法让它工作。

原图: 在此处输入图片描述

我的代码(根据使用层进行更新看评论):

\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}

我使用文章类的新输出(figure环境内的图表) 新文章类 FG 图输出

我的旧输出: FG 图输出

答案1

回答附属问题:

由于太宽,图片未居中:

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

在这种情况下,TeX 总是将附加材料放在右边距。

它也太长了:

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

假设您不介意它与标称顶部和侧面边距重叠,您可以将其提高 45pt 并在两侧插入(基本上是任意的)负空间,以便其有效宽度小于文本宽度。(由于我没有 Calibri,所以我还更改了您的字体选择)

在此处输入图片描述

\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}

答案2

为了在节点组周围绘制背景,您应该使用pgfonlayer background环境参见 TikZ 手册 2.10 第 49 页

\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}

图案填充目前不起作用使用xelatex(正如 Gonzalo Medina 在上面的评论中提到的)

相关内容