使用独立类删除百分号 (%) 时图像会偏移

使用独立类删除百分号 (%) 时图像会偏移

我偶尔会发现,一些 LaTeX 宏在有和没有行尾注释的情况下表现不同。我对此的理解是,宏可能会在堆栈上留下一个空间,但由于某种原因,这个空间会被移除如果宏以百分号结尾。我一直不太明白为什么会发生这种情况,所以我慢慢养成了以百分号结尾的习惯全部LaTeX 中带有 % 的“函数调用” 在本例中,我发现\pstScalePoints\newpsstyle表现得像那样,并努力将问题隔离到以下 MWE 中:

\documentclass{standalone}
\usepackage{pstricks}
\usepackage{pstricks-add}
\usepackage{pst-plot}
\listfiles
\begin{document}
\readdata{\mytable}{table.txt}  
\pstScalePoints(1.0,1.0){1.0 div}{1.0 div}%  <-- NB!
\newpsstyle{legendstyle}{fillstyle=solid}%   <-- NB!
\begin{psgraph}(0,0)(0,0)(1,1){1cm}{1cm}
\listplot{\mytable}
\end{psgraph}
\end{document}

问题:如果删除两个行尾 % 符号,输出会发生变化。我怀疑宏在堆栈上留下了一个空格,但我不知道如何纠正它 - 除了顽固地将 % 添加到全部宏观结局!

文件内容table.txt为:

0.0, 0.00
0.2, 0.04
0.4, 0.16
0.6, 0.36
0.8, 0.64
1.0, 1.00

我半信半疑地认为问题取决于我正在使用的包,因此我包含了来自的输出\listfiles

pstricks.sty      2013/12/12 v0.60
pstricks.tex      2014/10/25 v2.60
pst-xkey.tex      2005/11/25 v1.6
pst-fp.tex        2014/10/25 v2.60
pstricks-add.sty  2010/02/11 v.0.14
pst-plot.sty      2011/04/13
pst-xkey.sty      2005/11/25 v1.6
pst-plot.tex      2014/08/23 1.70
pst-node.sty      2010/04/22
pst-node.tex      2014/08/04 1.35
pstricks-add.tex  2014/12/08 v3.77
pstricks-add.cfg  2005/01/10 v0.1

最后,我附上了两张说明该问题的图片:

  1. 带有行尾注释
    带有行尾注释
    (来源:北师大新闻网

  2. 没有行尾注释
    没有行尾注释
    (来源:北师大新闻网

答案1

这是的具体问题standalone。你可以看看行末百分号(%)有什么用?以便理解接下来的内容。

默认情况下,在水平框(本质上)中standalone排版环境中的文本,以便稍后裁剪。document\mbox

在水平框中,空格很重要,因此必须隐藏行尾,%以免它们转换为空格。

在普通文档中,比如说\documentclassarticle`,你不会看到这些空格,因为当 TeX 尚未开始段落时就会看到它们。

所以

\documentclass{standalone}
\usepackage{pstricks}
\usepackage{pstricks-add}
\usepackage{pst-plot}
\begin{document}
\readdata{\mytable}{table.txt}%  <-- NB!
\pstScalePoints(1.0,1.0){1.0 div}{1.0 div}%  <-- NB!
\newpsstyle{legendstyle}{fillstyle=solid}%   <-- NB!
\begin{psgraph}(0,0)(0,0)(1,1){1cm}{1cm}
\listplot{\mytable}
\end{psgraph}
\end{document}

另一方面,

\documentclass{article}
\usepackage{pstricks}
\usepackage{pstricks-add}
\usepackage{pst-plot}
\begin{document}

\readdata{\mytable}{table.txt}  
\pstScalePoints(1.0,1.0){1.0 div}{1.0 div}
\newpsstyle{legendstyle}{fillstyle=solid}

\begin{psgraph}(0,0)(0,0)(1,1){1cm}{1cm}
\listplot{\mytable}
\end{psgraph}

\end{document}

不需要,%因为该段落以 开头\begin{psgraph}

如果您发现自己做了很多这样的%添加,您可以考虑在文档中添加一些内容:

\documentclass[varwidth]{standalone}
\usepackage{pstricks}
\usepackage{pstricks-add}
\usepackage{pst-plot}

\newcommand{\startsetup}{%
  \chardef\oldendlinechar\endlinechar
  \endlinechar=-1
}
\newcommand{\stopsetup}{\endlinechar=\oldendlinechar}

\begin{document}

\startsetup
\readdata{\mytable}{table.txt}
\pstScalePoints(1.0,1.0){1.0 div}{1.0 div}
\newpsstyle{legendstyle}{fillstyle=solid}
\stopsetup

\begin{psgraph}(0,0)(0,0)(1,1){1cm}{1cm}
\listplot{\mytable}
\end{psgraph}
\end{document}

相关内容