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:

enter image description here

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

enter image description here



\setlength{\parindent}{0pt}% Just for this example



\clipbox{0 0 0 \dimexpr\height-10pt}{\includegraphics[width=\linewidth]{colour_gradient}}


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.

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.