我使用 MikTex 和 Texmaker,以及配置-LaTeX+dvips+ps2pdf+View PDF。我有以下 latex 命令:
\documentclass[11pt]{article}
\usepackage{graphicx}
\usepackage{amsmath,amsfonts,amsthm}
\usepackage{pst-all}
\begin{document}
\begin{figure}[h]
\centering
\begin{pspicture}(4,4.3)
\rput(3.7,-0.2){\scalebox{1.2}{
\psdot(1.5,3.5)\rput(1.45,3.75){$v_1$}
\psdot(-1,2)\rput(-1.3,2){$v_2$}
\psdot(.5,2.3)\rput(0.9,2.3){$v_3$}
\psdot(3,1)\rput(3,0.7){$v_4$}
\psdot(4,2)\rput(4.3,2){$v_5$}
\psdot(1,0.5)\rput(1,0.2){$v_6$}
\psline(1.5,3.5)(-1,2)
\psline(1.5,3.5)(0.5,2.3)
\psline(1.5,3.5)(3,1)
\psline(1.5,3.5)(1,0.5)
\psline(-1,2)(.5,2.3)
\psline(-1,2)(1,0.5)
\psline(-1,2)(4,2)
\psline(3,1)(.5,2.3)
\psline(4,2)(3,1)
\psline(-1,2)(1,0.5)
}
\end{pspicture}
\caption{The graph $G_1$}\label{Fig-1}
\end{figure}
}
\end{document}
当我尝试运行源文件时,该图没有出现。出现以下错误:
!LaTeX Error: Two \documentclass or \documentstyle commands.
但是,没有\documentclass
像警告的那样使用两个。请帮我排除故障。
答案1
我猜测您的文档名为pstricks.tex
并且您的日志看起来像这样:
(/usr/local/texlive/2023/texmf-dist/tex/generic/xkeyval/pst-xkey.tex
(/usr/local/texlive/2023/texmf-dist/tex/latex/xkeyval/xkeyval.sty
(/usr/local/texlive/2023/texmf-dist/tex/generic/xkeyval/xkeyval.tex
(/usr/local/texlive/2023/texmf-dist/tex/generic/xkeyval/xkvutils.tex))))
(./pstricks.tex
! LaTeX Error: Two \documentclass or \documentstyle commands.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.1 \documentclass[11pt]{
article}
?
问题在于,这pstricks.sty
是一个纯 tex 文件的乳胶包装器pstricks.tex
,因此,如果您的文档pstricks.tex
在调用时被调用\usepackage{pstricks}
,它最终会执行操作\input pstricks.tex
,而不是找到 pstricks 代码,它会重新输入您的文档,您会收到两个文档类错误。
只需将您的文档文件重命名为其他名称即可。
如果文档被重命名,则日志/终端输出的该部分是:
(/usr/local/texlive/2023/texmf-dist/tex/generic/xkeyval/xkeyval.tex
(/usr/local/texlive/2023/texmf-dist/tex/generic/xkeyval/xkvutils.tex))))
(/usr/local/texlive/2023/texmf-dist/tex/generic/pstricks/pstricks.tex
表示真实pstricks.tex
信息texmf-dist/tex/generic/pstricks/pstricks.tex
已经加载。
答案2
分组有误,修改MWE
为:
\documentclass[11pt]{article}
\usepackage{graphicx}
\usepackage{amsmath,amsfonts,amsthm}
\usepackage{pst-all}
\begin{document}
\begin{figure}[h]
\centering
\begin{pspicture}(4,4.3)
\rput(3.7,-0.2){\scalebox{1.2}{
\psdot(1.5,3.5)\rput(1.45,3.75){$v_1$}
\psdot(-1,2)\rput(-1.3,2){$v_2$}
\psdot(.5,2.3)\rput(0.9,2.3){$v_3$}
\psdot(3,1)\rput(3,0.7){$v_4$}
\psdot(4,2)\rput(4.3,2){$v_5$}
\psdot(1,0.5)\rput(1,0.2){$v_6$}
\psline(1.5,3.5)(-1,2)
\psline(1.5,3.5)(0.5,2.3)
\psline(1.5,3.5)(3,1)
\psline(1.5,3.5)(1,0.5)
\psline(-1,2)(.5,2.3)
\psline(-1,2)(1,0.5)
\psline(-1,2)(4,2)
\psline(3,1)(.5,2.3)
\psline(4,2)(3,1)
\psline(-1,2)(1,0.5)
}}
\end{pspicture}
\caption{The graph $G_1$}\label{Fig-1}
\end{figure}
\end{document}
输出
答案3
用 运行lualatex --shell-escape <your file>
。然后它可以计算图像的帧。并使用节点,使生活更轻松:
\DocumentMetadata{}
\documentclass[11pt]{article}
\usepackage{graphicx}
\usepackage{amsmath,amsfonts,amsthm}
\usepackage{pst-all}
\begin{document}
\begin{figure}[!htb]
\centering
\psset{calcframe}
\begin{pspicture}%
\pnodes{v}(0,0)(1.5,3.5)(-1,2)(0.5,2.3)(3,1)(4,2)(1,0.5)
\pspolygon[showpoints](v5)(v4)(v3)(v2)(v1)(v6)(v2)
\pspolygon[showpoints](v3)(v1)(v4)
\uput[90](v1){$v_1$}\uput[180](v2){$v_2$}\uput[0](v3){$v_3$}
\uput[-90](v4){$v_4$}\uput[0](v5){$v_5$}\uput[-90](v6){$v_6$}
\end{pspicture}
\caption{The graph $G_1$}\label{Fig-1}
\end{figure}
\end{document}