我正在尝试为论文制作插图,但我没有太多时间,所以我没有时间学习一门完整的语言,所以我知道 GeoGebra 可以自动生成代码。这是我想要实现的结果(较暗的区域=我想要保留的部分):
以下是自动生成的代码:
\documentclass[10pt]{article}
\usepackage{pstricks-add}
\pagestyle{empty}
\begin{document}
\psset{xunit=1.0cm,yunit=1.0cm,algebraic=true,dimen=middle,dotstyle=o,dotsize=5pt 0,linewidth=2.pt,arrowsize=3pt 2,arrowinset=0.25}
\begin{pspicture*}(-0.75,-0.2)(2.5,1.8)
\psaxes[labelFontSize=\scriptstyle,xAxis=true,yAxis=true,Dx=0.2,Dy=0.2,ticksize=-2pt 0,subticks=2]{->}(0,0)(-0.75,-0.2)(2.5,1.8)
\psplot[linewidth=2.pt]{-0.75}{2.5}{(--1.92-1.2*x)/1.6}
\psline[linewidth=1.2pt,linestyle=dashed,dash=1pt 1pt](0.,0.)(0.576,0.768)
\psline[linewidth=1.2pt,linestyle=dashed,dash=1pt 1pt](-0.4,1.19677)(-0.4,0.)
\psline[linewidth=1.2pt,linestyle=dashed,dash=1pt 1pt](0.992,0.456)(1.4,1.)
\begin{scriptsize}
\rput[bl](-1.2222293167219342,2.0250662487315707){Iperpiano}
\psdots[dotstyle=*](0.,0.)
\rput[bl](0.347674159199165,0.33990526238231566){$\scalebox{1.5}{\boldsymbol{\cfrac{b}{\lVert \underline w\rVert}}}$}
\psdots[dotsize=4pt 0,dotstyle=*,linecolor=darkgray](0.,1.2)
\rput[bl](0.01742007432551912,1.2396098567891212){\darkgray{$D$}}
\rput[bl](-0.5330034004638906,0.5826826926190728){$\scalebox{1.5}{\boldsymbol{b}}$}
\psdots[dotstyle=*](1.4,1.)
\rput[bl](1.4676662731184857,0.9444686670895343){$\scalebox{1.5}{\boldsymbol{x^{(i)}}$}
\rput[bl](1.2570694653729724,0.6826498697753844){$\scalebox{1.5}{\boldsymbol{d^{(i)}=\cfrac{y^{(i)}(\langle\underline{w},\underline{x}\rangle+b)}{\lVert \underline w\rVert}}}$}
\end{scriptsize}
\end{pspicture*}
\end{document}
但代码无法通过 pdfLaTeX 和 XeLaTeX 编译。我得到的只是几个“未定义的控制序列”错误,如下所示:
Undefined control sequence. ...l{\cfrac{b}{\lVert \underline w\rVert}}}$}
Undefined control sequence. ...l{\cfrac{b}{\lVert \underline w\rVert}}}$}
Undefined control sequence. ...l{\cfrac{b}{\lVert \underline w\rVert}}}$}
Undefined control sequence. ...l{\cfrac{b}{\lVert \underline w\rVert}}}$}
Undefined control sequence. ...l{\cfrac{b}{\lVert \underline w\rVert}}}$}
Undefined control sequence. ...3984034){$\scalebox{1.5}{\boldsymbol{b}}$}
Undefined control sequence. ...3984034){$\scalebox{1.5}{\boldsymbol{b}}$}
File ended while scanning use of \pst@makenotverbbox.
No file amsmath.tex.
我添加了\include{amsmath}
代码,因为我知道代码\cfrac
来自那里,但它没有解决,我仍然得到相同的错误...但它是自动生成的,所以语法一定是正确的。出了什么问题?
答案1
您没有显示错误消息,只是显示缺少主要信息的摘要。
第一个错误是
! Undefined control sequence.
<recently read> \scalebox
l.15 ...l{\cfrac{b}{\lVert \underline w\rVert}}}$}
?
显示\scalebox
未定义。它来自graphicx
(或graphics
)包。
添加
\usepackage{graphicx}
并重新运行生产
! Undefined control sequence.
<argument> \boldsymbol
{\cfrac {b}{\lVert \underline w\rVert }}
l.16 ...l{\cfrac{b}{\lVert \underline w\rVert}}}$}
?
显示\boldsymbol
未定义,这来自amsmath
所以添加
\usepackage{amsmath}
产生
! Missing $ inserted.
<inserted text>
$
l.16 ...l{\cfrac{b}{\lVert \underline w\rVert}}}$}
?
因此,将所有不正确的替换$\scalebox{1.5}{
为\scalebox{1.5}{$
然后运行就不会出错了
\documentclass[10pt]{article}
\usepackage{pstricks-add}
\usepackage{graphicx,amsmath}
\pagestyle{empty}
\begin{document}
\psset{xunit=1.0cm,yunit=1.0cm,algebraic=true,dimen=middle,dotstyle=o,dotsize=5pt 0,linewidth=2.pt,arrowsize=3pt 2,arrowinset=0.25}
\begin{pspicture*}(-0.75,-0.2)(2.5,1.8)
\psaxes[labelFontSize=\scriptstyle,xAxis=true,yAxis=true,Dx=0.2,Dy=0.2,ticksize=-2pt 0,subticks=2]{->}(0,0)(-0.75,-0.2)(2.5,1.8)
\psplot[linewidth=2.pt]{-0.75}{2.5}{(--1.92-1.2*x)/1.6}
\psline[linewidth=1.2pt,linestyle=dashed,dash=1pt 1pt](0.,0.)(0.576,0.768)
\psline[linewidth=1.2pt,linestyle=dashed,dash=1pt 1pt](-0.4,1.19677)(-0.4,0.)
\psline[linewidth=1.2pt,linestyle=dashed,dash=1pt 1pt](0.992,0.456)(1.4,1.)
\begin{scriptsize}
\rput[bl](-1.2222293167219342,2.0250662487315707){Iperpiano}
\psdots[dotstyle=*](0.,0.)
\rput[bl](0.347674159199165,0.33990526238231566){\scalebox{1.5}{$\boldsymbol{\cfrac{b}{\lVert \underline w\rVert}}$}}
\psdots[dotsize=4pt 0,dotstyle=*,linecolor=darkgray](0.,1.2)
\rput[bl](0.01742007432551912,1.2396098567891212){\darkgray{$D$}}
\rput[bl](-0.5330034004638906,0.5826826926190728){\scalebox{1.5}{$\boldsymbol{b}$}}
\psdots[dotstyle=*](1.4,1.)
\rput[bl](1.4676662731184857,0.9444686670895343){\scalebox{1.5}{$\boldsymbol{x^{(i)}}$}}
\rput[bl](1.2570694653729724,0.6826498697753844){\scalebox{1.5}{$\boldsymbol{d^{(i)}=\cfrac{y^{(i)}(\langle\underline{w},\underline{x}\rangle+b)}{\lVert \underline w\rVert}}$}}
\end{scriptsize}
\end{pspicture*}
\end{document}
最终的输出可能不是预期的,但这是另一个问题
或者如果你将 pspicture 单位从 1cm 更改为 4cm
\psset{xunit=4.0cm,yunit=4.0cm,algebraic=true,dimen=middle,dotstyle=o,dotsize=5pt 0,linewidth=2.pt,arrowsize=3pt 2,arrowinset=0.25}