TikZ 背景不工作

TikZ 背景不工作

我正在用 TikZ 绘制框图。虽然一切运行正常,但我无法在后台绘制。我的代码是

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,snakes,automata,backgrounds,petri,shadows}
\pgfdeclarelayer{background}
\newcommand{\eng}[1]{\latintext#1\greektext}

\tikzstyle{blockOrange}=[top color=white, bottom color=orange!60,     draw=orange!90!black!100, minimum size=1cm, rounded corners]
\tikzstyle{blockBrown}=[top color=white, bottom color=brown!60,   draw=brown!90!black!100, minimum size=1cm, rounded corners]
\tikzstyle{blockGray}=[top color=white, bottom color=gray!60, draw=gray!90!black!100,  minimum size=1cm, rounded corners]
\tikzstyle{blockBlack}=[top color=white, bottom color=black!60, draw=black!90!black!100, minimum size=1cm, rounded corners]

\begin{figure}%[H]%
\centering%
\begin{tikzpicture}[node distance=0.1cm,auto,>=latex']


%read-out
\node [blockOrange] (MM) {\eng{Detector}};
\node [blockBrown, right of=MM, node distance=3cm] (PRE) {\eng{Pre-Amp}};
\node [blockBrown, right of=PRE, node distance=3cm] (AMP) {\eng{Amplifier}};
\node [below of=AMP, node distance=2cm] (dummy1) {};
\node [blockBlack, right of=AMP, node distance=2.7cm] (MCA) {\eng{\textcolor{red}{MCA}}};
\node [blockGray, below of=MCA, node distance=2cm] (SCOPE) {\eng{Scope}};
\node [blockGray, above of=MCA, node distance=2.5cm] (PC) {\eng{\textcolor{red}{PC}}};

\path[->] (MM) edge node {strips} (PRE);
\path[->] (PRE) edge node {energy} (AMP);
\path[->] (AMP) edge node {bipolar} (MCA);
\path[->] (MCA) edge node {} (PC);
\draw (7.3,0) -- (7.3,-2);
\draw[->] (7.3,-2) -- (8.1,-2);
\draw node at (7.9,-1) {\textcolor{red}{balun}};

\begin{pgfonlayer}{background}

    %Read Out   
    \path (PRE.east |- PRE.north)+(1,0.3) node (e) {};
    \path (SCOPE.south -| SCOPE.west)+(-0.8,-0.3) node (f) {};

    \path[top color=white, bottom color=red!60, draw=red!90!black!100, dashed, rounded corners, thick]
        (e) rectangle (f);

\end{pgfonlayer}

\end{tikzpicture}
\caption{Block Diagram}
\label{fig:blockGain}%
\end{figure}

\end{document}

对此有什么想法吗?我的输出是


这是文件\listitem直接的输出.log

 *File List*
subfiles.cls    2002/06/08 Federico Garcia
verbatim.sty    2003/08/22 v1.5q LaTeX2e package for verbatim enhancements
    main.tex
filecontents.sty    2009/03/17 v1.2 Create an external file from within a LaTeX
 document
    book.cls    2007/10/19 v1.4h Standard LaTeX document class
    bk11.clo    2007/10/19 v1.4h Standard LaTeX file (size option)
   babel.sty    2008/07/06 v3.8l The Babel package
 bblopts.cfg    2005/09/08 v0.1 add Arabic and Farsi to "declared" options of b
abel
 english.ldf    2005/03/30 v3.3o English support from the babel system
   greek.ldf    2005/03/30 v1.3l Greek support from the babel system
  lgrenc.def    2008/06/17 v2.3 Greek Encoding
inputenc.sty    2008/03/30 v1.1d Input encoding file
iso-8859-7.def    2000/05/28 v1.2 Greek input encoding file
kerkis.sty    2000/02/25 v1.5 Package `kerkis.sty'
 amsmath.sty    2000/07/18 v2.13 AMS math features
 amstext.sty    2000/06/29 v2.01
  amsgen.sty    1999/11/30 v2.0
  amsbsy.sty    1999/11/29 v1.2d
  amsopn.sty    1999/12/14 v2.01 operator names
 amssymb.sty    2009/06/22 v3.00
 amsfonts.sty    2009/06/22 v3.00 Basic AMSFonts support
 amsthm.sty    2004/08/06 v2.20
resizegather.sty    2010/03/01 v1.2 Automatically resizing of too large equatio
ns (HO)
kvoptions.sty    2010/02/22 v3.7 Keyval support for LaTeX options (HO)
  keyval.sty    1999/03/16 v1.13 key=value parser (DPC)
kvsetkeys.sty    2010/03/01 v1.9 Key value parser (HO)
infwarerr.sty    2010/04/08 v1.3 Providing info/warning/message (HO)
etexcmds.sty    2010/01/28 v1.3 Prefix for e-TeX command names (HO)
graphics.sty    2009/02/05 v1.0o Standard LaTeX Graphics (DPC,SPQR)
    trig.sty    1999/03/16 v1.09 sin cos tan (DPC)
graphics.cfg    2007/01/18 v1.5 graphics configuration of teTeX/TeXLive
  pdftex.def    2010/02/14 v0.04n Graphics/color for pdfTeX
   units.sty    1998/08/04 v0.9b Typesetting units
  ifthen.sty    2001/05/26 v1.1c Standard LaTeX ifthen package (DPC)
nicefrac.sty    1998/08/04 v0.9b Nice fractions
   array.sty    2008/09/09 v2.4c Tabular extension package (FMi)
  framed.sty    2007/10/04 v 0.95: framed or shaded text with page breaks
extarrows.sty    2008/05/15 v1.0b Some extensible arrows
  cancel.sty    2000/03/12 v2.1 Cancel math terms
graphicx.sty    1999/02/16 v1.0f Enhanced LaTeX Graphics (DPC,SPQR)
geometry.sty    2010/03/13 v5.3 Page Geometry
   ifpdf.sty    2010/01/28 v2.1 Provides the ifpdf switch (HO)
  ifvtex.sty    2010/03/01 v1.5 Switches for detecting VTeX and its modes (HO)
geometry.cfg
fncychap.sty    2007/07/30 v1.34 LaTeX package (Revised chapters)
fancybox.sty    2010/05/15 1.4
fancyhdr.sty    
colortbl.sty    2001/02/13 v0.1j Color table columns (DPC)
   color.sty    1999/02/16
   color.cfg    2007/01/18 v1.5 color configuration of teTeX/TeXLive
  xcolor.sty    2007/01/21 v2.11 LaTeX color extensions (UK)
   color.cfg    2007/01/18 v1.5 color configuration of teTeX/TeXLive
footmisc.sty    2011/06/06 v5.5b a miscellany of footnote facilities
subfiles.sty    2002/06/08 Federico Garcia
   float.sty    2001/11/08 v1.3d Float enhancements (AL)
slashbox.sty    
 tocloft.sty    2010/10/13 v2.3e parameterised ToC, etc., typesetting
 hyperref.sty    2010/03/30 v6.80u Hypertext links for LaTeX
  ltxcmds.sty    2010/04/08 v1.5 LaTeX kernel commands for general use (HO)
 pdfescape.sty    2010/03/01 v1.9 Provides hex, PDF name and string conversions 
(HO)
pdftexcmds.sty    2010/04/01 v0.9 Utility functions of pdfTeX for LuaTeX (HO)
ifluatex.sty    2010/03/01 v1.3 Provides the ifluatex switch (HO)
 ifxetex.sty    2009/01/23 v0.5 Provides ifxetex conditional
 hycolor.sty    2009/12/12 v1.6 Color options of hyperref/bookmark (HO)
xcolor-patch.sty    2009/12/12 xcolor patch
letltxmacro.sty    2008/06/24 v1.3 Let assignment for LaTeX macros (HO)
  pd1enc.def    2010/03/30 v6.80u Hyperref: PDFDocEncoding definition (HO)
 intcalc.sty    2007/09/27 v1.1 Expandable integer calculations (HO)
hyperref.cfg    2002/06/06 v1.2 hyperref configuration of TeXLive
     url.sty    2006/04/12  ver 3.3  Verb mode for urls, etc.
  bitset.sty    2007/09/28 v1.0 Data type bit set (HO)
bigintcalc.sty    2007/11/11 v1.1 Expandable big integer calculations (HO)
atbegshi.sty    2010/03/25 v1.12 At begin shipout hook (HO)
 hpdftex.def    2010/03/30 v6.80u Hyperref driver for pdfTeX
atveryend.sty    2010/03/24 v1.5 Hooks at very end of document (HO)
rerunfilecheck.sty    2010/03/16 v1.6 Rerun checks for auxiliary files (HO)
uniquecounter.sty    2009/12/18 v1.1 Provides unlimited unique counter (HO)
subfigure.sty    2002/07/30 v2.1.4 subfigure package
subfigure.cfg
 wrapfig.sty    2003/01/31  v 3.6
rotating.sty    2009/03/28 v2.16a rotated objects in LaTeX
  lscape.sty    2000/10/22 v3.01 Landscape Pages (DPC)
fancyvrb.sty    2008/02/07
listings.sty    2007/02/22 1.4 (Carsten Heinz)
 lstmisc.sty    2007/02/22 1.4 (Carsten Heinz)
listings.cfg    2007/02/22 1.4 listings configuration
textcomp.sty    2005/09/27 v1.99g Standard LaTeX package
  ts1enc.def    2001/06/05 v3.0e (jk/car/fm) Standard LaTeX file
lstlang1.sty    2004/09/05 1.3 listings language file
pifont.sty    2005/04/12 PSNFSS-v9.2a Pi font support (SPQR) 
    upzd.fd    2001/06/04 font definitions for U/pzd.
    upsy.fd    2001/06/04 font definitions for U/psy.
  feynmp.sty    1996/12/02 v1.08 LaTeX/MetaPost Feynman Diagram Package (ohl)
    tikz.sty    2010/10/13 v2.10 (rcs-revision 1.76)
     pgf.sty    2008/01/15 v2.10 (rcs-revision 1.12)
  pgfrcs.sty    2010/10/25 v2.10 (rcs-revision 1.24)
everyshi.sty    2001/05/15 v3.00 EveryShipout Package (MS)
  pgfrcs.code.tex
 pgfcore.sty    2010/04/11 v2.10 (rcs-revision 1.7)
  pgfsys.sty    2010/06/30 v2.10 (rcs-revision 1.37)
  pgfsys.code.tex
pgfsyssoftpath.code.tex    2008/07/18  (rcs-revision 1.7)
pgfsysprotocol.code.tex    2006/10/16  (rcs-revision 1.4)
 pgfcore.code.tex
pgfcomp-version-0-65.sty    2007/07/03 v2.10 (rcs-revision 1.7)
pgfcomp-version-1-18.sty    2007/07/23 v2.10 (rcs-revision 1.1)
  pgffor.sty    2010/03/23 v2.10 (rcs-revision 1.18)
 pgfkeys.sty    
 pgfkeys.code.tex
  pgffor.code.tex
    tikz.code.tex
circuitikz.sty    2009/11/18 The CircuiTikz circuit drawing package version 0.2.4    
multicol.sty    2008/12/05 v1.6h multicolumn formatting (FMi)
enumitem.sty    2011/07/14 v3.3 Customized lists
 makeidx.sty    2000/03/29 v1.0m Standard LaTeX package
booktabs.sty    2005/04/14 v1.61803 publication quality tables
  lgrcmr.fd    2008/06/17 v2.3 Greek Computer Modern
  ts1cmr.fd    1999/05/25 v2.5h Standard LaTeX font definitions
  ot1mak.fd
  lgrmak.fd
  supp-pdf.tex
 nameref.sty    2010/01/25 v2.36 Cross-referencing by name of section
refcount.sty    2008/08/11 v3.1 Data extraction from references (HO)
gettitlestring.sty    2009/12/18 v1.3 Cleanup title references (HO)
chapter4.out
chapter4.out
lgrmaksf.fd
    umsa.fd    2009/06/22 v3.00 AMS symbols A
    umsb.fd    2009/06/22 v3.00 AMS symbols B
 ***********

)

我忘了在主要的序言中添加\usetikzlibrary{backgrounds}...当我这样做时,发生了一些非常奇怪的事情......矩形没有填充颜色,背景矩形也没有填充颜色,并且您可以看到一些阴影在页面周围浮动。

我不知道发生了什么事...

答案1

你必须告诉蒂克兹按照什么顺序通过 堆叠层\pgfsetlayers{<layers>},其中<layers>是从后到前的层列表,以逗号分隔。所有不在环境中的命令都pgfonlayer将分配给main始终定义的层。要让这些命令位于正确的层上,main应该始终出现在规范中<layers>蒂克兹不使用时不会抛出错误\pgfsetlayers{<layers>},但是它会表现得相当奇怪,并且会遗漏大多数层的命令。当省略时,\pgfsetlayers{<layers>}无论以何种顺序声明backgroundforeground使用或,backround总是显示,而从不foreground显示,这真的很奇怪。所以我想建议始终记住书写\pgfsetlayers{<layers>},否则可能会出现奇怪的结果。

代码

\documentclass[tikz,border=5mm]{standalone}
\usetikzlibrary{arrows,backgrounds,shadows}

% define layers
    \pgfdeclarelayer{foreground}
    \pgfdeclarelayer{background}
% tell TikZ how to stack them (back to front)
    \pgfsetlayers{background,main,foreground}

\begin{document}

\begin{tikzpicture}[rounded corners=3mm,mysquare/.style={left color=#1!10,right color=#1!90,draw=#1!50!black}]
    \begin{pgfonlayer}{foreground}
        \fill[mysquare=green] (-1,-3) node[above right] {\Huge F} rectangle (1,3);
    \end{pgfonlayer}

    \fill[mysquare=red] (-2,-2) node[above right] {\Huge M} rectangle (2,2);

    \begin{pgfonlayer}{background}
        \fill[mysquare=blue] (-3,-1) node[above right] {\Huge B} rectangle (3,1);
    \end{pgfonlayer}
\end{tikzpicture}

\end{document}

输出

在此处输入图片描述

相关内容