Graphics, Figures & TablesPgfonlayer

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
mtanner
Posts: 9
Joined: Sat Jul 22, 2017 9:55 am

Pgfonlayer

Post by mtanner »

I have a couple of simple charts. Pgfonlayer seems to work fine in one chartbut not the other.
First chart uses:

Code: Select all

\begin{pgfonlayer}{forground}
.. several \node statements
\end{pgfonlayer}
to make the nodes appear on top of the lines plotted in the graph. This works exactly as expected.

Second chart is a stacked area chart with some guidelines overlaid by

Code: Select all

\begin{pgfonlayer}(foreground}
.. several \draw statements
\end{pgfonlayer}
but this gives error messages
"missing } inserted"
"extra } or missing \endgroup"

The \draw statements work ok when the pgfonlayer statements are removed, except the guidelines are behind the area plot, which is what I am trying to avoid. The error messages seem to saying a } is missing so one is inserted, but then complaining that there is an extra }.

Any suggestions please?
Last edited by Stefan Kottwitz on Thu Jan 10, 2019 12:39 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
Stefan Kottwitz
Site Admin
Posts: 10323
Joined: Mon Mar 10, 2008 9:44 pm

Pgfonlayer

Post by Stefan Kottwitz »

Hi!

I guess there's a syntax error in the \node or \draw commands that is not shown here.

Can you please post a complete code for that pgf/TikZ image?

Thanks,

Stefan
LaTeX.org admin
mtanner
Posts: 9
Joined: Sat Jul 22, 2017 9:55 am

Pgfonlayer

Post by mtanner »

The actual tex code is on another, not connected. system, but I will arrange to copy it across. However, since the \draw statements work ok without the pgfonlayer statements, then I think that demonstrates there is no systax error in them. At most it might make a diference whether the \draw statements are terminated by a semi-colon or not but I have tried all obvious variations, and TexMaker syntax highlighter tells me that the { and } match up properly/.

I admit to being hazy about pgfplots syntax, whether things are terminated by a sem-colon or not - I generally just copy previous working code. I would like to understand this kore, but the pgfplots user guide has a daunting amount of detail, but ;littel middle-level guidance. Any pointers to good introductory documemts would be helpful - there are anumber of simple introductions but they seem tol concentrate of a cookbook approach to drawing simple and then more complex charts, without addressing the language syntax directly.

The thing that runs through my mind is that the chart that works just has sinple lines plotted, while the chart that fails has stacked area plots with \closedcycle at the end of the coordinate lists.
mtanner
Posts: 9
Joined: Sat Jul 22, 2017 9:55 am

Pgfonlayer

Post by mtanner »

I have a simple work-around, which is to mode the \draw statements before the \addplot statemnets for the statcked areaa. This puts the \draw lines in front of the areas, but this is a workaround rather than a solution.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10323
Joined: Mon Mar 10, 2008 9:44 pm

Pgfonlayer

Post by Stefan Kottwitz »

I guess I would see the cause immediately when I see a complete picture code or compile it myself to trigger the error. ;-)

Stefan
LaTeX.org admin
mtanner
Posts: 9
Joined: Sat Jul 22, 2017 9:55 am

Pgfonlayer

Post by mtanner »

Here is the code. In the actual document this code is within a subfigure, and there is a preamble with a lot of \usepackage statements. The pgfonlayer statements are commented out in the code below, towards the end and surrounding some \draw statements. I am using TexMaker 4.5.
\begin{tikzpicture}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}
%--------Left axis--------
\begin{axis}[width=6.0cm,height=5.0cm,scale only axis,
   unbounded coords=jump,
   stack plots=y,area style,
   xticklabel style={font=\scriptsize},
   xlabel style={font=\scriptsize},
   yticklabel style={font=\scriptsize},
   ylabel style={font=\scriptsize},
   xmin=10.0,xmax=60.0,
   ymin=20.0,ymax=40.0,
   xlabel={target time},
   ylabel={agents},
   legend entries={ready,
                   talk},
   legend style={font=\scriptsize,rounded corners=2pt,
                 at={(rel axis cs:0.02,0.50)},anchor=west}]
\addlegendimage{area legend,black,no markers,fill=green}
\addlegendimage{area legend,black,no markers,fill=blue}
\addplot [mark=none,fill=green]
    coordinates {
    (10,30)(12.7,30)(12.7,30)(28.45,30)(28.45,30)(53.83,30)(53.83,30)
    (60,30)}\closedcycle;
\addplot [mark=none,fill=blue]
    coordinates {
    (10,6)(12.7,6)(12.7,5)(28.45,5)(28.45,4)(53.83,4)(53.83,3)
    (60,3)}\closedcycle;
%\begin{pgfonlayer}{foreground}    
\draw[dotted](axis cs:12.70,20.00)--(axis cs:12.70,40.00);
\draw[dotted](axis cs:28.45,20.00)--(axis cs:28.45,40.00);
\draw[dotted](axis cs:53.83,20.00)--(axis cs:53.83,40.00);
%\end{pgfonlayer}
\draw[dotted](axis cs:60.00,20.00)--(axis cs:60.00,40.00);
\end{axis}
\end{tikzpicture}
mtanner
Posts: 9
Joined: Sat Jul 22, 2017 9:55 am

Pgfonlayer

Post by mtanner »

Just had a thought. Could it be related to the "area style" command in the axis statement - do I nee to overlay another axis for the \draw?
mtanner
Posts: 9
Joined: Sat Jul 22, 2017 9:55 am

Pgfonlayer

Post by mtanner »

If I take out the "stack plots=y,area style" then the code workds/ Of course the areas are npot stacked so it does not give me what I want, but it does suggest I need to do the \draw's in a separate axis.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10323
Joined: Mon Mar 10, 2008 9:44 pm

Pgfonlayer

Post by Stefan Kottwitz »

Interesting!

Good that you have a workaround. I think I can take a look again later on it. It reminds me of bug #53 pgfplots and pgfonlayer incompatibility but this had been fixed: Maybe stack plots already use layers internally, but for digging deeper I will have time later today I guess.

Stefan
LaTeX.org admin
Post Reply