編輯

編輯

我使用它TikzEdt是為了產生一些在我的論文中使用的數字。但是,當我透過以下方式包含原始程式碼時複製貼上/\輸入在主文檔中,under a figure environment我的文檔花了很長時間才編譯,沒有任何錯誤,並在取消編譯後產生損壞的 PDF 輸出檔。

就我而言,我在序言中擁有所有必要的包,並且在檢查從 導出的程式碼後生成了一個最小的工作範例TikzEdt

非編譯檔很大,所以驅動檔是這裡, 這類別文件是一個修改過的書籍類,並且包含是基本的。

此外,還TikzEdt抱怨以下行帶有訊息:「無法解析程式碼。第 16 行第 44 處的 NoViableAltException。」。編譯 MWE 是這裡

\draw[<->, 厚] (-1,0)++({\ang+90}:1) --++ (\ang:{2*cos(\ang)});

編輯 問題已解決,問題是我使用了\ang套件中定義的內部巨集siunitx。 TikzEdt 解析器仍然抱怨,但我不知道這是否是一個真正的問題。

下面是該問題的螢幕截圖TikzEdt。錯誤訊息顯示在紅線在此輸入影像描述

答案1

嗯,顯然,您需要一個\begin{document},但它可以很好地轉換為帶有圖片的常規文件figure

\documentclass{article}
\usepackage{tikz,amsmath, amssymb,bm,color}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{decorations.markings,math}
\usetikzlibrary{calc}

\begin{document}
\begin{figure}
  \center
  \begin{tikzpicture}
    \tikzmath{\ang = 45;};
    \begin{scope}[thick,decoration={
        markings,
        mark=at position 0.5 with {\arrow{latex}}}
      ]
      \filldraw[red] (-1,0) circle (2pt)
      node[anchor=east, font = \footnotesize] at (-1,-0.2) {$\mathrm{E_0}$};
      \draw[dashed, red] (-1,0) --++({\ang+90}:1);
      \filldraw[green] (1,0) circle (2pt)
      node[anchor=west, font = \footnotesize] at (1,-0.2) {$\mathrm{E_0}$};
      \draw[postaction={decorate}, red] (-1,0) --++ (\ang:2);
      \draw[postaction={decorate}, green] (1,0) --++ (\ang:2);
      \draw[<->, thick] (-1, -0.2) -- (1, -0.2);
      \draw[dashed, green] (1,0) --++ ({\ang+90}:2.5);
      \draw[<->, thick] (-1,0)++({\ang+90}:1) --++ (\ang:{2*cos(\ang)});
      %       \draw[<->, thick] (-1,0)++({\ang+90}:1) --++ (\ang:{2*cos(\ang) });
      \node[anchor=north, font = \footnotesize]  at  (0, -0.2) {d=$\lambda/2$};
    \end{scope}
    \draw[blue, thick, dash pattern= on 25 off 7 on 50 off 7 on 10] (-2,0) -- (2, 0);
    \node[anchor=west, font = \footnotesize, blue] at (1.5,-0.05) {z}; node[near start, auto] {true}
    \draw[thick,blue,->] ([shift=(0:1)]1,0) arc (0:\ang:1);
    %   \draw[thick,blue,->] (2,0)  arc (0:\ang:1);
    \draw (1,0)++({\ang/2}:1.2) node[rotate=\ang, anchor=base, blue, font=\normalsize]{$\theta$};
    \draw ({\ang+90}:1.3) node[rotate=\ang, anchor=base, black, font=\normalsize]{$d\cos\theta$};
  \end{tikzpicture}
  \caption{Picture}
\end{figure}
\end{document}

數位

可能我不明白這個問題。

編輯

添加siunitx會產生錯誤,但我不知道這是否是您的錯誤。特別xparse抱怨\ang不可擴展。這是因為當前程式碼調用\ang,它不再是未分配的巨集名稱。所以它試圖擴展\ang它的定義,但不能。 (而且,如果可以的話,結果也不會好。)

解決方案是使用新名稱,例如\myangle.

\documentclass{article}
\usepackage{tikz,amsmath,amssymb,bm}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{decorations.markings,math}
\usetikzlibrary{calc}
\usepackage{siunitx}

\begin{document}
\begin{figure}
  \center
  \begin{tikzpicture}
    \tikzmath{\myangle = 45;};
    \begin{scope}[thick,decoration={
        markings,
        mark=at position 0.5 with {\arrow{latex}}}
      ]
      \filldraw[red] (-1,0) circle (2pt)
      node[anchor=east, font = \footnotesize] at (-1,-0.2) {$\mathrm{E_0}$};
      \draw[dashed, red] (-1,0) --++({\myangle+90}:1);
      \filldraw[green] (1,0) circle (2pt)
      node[anchor=west, font = \footnotesize] at (1,-0.2) {$\mathrm{E_0}$};
      \draw[postaction={decorate}, red] (-1,0) --++ (\myangle:2);
      \draw[postaction={decorate}, green] (1,0) --++ (\myangle:2);
      \draw[<->, thick] (-1, -0.2) -- (1, -0.2);
      \draw[dashed, green] (1,0) --++ ({\myangle+90}:2.5);
      \draw[<->, thick] (-1,0)++({\myangle+90}:1) --++ (\myangle:{2*cos(\myangle)});
      %       \draw[<->, thick] (-1,0)++({\myangle+90}:1) --++ (\myangle:{2*cos(\myangle) });
      \node[anchor=north, font = \footnotesize]  at  (0, -0.2) {d=$\lambda/2$};
    \end{scope}
    \draw[blue, thick, dash pattern= on 25 off 7 on 50 off 7 on 10] (-2,0) -- (2, 0);
    \node[anchor=west, font = \footnotesize, blue] at (1.5,-0.05) {z}; node[near start, auto] {true}
    \draw[thick,blue,->] ([shift=(0:1)]1,0) arc (0:\myangle:1);
    %   \draw[thick,blue,->] (2,0)  arc (0:\myangle:1);
    \draw (1,0)++({\myangle/2}:1.2) node[rotate=\myangle, anchor=base, blue, font=\normalsize]{$\theta$};
    \draw ({\myangle+90}:1.3) node[rotate=\myangle, anchor=base, black, font=\normalsize]{$d\cos\theta$};
  \end{tikzpicture}
  \caption{Picture}
\end{figure}
\end{document}

編譯為如上所示的輸出。

相關內容