# Is it possible to use a color gradient as the color of the \rule command?

I have an image which is just colors in a gradient pattern and I would like to apply this pattern to the \rule command instead of just choosing one color for it. Is it possible to use an image as the color of the rule? Like if the rule was a stripe cut off from the image.

• You could include the image itself with an appropriate crop value to only select the colour gradient. – Werner Dec 5 '16 at 19:23

Let's assume this is your image and call it colour_gradient.png:

You can crop out a portion of this image and use it as a rule in your document:

\documentclass{article}


The above example sets a \rule of width 10pt. Using \clipbox from the adjustbox package, we clip the bottom 10pt from colour_gradient.png so that it resembles the colour gradient of the actual image. Depending on the layout of the image, you'll have to play around with the clipping dimensions.