# Color influences layout?

To verify a layout template, I use eso-pic. In this example, all boxes should start at 20mm from the left, but as soon as I use \color...put \color...put the X-coordinates of the boxes are deferred.

%\documentclass[]{letter} same
\documentclass[]{scrlttr2}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage{picture,eso-pic}
\setlength\fboxsep{0pt}

\multiput(20mm,0)(0,-.01\paperheight){100}{\line(0,-1){.005\paperheight}}
\put(20mm,-85mm){\colorbox{red!25}{\framebox(30mm,10mm){A}}}
\put(20mm,-100mm){\colorbox{blue!25}{\framebox(30mm,10mm){B}}}
\color{lightgray}{\put(20mm,-65mm){\colorbox{green!25}{\framebox(30mm,10mm){C}}}}
\color{red}{\put(20mm,-50mm){\colorbox{pink!25}{\framebox(30mm,10mm){D}}}} % 2 following rows with color break X coord.
\put(20mm,-35mm){\colorbox{yellow!25}{\framebox(30mm,10mm){E}}}
}}

\begin{document}
\begin{letter}{To} \opening{Hi,}
\textbf{ALL} boxes should start at 20mm from the left side \closing{bye} \end{letter}
\end{document}


How do I fix this?

Removing \color{red} fixes the problem in this example.

--
As a follow up question: I created my own commands to ease control over which standard should be drawn with its corresponding color. Sadly, they silently mess up layout, too. The lines work fine, but succeeding boxes are deferred.

How can I fix that and still avoid redundancy and maintain abstraction?

\documentclass[]{scrlttr2}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage{picture,eso-pic,etoolbox}
\setlength\fboxsep{0pt}

\newtoggle{printA}
\toggletrue{printA}
\newcommand \colorA {red}
\newcommand \printA [1]{\iftoggle{printA}{{\color{\colorA}{#1}}}{}}

\put(20mm,-85mm){\colorbox{yellow!25}{\framebox(30mm,10mm){A}}}
\printA{\multiput(20mm,0)(0,-.01\paperheight){100}{\line(0,-1){.005\paperheight}}}
\printA{\multiput(25mm,0)(0,-.01\paperheight){100}{\line(0,-1){.005\paperheight}}}
\put(20mm,-100mm){\colorbox{blue!25}{\framebox(30mm,10mm){B}}}
}}

\begin{document}
\begin{letter}{To} \opening{Hi,}
\textbf{ALL} boxes should start at 20mm from the left side \closing{bye} \end{letter}
\end{document}


I really do feel lost in latex regarding determinism of my code! Is there anything I can do to ensure color doesn't has any side-effects or in other words doesn't silently messes up the layout?

• There is a box indent with each box. Add \hspace*{-.3333em} before the colorbox – percusse Mar 26 '13 at 19:32
• @percusse you should recognise that amount: It is not a box (or indentation) it is a word space. – David Carlisle Mar 26 '13 at 21:06

Put the \color in a safer place, inside the \put, not before it. The thing to note about \color affecting position is that it is not my fault.

An alternative (more suitable for your edited question) is to make your \printA command act like other picture mode commands and remove white space around them. The extra space is in fact an inter-word space coming from the end of lines in your source code (so an alternative would be to use % at the end of each line). \put normally removes any white space that has crept in by issuing \unskip but the \color command inserts a whatsit node after the white space which prevents \unskip working. This definition makes \printA itself remove preceding white space and ignore following white space.

\newcommand \printA [1]{%
\ifhmode\unskip\fi
\iftoggle{printA}{{\color{\colorA}{#1}}}{}%
\ignorespaces}


\documentclass[]{scrlttr2}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage{picture,eso-pic}
\setlength\fboxsep{0pt}

\multiput(20mm,0)(0,-.01\paperheight){100}{\line(0,-1){.005\paperheight}}
\put(20mm,-85mm){\colorbox{red!25}{\framebox(30mm,10mm){A}}}
\put(20mm,-100mm){\colorbox{blue!25}{\framebox(30mm,10mm){B}}}
\put(20mm,-65mm){\color{lightgray}\colorbox{green!25}{\framebox(30mm,10mm){C}}}
\put(20mm,-50mm){\color{red}\colorbox{pink!25}{\framebox(30mm,10mm){D}}} % 2 following rows with color break X coord.
\put(20mm,-35mm){\colorbox{yellow!25}{\framebox(30mm,10mm){E}}}
}}

\begin{document}
\begin{letter}{To} \opening{Hi,}
\textbf{ALL} boxes should start at 20mm from the left side \closing{bye} \end{letter}
\end{document}

• as a follow up question: I created own commands to ease control over which standard should be drawn with its corresponding color. Sadly, they mess up layout, too. How can I fix them? \newcommand \printA [1]{\iftoggle{printA}{\color{\colorA}{#1}}{}}. I really do feel lost in latex regarding determinism of my code :| – Stefan K. Mar 26 '13 at 20:58
• If possible use \textcolor rather than \color it has more predicatable effects See grfguide documentation in the core dostribution where I give some warnings about color. – David Carlisle Mar 26 '13 at 21:05
• I can't use \textcolor. I extended my question above. – Stefan K. Mar 27 '13 at 10:56
• @StefanK. Updated answer. – David Carlisle Mar 27 '13 at 11:55