6

After a figure construction in my thesis, the compiled figure has an unwanted blue line. The figure is within the margins of the page. So I don't understand why does the blue line shows up and don't know how to remove it.

Failed

When I try to compile the code as a MWE, it works like a charm as follows:

 \documentclass{memoir}
 \usepackage{tikz,pgfplots}
 \usetikzlibrary{arrows.meta}

 \begin{document}
 \chapter{First Chapter}
 \section{First Section}

 \begin{figure}
     \centering
     \begin{tikzpicture}
         \node[anchor=south west] (x) at (0,0) {$x(t)$};

         \draw[-{Latex[length=3mm, width=2mm]}] (0,0)--(1,0);

         \draw  (1,-1) rectangle (3.5,1);
         \draw[-{Latex[length=2.5mm, width=1.25mm]}] (1.2,-0.9)--(1.2,0.9);
         \draw[-{Latex[length=2.5mm, width=1.25mm]}] (1.1,-0.8)--(3.4,-0.8);
         \draw (1.2,0.2) -- (2.2,0.2);
         \draw (2.2,0.2) -- (3,-0.8);
         \node[anchor=center] (a) at (2.25,0.7) {AAF};
         \node[anchor=south east] (b) at (3.4,-0.8) {$f$};

         \draw[-{Latex[length=3mm, width=2mm]}] (3.5,0)--(5,0) node[anchor=south east] {$x_1(t)$};

         \draw  (5,-0.5) rectangle (6,0.5);
         \draw (5.5, -0.8) circle (0.1) node[anchor=north west] {$f_s$};
         \draw (5.5,-0.7) -- (5.5,-0.5);
         \node[anchor=center] (c) at (5.5,0) {S/H};

         \draw[-{Latex[length=3mm, width=2mm]}] (6,0)--(7.5,0) node[anchor=south east] {$y(k)$};

         \draw  (7.5,-1) rectangle (10,1);
         \draw (7.75,-0.9) -| (8.25,-0.5);
         \draw (8.25,-0.5) -| (8.75,0);
         \draw (8.75,0) -| (9.25,0.5);
         \draw (9.25,0.5) -- (9.75,0.5);
         \node[anchor=center] (d) at (8.75,0.75) {Quantizer};

         \draw[-{Latex[length=3mm, width=2mm]}] (10,0)--(11.5,0) node[anchor=south east] {$y(k)$};

         \draw  (11.5,-0.5) rectangle (13,0.5);
         \node[anchor=center] (e) at (12.25,0.2) {Binary};
         \node[anchor=center] (f) at (12.25,-0.2) {Encoder};

         \draw[-{Latex[length=3mm, width=2mm]}] (13,0)--(14,0) node[anchor=south east] {$z$};
     \end{tikzpicture}
     \caption{Generic scheme for an ADC.}
     \label{fig:generic_adc_scheme}
 \end{figure}
 \end{document}

Result:

Correct compilation

I should add that in my thesis I use external figure compilation:

\usepgfplotslibrary{external} 
\tikzexternalize

But it doesn't affect the outcome in the MWE.

EDIT:

After JLDiaz's comment, I tried to scale down figure and the blue line desappears indeed. Then I made a new "big" figure, which checked JLDiaz's hypotesis. The problem here is that the externalization compiles the figures on the first page of the document, which in my thesis is the front page, that contains the mysterious blue line.

The solution that I found was to replace the front page with an blank empty page, compile the document (which compiles the figures on a blank page), then put back the front page and compile the document normally (as figures were already compiled, they are just included in the document).

12
  • 2
    I don't see how it comes from the snippet you show, but what I see is that you do some unfortunate things like naming several nodes (a). I suspect that you have done some similar things in other pictures and then a combination of overlay and remember picture can cause this, but I am not sure. So my first advice is to name the nodes differently. – user121799 Feb 12 '18 at 17:01
  • Your figure is wider than \texwidth in your MWE but we don't know your real document. Where is this blue line appearing? in final pdf in intermediate dvi? are you compiling with pdflatex, latex? do you use any blue line in other figures? ... – Ignasi Feb 12 '18 at 17:03
  • @marmot With the changed names of the nodes, the outcome is still the same. – Syphirint Feb 12 '18 at 17:44
  • 1
    Looks like something similar to this one: tex.stackexchange.com/questions/89057/… Probably your thesis layout uses some kind of blue lines, perhaps in the title page, which interfere with the shipout process done by the externalization mechanism. – JLDiaz Feb 12 '18 at 17:57
  • 1
    @Syphirint It depends on the size of the figure. Externalization causes tikz to make the drawing in the upper left corner of an "empty" page, and then cropping the page to the size of the figure. My guess is that the "empty" page is not empty, but contains some kind of blue frame. If the figure is small enough, the cropped area would not include it. You may test the hypothesys by creating another figure as big as yours. – JLDiaz Feb 12 '18 at 18:14
7
  • for sure this image is not a cause for showed blue line
  • for fun and exercise i re-code your mwe to

\documentclass{memoir}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                backgrounds,
                calc,
                positioning,
                quotes,
                shadows, shapes}

%-------------------------------- show page layout, only for test
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{lipsum}

 \begin{document}
 \chapter{First Chapter}
 \section{First Section}
\lipsum[11]
 \begin{figure}[ht]
     \centering
     \begin{tikzpicture}[
node distance = 6mm and 12mm,
            > = latex,
   box/.style = {rectangle, draw, thick,
                 minimum size=16mm, align=center,
                 outer sep=0pt},
 block/.style = {box, draw, thick, minimum size=8mm},
 quant/.style = {box,
                 append after command={
        \pgfextra{\let\LN\tikzlastnode
        \draw[very thick]
        ($(\LN.south west)+(2mm,2mm)$) -| ++ (3mm,3mm) -| ++ (3mm,3mm)
                                       -| ++ (3mm,3mm) -- ++ (3mm,0mm);
                    }% end \pgfextra
                            }% end after command
                },
   sat/.style = {box,
                 append after command={
        \pgfextra{\let\LN\tikzlastnode
        \draw[-Straight Barb]
        ($(\LN.south west)+(1mm,2mm)$) coordinate (a)
                                       edge  ($(\LN.south east)+(-1mm, 2mm)$)
        ($(\LN.south west)+(2mm,1mm)$)  to   ($(\LN.north west)+( 2mm,-1mm)$);
        \draw[very thick]
        ($(\LN.west)+(2mm,0mm)$) -- (\LN.west -| \LN.south)
                                 -- ([xshift=3mm] a -| \LN.south)
                                      node[above right,inner sep=1pt] {f};
                    }% end \pgfextra
                            }% end after command
                },
%every label/.append style = {font=\small}
                    ]
%
         \node (n1) [sat,label={[anchor=north] AAF}]    {};
         \node (n2) [block,right=of n1]                 {S/H};
         \node (n3) [quant,right=of n2,
                     label={[anchor=north]Quantizer}]   {};
         \node (n4) [block,right=of n3]                 {Binary\\ encoder};
%
    \draw[-Stealth] ($(n1.west)-(1,0)$) edge ["$x(t)$"]     (n1)
                    (n1)                edge ["$x_1(t)$"]   (n2)
                    (n2)                edge ["$y(k)$"]     (n3)
                    (n3)                edge ["$y(k)$"]     (n4)
                    (n4)                 to  ["$z$"]        ($(n4.east)+(1,0)$);
    \end{tikzpicture}
     \caption{Generic scheme for an ADC.}
     \label{fig:generic_adc_scheme}
 \end{figure}
 \lipsum[12]
 \end{document}

which gives

enter image description here

  • defined symbols in my mwe might be usefull in your other tikz pictures
  • from discusion in comments below your question follows, that source of your problem is externalization of tikzpicture
  • one among possible solution is not use externalization but draw each image as separated document using standalone package for document class. for example as:

\documentclass[tikz, margin=0pt]{memoir}
\usetikzlibrary{arrows.meta,
                backgrounds,
                calc,
                positioning,
                quotes,
                shadows, shapes}

 \begin{document}
 ... image code ...
 \end{document}

and than obtained pdf file use as image:

 \begin{figure}[htb]
 \includegraphics{<file name>}
 \end{figure}

... just my 2 cents :-)

3
  • That should probably use the standalone class in the last mwe.... – daleif Feb 12 '18 at 20:48
  • Due to my laziness I was trying to get a one click solution, but unfortunatly there are always drawbacks. – Syphirint Feb 12 '18 at 21:15
  • +1 Thanks! I haven't seen \tikzlastnode before. Will have to devel into section 17.14 of the manual:) – user30471 Feb 12 '18 at 23:10
0

After some experimentation, found that one could impose a white background in the figure, rendering almost everything in the first page "invisible" as follows:

\documentclass{memoir}
\usepackage{tikz,pgfplots}
\usetikzlibrary{arrows.meta}

\usepgfplotslibrary{external} 
\tikzexternalize

\begin{document}
\chapter{First Chapter}
\section{First Section}

\begin{figure}
    \centering
    \begin{tikzpicture}[background rectangle/.style={fill=white}, show background rectangle]
        \node[anchor=south west] (x) at (0,0) {$x(t)$};

        \draw[-{Latex[length=3mm, width=2mm]}] (0,0)--(1,0);

        \draw  (1,-1) rectangle (3.5,1);
        \draw[-{Latex[length=2.5mm, width=1.25mm]}] (1.2,-0.9)--(1.2,0.9);
        \draw[-{Latex[length=2.5mm, width=1.25mm]}] (1.1,-0.8)--(3.4,-0.8);
        \draw (1.2,0.2) -- (2.2,0.2);
        \draw (2.2,0.2) -- (3,-0.8);
        \node[anchor=center] (a) at (2.25,0.7) {AAF};
        \node[anchor=south east] (b) at (3.4,-0.8) {$f$};

        \draw[-{Latex[length=3mm, width=2mm]}] (3.5,0)--(5,0) node[anchor=south east] {$x_1(t)$};

        \draw  (5,-0.5) rectangle (6,0.5);
        \draw (5.5, -0.8) circle (0.1) node[anchor=north west] {$f_s$};
        \draw (5.5,-0.7) -- (5.5,-0.5);
        \node[anchor=center] (c) at (5.5,0) {S/H};

        \draw[-{Latex[length=3mm, width=2mm]}] (6,0)--(7.5,0) node[anchor=south east] {$y(k)$};

        \draw  (7.5,-1) rectangle (10,1);
        \draw (7.75,-0.9) -| (8.25,-0.5);
        \draw (8.25,-0.5) -| (8.75,0);
        \draw (8.75,0) -| (9.25,0.5);
        \draw (9.25,0.5) -- (9.75,0.5);
        \node[anchor=center] (d) at (8.75,0.75) {Quantizer};

        \draw[-{Latex[length=3mm, width=2mm]}] (10,0)--(11.5,0) node[anchor=south east] {$y(k)$};

        \draw  (11.5,-0.5) rectangle (13,0.5);
        \node[anchor=center] (e) at (12.25,0.2) {Binary};
        \node[anchor=center] (f) at (12.25,-0.2) {Encoder};

        \draw[-{Latex[length=3mm, width=2mm]}] (13,0)--(14,0) node[anchor=south east] {$z$};
    \end{tikzpicture}
    \caption{Generic scheme for an ADC.}
    \label{fig:generic_adc_scheme}
\end{figure}
\end{document}

It is to notice that I wrote almost everything, as if there is text on top of the first page and the figure is large enough, the text will be shown.

Zerko's answer is a better solution I think, because it also leaves a better looking and less crowded main .tex.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.