3

Sadly I wasn't able to get the help I needed from this other question with the same problem:

Undefined control sequence \draw and \end{tikzpicture}

I am using the code presented in this answer: https://tex.stackexchange.com/a/25433/61740 and my objective is to show selections of an image and magnify them. I have used the code exactly as presented there (that is where the zoomboxes come from).

My code is as follows:

\documentclass{article}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{spy,calc}
\usepackage{hyperref}


\newif\ifblackandwhitecycle
\gdef\patternnumber{0}

\pgfkeys{/tikz/.cd,
    zoombox paths/.style={
        draw=orange,
        very thick
    },
    black and white/.is choice,
    black and white/.default=static,
    black and white/static/.style={
        draw=white,
        zoombox paths/.append style={
            draw=white,
            postaction={
                draw=black,
                loosely dashed
            }
        }
    },
    black and white/static/.code={
        \gdef\patternnumber{1}
    },
    black and white/cycle/.code={
        \blackandwhitecycletrue
        \gdef\patternnumber{1}
    },
    black and white pattern/.is choice,
    black and white pattern/0/.style={},
    black and white pattern/1/.style={
            draw=white,
            postaction={
                draw=black,
                dash pattern=on 2pt off 2pt
            }
    },
    black and white pattern/2/.style={
            draw=white,
            postaction={
                draw=black,
                dash pattern=on 4pt off 4pt
            }
    },
    black and white pattern/3/.style={
            draw=white,
            postaction={
                draw=black,
                dash pattern=on 4pt off 4pt on 1pt off 4pt
            }
    },
    black and white pattern/4/.style={
            draw=white,
            postaction={
                draw=black,
                dash pattern=on 4pt off 2pt on 2 pt off 2pt on 2 pt off 2pt
            }
    },
    zoomboxarray inner gap/.initial=5pt,
    zoomboxarray columns/.initial=2,
    zoomboxarray rows/.initial=2,
    subfigurename/.initial={},
    figurename/.initial={zoombox},
    zoomboxarray/.style={
        execute at begin picture={
            \begin{scope}[
                spy using outlines={%
                    zoombox paths,
                    width=\imagewidth / \pgfkeysvalueof{/tikz/zoomboxarray columns} - (\pgfkeysvalueof{/tikz/zoomboxarray columns} - 1) / \pgfkeysvalueof{/tikz/zoomboxarray columns} * \pgfkeysvalueof{/tikz/zoomboxarray inner gap} -\pgflinewidth,
                    height=\imageheight / \pgfkeysvalueof{/tikz/zoomboxarray rows} - (\pgfkeysvalueof{/tikz/zoomboxarray rows} - 1) / \pgfkeysvalueof{/tikz/zoomboxarray rows} * \pgfkeysvalueof{/tikz/zoomboxarray inner gap}-\pgflinewidth,
                    magnification=3,
                    every spy on node/.style={
                        zoombox paths
                    },
                    every spy in node/.style={
                        zoombox paths
                    }
                }
            ]
        },
        execute at end picture={
            \end{scope}
            \node at (image.north) [anchor=north,inner sep=0pt] {\subcaptionbox{\label{\pgfkeysvalueof{/tikz/figurename}-image}}{\phantomimage}};
            \node at (zoomboxes container.north) [anchor=north,inner sep=0pt] {\subcaptionbox{\label{\pgfkeysvalueof{/tikz/figurename}-zoom}}{\phantomimage}};
     \gdef\patternnumber{0}
        },
        spymargin/.initial=0.5em,
        zoomboxes xshift/.initial=1,
        zoomboxes right/.code=\pgfkeys{/tikz/zoomboxes xshift=1},
        zoomboxes left/.code=\pgfkeys{/tikz/zoomboxes xshift=-1},
        zoomboxes yshift/.initial=0,
        zoomboxes above/.code={
            \pgfkeys{/tikz/zoomboxes yshift=1},
            \pgfkeys{/tikz/zoomboxes xshift=0}
        },
        zoomboxes below/.code={
            \pgfkeys{/tikz/zoomboxes yshift=-1},
            \pgfkeys{/tikz/zoomboxes xshift=0}
        },
        caption margin/.initial=4ex,
    },
    adjust caption spacing/.code={},
    image container/.style={
        inner sep=0pt,
        at=(image.north),
        anchor=north,
        adjust caption spacing
    },
    zoomboxes container/.style={
        inner sep=0pt,
        at=(image.north),
        anchor=north,
        name=zoomboxes container,
        xshift=\pgfkeysvalueof{/tikz/zoomboxes xshift}*(\imagewidth+\pgfkeysvalueof{/tikz/spymargin}),
        yshift=\pgfkeysvalueof{/tikz/zoomboxes yshift}*(\imageheight+\pgfkeysvalueof{/tikz/spymargin}+\pgfkeysvalueof{/tikz/caption margin}),
        adjust caption spacing
    },
    calculate dimensions/.code={
        \pgfpointdiff{\pgfpointanchor{image}{south west} }{\pgfpointanchor{image}{north east} }
        \pgfgetlastxy{\imagewidth}{\imageheight}
        \global\let\imagewidth=\imagewidth
        \global\let\imageheight=\imageheight
        \gdef\columncount{1}
        \gdef\rowcount{1}
        \gdef\zoomboxcount{1}
    },
    image node/.style={
        inner sep=0pt,
        name=image,
        anchor=south west,
        append after command={
            [calculate dimensions]
            node [image container,subfigurename=\pgfkeysvalueof{/tikz/figurename}-image] {\phantomimage}
            node [zoomboxes container,subfigurename=\pgfkeysvalueof{/tikz/figurename}-zoom] {\phantomimage}
        }
    },
    color code/.style={
        zoombox paths/.append style={draw=#1}
    },
    connect zoomboxes/.style={
    spy connection path={\draw[draw=none,zoombox paths] (tikzspyonnode) -- (tikzspyinnode);}
    },
    help grid code/.code={
        \begin{scope}[
                x={(image.south east)},
                y={(image.north west)},
                font=\footnotesize,
                help lines,
                overlay
            ]
            \foreach \x in {0,1,...,9} {
                \draw(\x/10,0) -- (\x/10,1);
                \node [anchor=north] at (\x/10,0) {0.\x};
            }
            \foreach \y in {0,1,...,9} {
                \draw(0,\y/10) -- (1,\y/10);                        \node [anchor=east] at (0,\y/10) {0.\y};
            }
        \end{scope}
    },
    help grid/.style={
        append after command={
            [help grid code]
        }
    },
}

\newcommand\phantomimage{%
    \phantom{%
        \rule{\imagewidth}{\imageheight}%
    }%
}
\newcommand\zoombox[2][]{
    \begin{scope}[zoombox paths]
        \pgfmathsetmacro\xpos{
            (\columncount-1)*(\imagewidth / \pgfkeysvalueof{/tikz/zoomboxarray columns} + \pgfkeysvalueof{/tikz/zoomboxarray inner gap} / \pgfkeysvalueof{/tikz/zoomboxarray columns} ) + \pgflinewidth
        }
        \pgfmathsetmacro\ypos{
            (\rowcount-1)*( \imageheight / \pgfkeysvalueof{/tikz/zoomboxarray rows} + \pgfkeysvalueof{/tikz/zoomboxarray inner gap} / \pgfkeysvalueof{/tikz/zoomboxarray rows} ) + 0.5*\pgflinewidth
        }
        \edef\dospy{\noexpand\spy [
            #1,
            zoombox paths/.append style={
                black and white pattern=\patternnumber
            },
            every spy on node/.append style={#1},
            x=\imagewidth,
            y=\imageheight
        ] on (#2) in node [anchor=north west] at ($(zoomboxes container.north west)+(\xpos pt,-\ypos pt)$);}
        \dospy
        \pgfmathtruncatemacro\pgfmathresult{ifthenelse(\columncount==\pgfkeysvalueof{/tikz/zoomboxarray columns},\rowcount+1,\rowcount)}
        \global\let\rowcount=\pgfmathresult
        \pgfmathtruncatemacro\pgfmathresult{ifthenelse(\columncount==\pgfkeysvalueof{/tikz/zoomboxarray columns},1,\columncount+1)}
        \global\let\columncount=\pgfmathresult
        \ifblackandwhitecycle
            \pgfmathtruncatemacro{\newpatternnumber}{\patternnumber+1}
            \global\edef\patternnumber{\newpatternnumber}
        \fi
    \end{scope}
}


\begin{document}
\begin{figure*}
\begin{tikzpicture}[zoomboxarray, zoomboxes below]
    \node [image node] { \includegraphics[scale=0.3]{example-image-a} };
    \zoombox[magnification=1.65,color code=red]{0.16,0.16}
    \zoombox[magnification=2.1,color code=yellow]{0.42,0.63}
\end{tikzpicture}
\caption{Detailed look.}
\label{fig:detail}
\end{figure*}
\end{document}

However, it works perfectly, but it leaves me with the Undefined control sequence \end{tikzpicture} error message, but nothing about \draw as in the related question. This error message comes from compiling with Kile.

When compiling with pdflatex the following message occurs:

! Undefined control sequence.
\tikz@atend@picture ...r sep=0pt] \{\subcaptionbox 
                                                  {\label {\pgfkeysvalueof {...
l.422 \end{tikzpicture}

If the subcaptionbox package is not commented out, the following error is presented:

! Package subcaption Error: This package can't be used in cooperation
(subcaption)                with the subfig package.
user1603472
  • 191
  • 1
  • 5
  • 4
    where does the zoombox stuff come from? It would be much easier if we see the whole document. Otherwise we are in the dark. – percusse Jul 06 '15 at 16:36
  • please add a complete MWE – touhami Jul 06 '15 at 16:41
  • Did you try removing/commenting out the \zoombox instructions? Does it work? If it does, then you found the culprit! – LaX Jul 06 '15 at 17:57
  • I have a huge document so I can't quote everything, but I have simply pasted in the code from the tex answer I just referenced in the question now. Can't understand the error message, because everything seems to work. Considering just creating a screenshot as a workaround. – user1603472 Jul 06 '15 at 19:06
  • I've completed your code by adding the code from the answer you linked to. So now you have an MWE. But it compiled without error here so it cannot be used to reproduce the problem you are asking about. The problem must lie elsewhere. Please modify the example so that it shows the problem you need help with. – cfr Jul 06 '15 at 19:23
  • You can not possibly have a tex error that says Undefined control sequence \end{tikzpicture} the subject of that error is always a control sequence that is a single command. As well as fixing the example so it demonstrates the error, you should place the exact error message from the log in a {} code block in your question, so that line breaks (which are very important in tex error messages) are preserved. – David Carlisle Jul 06 '15 at 21:57
  • Thanks, guys. I didn't mean to be rude by posting a poor question, it's just my first on this forum. It comes from a very long document (200 pages+) so I was hoping experienced users could interpret the error messasge or help me chase in the right direction. I will update again. – user1603472 Jul 06 '15 at 22:07
  • The undefined command is \subcaptionbox. I can compile your example fine. No errors at all. I can compile without error using pdflatex, xelatex, lualatex or latex. I compiled twice with each to rule out errors which appear only when the generated files are read on the second run. No problems. – cfr Jul 06 '15 at 22:17
  • Can you try compiling the very same code currently in your question? Create a new .tex document, paste the code there and compile it. This is a sanity check: we want to figure out if the problem is really your code or something else. I also checked with pdflatex from TeX Live 2015, 2014, 2013, 2012 and 2011. – cfr Jul 06 '15 at 22:24
  • Turns out that \subcaption is not possible to use alongside the {subfig} package, which is why it was commented out. subfig is imported through the classicthesis.sty style I'm using so I don't think it can be commented out. I'll update the question with that information. – user1603472 Jul 08 '15 at 07:06
  • Best option: don't use classicthesis. Take what you need and like from it, but don't use the whole caboodle. It breeds problems, mysterious errors and incompatibilities. Otherwise, you'll have to make do without subcaption, I think. I've used subfig and worked around not being able to use subcaption just because my document was almost done and I just needed to work around something for one figure. But switching to subcaption is probably a better choice. – cfr Jul 08 '15 at 14:18
  • @cfr What to do here? Suggestions? – Johannes_B Feb 15 '16 at 10:05
  • @Johannes_B Close? As given, it is a non-question: there is no problem with the code. And all that emerges in comments is that the question lacks the information necessary to reproduce the problem and that that information is that classicthesis is, as so often, the problem. Do you see much worth pulling out of it? – cfr Feb 15 '16 at 23:18
  • 2
    @cfr voted as unclear. – Johannes_B Feb 15 '16 at 23:58

0 Answers0