\color 导致图片环境中发生位移

\color 导致图片环境中发生位移

当我在以下 LaTeX 代码环境\color中使用时,是什么原因导致位移?我该如何防止它们?picture

LaTeX 代码:

\documentclass{article}
\usepackage{xcolor}
\usepackage{multido}
\usepackage{pict2e}
\def\Color#1{\color{#1}}
\def\Color#1{}
\def\picgrid(#1,#2)(#3,#4){%
  \multido{\ix=#1+1}{#3}{%
    \put(\ix,#2){%
      \multido{\rx=0.2+0.2}{4}{%
        {%
          \thinlines%
          \Color{yellow}%
          \put(\rx,0){%
            \line(0,1){#4}%
          }%
        }%
      }%
      {%
        \thicklines%
        \Color{green}%
        \line(0,1){#4}%
      }%
    }%
  }%
  \multido{\iy=#1+1}{#4}{%
    \put(#1,\iy){%
      \multido{%
        \ry=0.2+0.2}{4}{%
        {%
          \thinlines%
          \Color{yellow}%
          \put(0,\ry){%
            \line(1,0){#3}%
          }%
        }%
      }%
      {%
        \thicklines%
        \Color{green}%
        \line(1,0){#3}%
      }%
    }%
  }%
}
\begin{document}
\begin{figure}
\unitlength1cm
\begin{picture}(10,10)(-5,-5)
\picgrid(-5,-5)(10,10)
\put(-5,0){\vector(1,0){10}}
\put(0,-5){\vector(0,1){10}}
{\Color{red}%
  \qbezier(-5,-4)(0,-4)(1,0)\qbezier(1,0)(2,4)(5,4)
  \thicklines\put(1.5,1.5){\vector(0.4,0.8){0.5}}
}
{\Color{blue}%
\qbezier(5,4)(0,4)(-1,0)\qbezier(-1,0)(-2,-4)(-5,-4)}
\thicklines\put(1.5,1.5){\line(0,1){1.8}}
\end{picture}
\end{figure}
\end{document}

未修改代码的渲染结果:

pdflatex 使用未修改的代码渲染结果

\Color注释掉第2个定义的渲染结果:

pdflatex 渲染结果带有注释的第二种颜色定义

人们可以很容易地识别出垂直线相对于下曲线的偏移。

系统信息:

$ latex -v
pdfTeX 3.14159265-2.6-1.40.18 (TeX Live 2017/Debian)
kpathsea version 6.2.3
Copyright 2017 Han The Thanh (pdfTeX) et al.
There is NO warranty.  Redistribution of this software is
covered by the terms of both the pdfTeX copyright and
the Lesser GNU General Public License.
For more information about these matters, see the file
named COPYING and the pdfTeX source.
Primary author of pdfTeX: Han The Thanh (pdfTeX) et al.
Compiled with libpng 1.6.34; using libpng 1.6.34
Compiled with zlib 1.2.11; using zlib 1.2.11
Compiled with poppler version 0.62.0

答案1

您内部团体的使用picture似乎引入了虚假的空间:

% ...previous document definitions/content
\begin{picture}(10,10)(-5,-5)
  \picgrid(-5,-5)(10,10)
  \put(-5,0){\vector(1,0){10}}
  \put(0,-5){\vector(0,1){10}}
  {\Color{red}%
    \qbezier(-5,-4)(0,-4)(1,0)\qbezier(1,0)(2,4)(5,4)
    \thicklines\put(1.5,1.5){\vector(0.4,0.8){0.5}}
  }% <------------------------------------------------------ Removed spurious space
  {\Color{blue}%
    \qbezier(5,4)(0,4)(-1,0)\qbezier(-1,0)(-2,-4)(-5,-4)}
    \thicklines\put(1.5,1.5){\line(0,1){1.8}}
\end{picture}

答案2

您需要让命令忽略空格:

\def\Color#1{\unskip\color{#1}\ignorespaces}

相关内容