1

I'm trying to print out a series of colour boxes, using the wave option of xcolor.

The result should be a (long) series of color boxes (possibly, but not necessarily) on two columns, which differ from each other by a constant value (I mean whose whavelength is incremented by a constant value).

My proto-code currently looks like:

 \documentclass{article}
 \usepackage{xcolor}
 \begin{document}
 \colorbox[wave]{363}{ \ \strut   } 363\\
 \colorbox[wave]{368}{ \ \strut   } 368\\

 ...
 \end{document}

But I was tired before reaching the end of the spectrum.

How is it possible to obtain the result in which the wavelength (and the number printed afterwards) are discretely incremented (and whose increment is configurable?

Thanks.

Just to clarify: this question is about loops, not colors per se: I'm fine with the output of xcolor

2

This way?

\documentclass{article}
\usepackage{xcolor}
\usepackage{pgffor}
\begin{document}
\noindent
\foreach \lambda in {363,368,373,...,763} {\colorbox[wave]{\lambda}{ \ \strut } \lambda\\}
\end{document}
  • 1
    if you are not drawing then \usepackage{pgffor} is enough. Otherwise TikZ already loads xcolor – percusse Mar 30 '17 at 10:07
  • @ percusse: Thanks for the hint. I will modify my answer. – Jürgen Mar 30 '17 at 10:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.