将 tikz 与 Miktex 和 TexStudio 结合使用

将 tikz 与 Miktex 和 TexStudio 结合使用

所以我使用 latex 提交作业,我已经努力了好几个小时,只为画一些费曼图。以下是我进行的步骤:

  1. 从 Miktex安装tikz-feynman。Texstudio 拒绝编译。

  2. 通过谷歌搜索发现我实际上需要 TikZ(以为它必须随基本软件包一起提供,但没有)。太好了,输入了\usepackage{tikz}。Texstudio 拒绝编译。

  3. 回到谷歌 - 发现 tikz 带有 pgf,而我没有。去安装了 pgf。Texstudio 拒绝编译。

这是我的片段

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}
\section{abcd}

\end{document}

以下是 Texstudio 的回应

Sorry, but pdflatex.exe did not succeed. The log file hopefully contains the information to get MiKTeX going again: #USER/AppData/Local/MiKTeX/2.9/miktex/log/pdflatex.log You may want to visit the MiKTeX project page, if you need help.

Process exited with error(s)

这是日志文件

LaTeX2e <2017-04-15>
Babel <3.18> and hyphenation patterns for 75 language(s) loaded.
("D:\Software installations\MikTex\tex\latex\base\article.cls"
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
("D:\Software installations\MikTex\tex\latex\base\size10.clo"
File: size10.clo 2014/09/29 v1.4h Standard LaTeX file (size option)
)
\c@part=\count79
\c@section=\count80
\c@subsection=\count81
\c@subsubsection=\count82
\c@paragraph=\count83
\c@subparagraph=\count84
\c@figure=\count85
\c@table=\count86
\abovecaptionskip=\skip41
\belowcaptionskip=\skip42
\bibindent=\dimen102
)
("D:\Software installations\MikTex\tex\latex\pgf\frontendlayer\tikz.sty"
("D:\Software installations\MikTex\tex\latex\pgf\basiclayer\pgf.sty"
("D:\Software installations\MikTex\tex\latex\pgf\utilities\pgfrcs.sty"
("D:\Software installations\MikTex\tex\generic\pgf\utilities\pgfutil-common.tex
"
\pgfutil@everybye=\toks14
\pgfutil@tempdima=\dimen103
\pgfutil@tempdimb=\dimen104

("D:\Software installations\MikTex\tex\generic\pgf\utilities\pgfutil-common-lis
ts.tex"))
("D:\Software installations\MikTex\tex\generic\pgf\utilities\pgfutil-latex.def"
\pgfutil@abb=\box26

是的,我刷新了 FNDB,更新了 Texstudio,更改了镜像,卸载并重新安装了上述所有软件包几次。我累了。

有人能告诉我,为了获得并随后工作,我还需要安装哪些其他依赖项吗pgftikztikz-feynman这个阶段,完整的代码片段将非常非常受欢迎,或者如果是这样的话,按照特定顺序安装所需软件包的指南将非常受欢迎。

提前致谢。

答案1

如果 MikTeX 安装正确,使用 MikTeX 控制台应用程序设置自动安装缺失包的选项将大大减轻您的压力。控制台>设置>>选择自动下载缺失包 - 是。还要下载所有 PGF 包,磁盘空间很便宜。PGFPLOTS/TikZ 是 TeX 社区的一个很棒的补充,但学习曲线是多方面的。我使用 WinEdt IDE 运行了您的代码,没有发现任何问题。TeXStudio 是否具有正确的配置?您在哪里安装与 MikTeX 包结构相关的包?权限可能会发挥作用。

这是一个可以与 PDFLaTeX 一起编译的 MWE:

\documentclass{article}
\usepackage{tikz-feynman}
%\usetikzlibrary{positioning}

\begin{document}
\section{abcd}
\feynmandiagram [horizontal=a to b] {
  i1 -- [fermion] a -- [fermion] i2,
  a -- [photon] b,
  f1 -- [fermion] b -- [fermion] f2,
  };
\begin{tikzpicture}
\begin{feynman}
\vertex (a1) {\(\overline b\)};
\vertex[right=1cm of a1] (a2);
\vertex[right=1cm of a2] (a3);
\vertex[right=1cm of a3] (a4) {\(b\)};
\vertex[right=1cm of a4] (a5);
\vertex[right=2cm of a5] (a6) {\(u\)};

\vertex[below=2em of a1] (b1) {\(d\)};
\vertex[right=1cm of b1] (b2);
\vertex[right=1cm of b2] (b3);
\vertex[right=1cm of b3] (b4) {\(\overline d\)};
\vertex[below=2em of a6] (b5) {\(\overline d\)};

\vertex[above=of a6] (c1) {\(\overline u\)};
\vertex[above=2em of c1] (c3) {\(d\)};
\vertex at ($(c1)!0.5!(c3) - (1cm, 0)$) (c2);

\diagram* {
  {[edges=fermion]
    (b1) -- (b2) -- (a2) -- (a1),
    (b5) -- (b4) -- (b3) -- (a3) -- (a4) -- (a5) -- (a6),
  },
  (a2) -- [boson, edge label=\(W\)] (a3),
  (b2) -- [boson, edge label'=\(W\)] (b3),

  (c1) -- [fermion, out=180, in=-45] (c2) -- [fermion, out=45, in=180] (c3),
  (a5) -- [boson, bend left, edge label=\(W^{-}\)] (c2),
};

\draw [decoration={brace}, decorate] (b1.south west) -- (a1.north west)
      node [pos=0.5, left] {\(B^{0}\)};
\draw [decoration={brace}, decorate] (c3.north east) -- (c1.south east)
      node [pos=0.5, right] {\(\pi^{-}\)};
\draw [decoration={brace}, decorate] (a6.north east) -- (b5.south east)
      node [pos=0.5, right] {\(\pi^{+}\)};
\end{feynman}
\end{tikzpicture}
\end{document} 

我截取了您的代码片段并插入了 CTAN tikz-feynman 文档中的一些示例代码。一些包示例需要 LUATEX 或 XETEX。我目前不做这些,但请注意 tikzpicture 环境将为您提供很多选项。此外,MikTex 自动下载功能将有助于解决您尚未安装的包问题,但您仍然必须知道您正在使用什么,即 \usepackage{...} 调用。

祝好,戴夫

相关内容