How to add shadow to text in LaTeX
In this tutorial, we will learn how to add shadow to text in LaTeX.
I will go with the very basic and then I will show you how to customize the shadow as well.
Add shadow to text using shadowtext package in LaTeX
\documentclass{article} \usepackage{shadowtext} \begin{document} \shadowtext{CodeSpeedy is helpful for LaTeX} \end{document}
Output:
If you look carefully, you can see that the position of the text is not fixed well, thus the shadows are not looking good at all.
To fix this, we can use textpos
package.
\documentclass{article} \usepackage[absolute,overlay]{textpos} \usepackage{shadowtext} \begin{document} \begin{textblock*}{5cm}(1cm,1cm) \shadowtext{Your shadowed text here} \end{textblock*} \end{document}
Output:
Here {5cm}
is the width of the text and (1cm,1cm)
are the coordinates of the text.
You can adjust it according to your document.
Add color to shadowed text in \shadowtext
\shadowrgb{2.0,0.5,0.7}
We can change the color easily with the above command if you want to deal with RGB color codes.
Or you can follow the below:
We can use \shadowcolor
command with xcolor
package to make the shadow colored.
\documentclass{article} \usepackage[absolute,overlay]{textpos} \usepackage{xcolor} \usepackage{shadowtext} \begin{document} \begin{textblock*}{5cm}(1cm,1cm) \shadowcolor{red} % Set the shadow color \shadowtext{Your shadowed text here} \end{textblock*} \end{document}
Output:
Change font color and shadow color both in LaTeX
\documentclass{article} \usepackage[absolute,overlay]{textpos} \usepackage{xcolor} \usepackage{shadowtext} \begin{document} \begin{textblock*}{5cm}(1cm,1cm) \shadowcolor{red} % Set the shadow color \shadowtext{\textcolor{green}{Your shadowed text here}} \end{textblock*} \end{document}
Output:
Change the position of shadow in \shadowtext
We can use \shadowoffset{}
command to change the position of the shadow.
\documentclass{article} \usepackage[absolute,overlay]{textpos} \usepackage{xcolor} \usepackage{shadowtext} \begin{document} \begin{textblock*}{5cm}(1cm,1cm) \shadowoffset{3pt} \shadowtext{Your shadowed text here} \end{textblock*} \end{document}
Output:
If we wish we can have more control over this offset with the below commands:
\shadowoffsetx{1pt} \shadowoffsety{3pt} \shadowtext{This is codespeedy}
It will change the position by using x and y axis pts.
Leave a Reply