声明图层导致 tikzpicture 消失

声明图层导致 tikzpicture 消失

我正在使用图片环境来\put从页面内部获取一些 tikzpictures \setkomavar{firsthead}。当我像这样声明一些 pgf 层时:

\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background, main, foreground}

图片消失了。图层的原因是为了创建一个漂亮的表格环境来显示一些数据。当我删除图层时,图片会重新出现。有谁知道让 tikzpictures 重新出现的任何明显方法吗?如果没有,我会举一个最简单的工作示例来解释我的意思。我试过了,\begin{pgfonlayer}{main}...\end{pgfonlayer}但什么也没改变。

编辑:最小工作示例

\documentclass{scrlttr2}
\usepackage{booktabs}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{tabularx}
\usepackage{color}

\usetikzlibrary{calc, fit, shadows, arrows, positioning}
% if these lines are commented out, the box draws.
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background, main, foreground}
% end comment out these lines

\newsavebox{\monotablecontent}
\newenvironment{monotable}[1]{%
  \begin{lrbox}{\monotablecontent}%
  \begin{tabular}{#1}}%
  %
  {%
  \end{tabular}
  \end{lrbox}
  \begin{tikzpicture}
    \node [inner xsep=0pt] (tbl){\usebox{\monotablecontent}};
    % table
    \draw[rounded corners=1pt,top color=gray!1,bottom color=gray!30,draw=black]
    (tbl.north east) rectangle (tbl.south west);
    % top line
    \draw[rounded corners=1pt,top color=gray!10!black,bottom color=gray!50!black,draw=black]
    ($(tbl.north west)$) rectangle ($(tbl.north east)-(0, 1.5\baselineskip)$);
    % bottom rule
    \draw[rounded corners=0.25pt,fill=gray,draw=black]
    (tbl.south west) rectangle ($(tbl.south east)+(0, 0.05)$);
  \end{tikzpicture}
}

\definecolor{myblue}{rgb}{0, 0.58, 0.85}

\newcommand*\invhead[1]{\sffamily{\color{myblue}\footnotesize{\textbf{#1}}}}
\newcommand*\head[1]{\tiny \invhead{#1}}

% set details
\setkomavar{fromname}{ACME Widgets}
\setkomavar{fromaddress}{1 Infinite Loop\\Sometown, 90210\\Uganda}
\setkomavar{fromphone}{+61 9876 5432}
\setkomavar{fromemail}{[email protected]}
\setkomavar{fromfax}{+61 9876 5431}
\setkomavar{fromurl}{http://acme.com/}
\setkomavar{signature}{ACME Widgets}
\setkomavar{fromlogo}{}
\setkomavar{invoice}[Invoice number]{1234 567}
\setkomavar{date}{}
\setkomavar{customer}[Account number]{123456}

% set up a style for our boxes that we will eventually draw.
\tikzstyle{shadedbox} = [
  draw=black,
  shade,
  top color=white,
  bottom color=bottom,
  drop shadow={
    top color=black,
    bottom color=black,
    shadow xshift=2pt,
    shadow yshift=-2pt,
  },
  thin,
  rectangle,
  inner sep=2pt,
  inner ysep=2pt,
  outer ysep=1ex,
]

\newcommand*\monobox[2]{%
  \begin{tikzpicture}
    \definecolor{top}{RGB}{250,250,250}
    \definecolor{bottom}{RGB}{235,235,235}
    \begin{pfgonlayer}{main}
    \node [shadedbox, minimum width=0.18\textwidth, text width=0.18\textwidth, align=right] (box) {
      \begin{tabular}{r}
        \invhead{\scriptsize #1}\\
        \footnotesize{#2}\\
      \end{tabular}
    };
    \end{pgfonlayer}
  \end{tikzpicture}
}

% set the logo, draw some boxes...
\setkomavar{firsthead}{
  \usekomavar{fromlogo}\\
  \begin{picture}(0,0)
    \put(0,0){
      \parbox[t]{\textwidth}{
        \vspace{\useplength{toaddrvpos}}
        \vspace{3\baselineskip}
        \hspace{-2pt}
        \monobox{Last Bill}{\$29.95}
      }
    }
  \end{picture}
}

\begin{document}

\begin{letter}[backaddress=false]{%
    Mr Joe Customer\\%
    17 Unicorn Avenue\\
    Narwhtropilis\\%
    Uganda\\%
}

\setkomavar{subject}{Invoice}
\opening{Dear Joe Customer,}
Here is your invoice.
\closing{Regards}
\end{letter}
\end{document}

我似乎得到的错误是:

! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerboxsaved@ main 
l.114 \opening{Dear Joe Customer,}

? 
! A <box> was supposed to be here.
<to be read again> 
                   =
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerbox@ main 
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerboxsaved@ foreground 
l.114 \opening{Dear Joe Customer,}

? 
! A <box> was supposed to be here.
<to be read again> 
                   =
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerbox@ foreground 
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerbox@ main 
l.114 \opening{Dear Joe Customer,}

? 
! A <box> was supposed to be here.
<to be read again> 
                   =
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerboxsaved@ main 
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerbox@ foreground 
l.114 \opening{Dear Joe Customer,}

? 
! A <box> was supposed to be here.
<to be read again> 
                   =
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerboxsaved@ foreground 
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerboxsaved@ main 
l.114 \opening{Dear Joe Customer,}

? 
! A <box> was supposed to be here.
<to be read again> 
                   =
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerbox@ main 
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerboxsaved@ foreground 
l.114 \opening{Dear Joe Customer,}

? 
! A <box> was supposed to be here.
<to be read again> 
                   =
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerbox@ foreground 
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerbox@ main 
l.114 \opening{Dear Joe Customer,}

? 
! A <box> was supposed to be here.
<to be read again> 
                   =
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerboxsaved@ main 
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerbox@ foreground 
l.114 \opening{Dear Joe Customer,}

? 
! A <box> was supposed to be here.
<to be read again> 
                   =
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerboxsaved@ foreground 
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerboxsaved@ main 
l.114 \opening{Dear Joe Customer,}

? 
! A <box> was supposed to be here.
<to be read again> 
                   =
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerbox@ main 
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerboxsaved@ foreground 
l.114 \opening{Dear Joe Customer,}

? 
! A <box> was supposed to be here.
<to be read again> 
                   =
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerbox@ foreground 
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerbox@ main 
l.114 \opening{Dear Joe Customer,}

? 
! A <box> was supposed to be here.
<to be read again> 
                   =
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerboxsaved@ main 
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerbox@ foreground 
l.114 \opening{Dear Joe Customer,}

? 
! A <box> was supposed to be here.
<to be read again> 
                   =
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerboxsaved@ foreground 
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerbox@ main 
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerbox@ foreground 
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerboxsaved@ main 
l.114 \opening{Dear Joe Customer,}

? 
! A <box> was supposed to be here.
<to be read again> 
                   =
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerbox@ main 
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerboxsaved@ foreground 
l.114 \opening{Dear Joe Customer,}

? 
! A <box> was supposed to be here.
<to be read again> 
                   =
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerbox@ foreground 
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerbox@ main 
l.114 \opening{Dear Joe Customer,}

? 
! A <box> was supposed to be here.
<to be read again> 
                   =
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerboxsaved@ main 
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerbox@ foreground 
l.114 \opening{Dear Joe Customer,}

? 
! A <box> was supposed to be here.
<to be read again> 
                   =
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerboxsaved@ foreground 
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerboxsaved@ main 
l.114 \opening{Dear Joe Customer,}

? 
! A <box> was supposed to be here.
<to be read again> 
                   =
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerbox@ main 
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerboxsaved@ foreground 
l.114 \opening{Dear Joe Customer,}

? 
! A <box> was supposed to be here.
<to be read again> 
                   =
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerbox@ foreground 
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerbox@ main 
l.114 \opening{Dear Joe Customer,}

? 
! A <box> was supposed to be here.
<to be read again> 
                   =
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerboxsaved@ main 
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerbox@ foreground 
l.114 \opening{Dear Joe Customer,}

? 
! A <box> was supposed to be here.
<to be read again> 
                   =
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerboxsaved@ foreground 
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerboxsaved@ main 
l.114 \opening{Dear Joe Customer,}

? 
! A <box> was supposed to be here.
<to be read again> 
                   =
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerbox@ main 
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerboxsaved@ foreground 
l.114 \opening{Dear Joe Customer,}

? 
! A <box> was supposed to be here.
<to be read again> 
                   =
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerbox@ foreground 
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerbox@ main 
l.114 \opening{Dear Joe Customer,}

? 
! A <box> was supposed to be here.
<to be read again> 
                   =
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerboxsaved@ main 
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerbox@ foreground 
l.114 \opening{Dear Joe Customer,}

? 
! A <box> was supposed to be here.
<to be read again> 
                   =
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerboxsaved@ foreground 
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerbox@ main 
l.114 \opening{Dear Joe Customer,}

? 
! Missing number, treated as zero.
<to be read again> 
                   \pgf@layerbox@ foreground 
l.114 \opening{Dear Joe Customer,}

? 
Foot of first page
Address (addressee)
Location field: empty
Reference line(s): with fields but without date
Title: no
Subject: before opening
[1] (./test.aux)


 )
Output written on test.pdf (1 page).

答案1

在修复 wh1t3 评论中强调的问题后,仍有一个问题尚未解决。答案来自 PGF 手册第 82.3 节(使用层):

笔记: 你可以不是使用此环境向图层添加任何内容main。向主图层添加任何内容的唯一方法是在所有环境之外发出图形命令{pgfonlayer}

main图层的处理方式与其他图层不同。分层系统的工作原理是将每个图层的命令放入框中,然后按正确的顺序放置这些框。可以不将东西放入框中,并且不在框中的所有内容都会放在图层上main。因此布局机制是:

  1. main按照给定的顺序处理之前列出的所有框。
  2. 处理所有非盒装物品。
  3. main按给定的顺序处理后面列出的所有框。

当你使用\begin{pgfonlayer}{main}时,它会寻找一个可以放东西的盒子。不知什么原因,它确实把东西放进了一个盒子里(它应该闪现一个大霓虹灯标志,上面写着“你正试图使用​​ pgfonlayer 将东西放在主层上。不要这样做。”)但那个盒子就像去年的圣诞装饰品一样被塞到角落里,再也没有人看过。

所以再试一次,但请确保不要明确使用该main层。如果您仍然遇到问题,请编辑问题以解释这些问题是什么,或者提出新问题。

答案2

实际上,问题在于pgfsetlayers命令中的空格有误。替换

\pgfsetlayers{background, main, foreground}

\pgfsetlayers{background,main,foreground}

一切都会好起来的!

相关内容