TikZ 不需要的藍線

TikZ 不需要的藍線

在我的論文中進行圖形建構後,編譯的圖形有一條不需要的藍線。該圖位於頁邊距內。所以我不明白為什麼會出現藍線,也不知道如何刪除它。

失敗的

當我嘗試將程式碼編譯為 MWE 時,它的工作原理如下:

 \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}

結果:

正確編譯

我應該補充一點,在我的論文中我使用外部圖形編譯:

\usepgfplotslibrary{external} 
\tikzexternalize

但這並不影響MWE的結果。

編輯:

在 JLDiaz 發表評論後,我嘗試縮小數字,藍線確實消失了。然後我做了一個新的「大」圖,它檢查了 JLDiaz 的假設。這裡的問題是,外部化編譯了文檔第一頁上的數字,在我的論文中是首頁,其中包含神秘的藍線。

我找到的解決方案是用空白頁替換首頁,編譯文檔(在空白頁上編譯圖形),然後放回首頁並正常編譯文檔(因為圖形已經編譯,所以它們僅包含在文檔中)。

答案1

  • 當然這張圖片不是顯示藍線的原因
  • 為了好玩和鍛煉,我將你的 mwe 重新編碼為

\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}

這使

在此輸入影像描述

  • tikz我的 mwe 中定義的符號可能對您的其他圖片有用
  • 從下面評論中的討論來看,您的問題如下,問題的根源是外部化tikzpicture
  • 可能的解決方案之一是不使用而是使用文檔類別包externalization將每個圖像繪製為單獨的文檔。standalone例如:

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

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

並將獲得的pdf文件用作圖像:

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

....只是我的 2 美分:-)

答案2

經過一番實驗,發現可以在圖中加入白色背景,渲染幾乎第一頁中的所有內容都“不可見”,如下所示:

\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}

注意,我寫的是almost everything,好像第一頁上面有文字,而且圖形夠大,就會顯示文字。

我認為 Zerko 的答案是一個更好的解決方案,因為它也留下了一個更好看且不那麼擁擠的 main .tex

相關內容