
我使用它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 解析器仍然抱怨,但我不知道這是否是一個真正的問題。
答案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}
編譯為如上所示的輸出。