# \color causes displacement in picture environment

What causes the displacements when I use \color in a picture environment as in the LaTeX code below? How can I prevent them?

The LaTeX code:

\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}


The rendered result with the unmodified code:

The rendered result with the 2nd definition of \Color commented out:

One easily recognizes the offset of the vertical line w.r.t. the lower curve.

System information:

\$ 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.
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

• You have a spurious space between the two groups within the picture environment.
– Werner
Jan 6, 2020 at 7:14
• @Werner: Please convert your comment into an answer. It qualifies as one and it may help others. I would like to up-vote it to indicate that it is a valid solution. If I insert a comment character behind the lonely } inside the picture environment the displacements are gone. I was not aware that a linebreak counts as space at that place. (I know that whitespace at the beginning of line is ignored and that one can comment-out lineends.) Jan 6, 2020 at 8:26
• @Tobias note that your line ends after \put and other picture mode commands do not cause any displacement as picture mode commands all use \unskip to remove space before and\ignorespaces to avoid adding space after. Jan 6, 2020 at 9:04
• @Tobias: I've converted my comment as a possible answer to your question.
– Werner
Jan 6, 2020 at 17:43

The use of groups within your picture seem to have introduced a spurious space:

% ...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}


You need to make the command ignore white space:

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

• Thank you. This works and it is clearly worth an up-vote. But, it does not as directly indicate the problem as Werner's comment. So I would like to accept his comment when he converts it to an answer. Jan 6, 2020 at 8:30
• Hm, on the second thought: It is very remarkable that only the \color command sequence shows this problem. If I replace it with an empty command sequence the problem is gone. Damn, I would really like to accept two answers;-). Maybe, we should add Werner's comment and my remedy to this answer and accept it. @Werner, are you fine with that solution? Jan 6, 2020 at 8:37
• @Tobias it's not at all surprising, all the other commands you are using are designed for picture mode and they already use \unskip/\ignorespaces in this way. The empty command does not introduce a node so does not interfere with \unskip Jan 6, 2020 at 9:00
• Thanks for the explanations. As I already mentioned I actually want to accept your answer and Werner's answer. Since yours is already promoted by a lot of up-votes I finally accepted Werners answer. So both answers get the due attention. Hope you are fine with that. Jan 6, 2020 at 18:44
• @Tobias Werner and I each have more than enough points not to worry too much about where the +15 goes:-) But for future readers I would say that this is the more correct answer. You don't need to put % at ends of lines in picture mode precisely because all the picture mode commands use \unskip and \ignorespaces so white space is ignored so it is better to introduce a new command in the same style than not do that and then have to comment out just one of the many space tokens from ends of lines in the environment. Jan 6, 2020 at 19:14