How to create text with shadows?
Sorry for the shameless self-advertising, but I once wrote a small package for drop shadows which is now available on CTAN; it's called shadowbox
. This package works with pdflatex.
A somewhat long MWE:
\documentclass{article}
\usepackage{shadowbox}
\usepackage{multicol}
%
\begin{document}
%
\setshadowoffset{1pt}
\begin{minipage}{\textwidth}
\begin{multicols*}{2}
{\footnotesize
\begin{verbatim}
\shadowbox{This is a shadowbox}
\end{verbatim}}
\shadowbox{This is a shadowbox}
\end{multicols*}
\end{minipage}
%
\section{Changing the position of the shadow}
%
\begin{minipage}{\textwidth}
\begin{multicols*}{2}
{\footnotesize
\begin{verbatim}
\setshadowoffset{2pt}
\shadowbox{This is a shadowbox}
\end{verbatim}}
%
\setshadowoffset{2pt}
\shadowbox{This is a shadowbox}
\end{multicols*}
\end{minipage}
%
\begin{minipage}{\textwidth}
\begin{multicols*}{2}
{\footnotesize
\begin{verbatim}
\shadowoffsetx=1pt
\shadowoffsety=4pt
\shadowbox{This is a shadowbox}
\end{verbatim}}
%
\shadowoffsetx=1pt
\shadowoffsety=4pt
\shadowbox{This is a shadowbox}\\
\phantom{}
\end{multicols*}
\end{minipage}
%
\section{Changing the color of the shadow}
%
\begin{minipage}{\textwidth}
\begin{multicols*}{2}
{\footnotesize
\begin{verbatim}
\setshadowoffset{2pt}
\setshadowcolor{0.66, 0.66, 1}
\shadowbox{This is a shadowbox}
\end{verbatim}}
%
\setshadowoffset{2pt}
\setshadowcolor{0.66, 0.66, 1}
\shadowbox{This is a shadowbox}\\
\phantom{}
\end{multicols*}
\end{minipage}
%
\section{More examples}
The following code illustrates how to use shadowbox in more interesting settings:
%
\definecolor{navy}{rgb}{0,0,0.5}
%
\begin{minipage}{\textwidth}
\begin{multicols*}{2}
{\footnotesize
\begin{verbatim}
\definecolor{navy}{rgb}{0,0,0.5}
\color{navy}
\setshadowoffset{1pt}
\shadowbox{
\fontsize{16}{16}\selectfont
Large!}
\end{verbatim}}
%
\color{navy}
\setshadowcolor{0.8, 0.8, 1}
\setshadowoffset{2pt}
\shadowbox{\fontsize{16}{16}\selectfont \textbf{Large!}}\\
\phantom{}\\
\phantom{}
\end{multicols*}
\end{minipage}
%
\color{black}
\begin{minipage}{\textwidth}
\begin{multicols*}{2}
{\footnotesize
\begin{verbatim}
\setshadowoffset{1pt}
\color{black}
\shadowbox{%
\begin{tabular}{|l|l|}
\hline
1 & 2 \\
3 & 4 \\
\hline
\end{tabular}
}
\end{verbatim}}
%
\setshadowoffset{1pt}
\shadowbox{%
\begin{tabular}{|l|l|}
\hline
1 & 2 \\
3 & 4 \\
\hline
\end{tabular}
}
\phantom{}\\
\phantom{}\\
\phantom{}\\
\phantom{}\\
\phantom{}\\
\phantom{}
\end{multicols*}
(Notice the percent sign right after the shadowbox command. This is necessary!)
\end{minipage}
%
\begin{minipage}{\textwidth}
\begin{multicols*}{2}
{\footnotesize
\begin{verbatim}
\setshadowoffset{1pt}
\shadowbox{$\sqrt{2\pi}e^{-n}$}
\end{verbatim}}
\setshadowoffset{1pt}
\shadowbox{$\sqrt{2\pi}e^{-n}$}\\
\phantom{}
\end{multicols*}
\end{minipage}
%
\color{black}
%
\begin{minipage}{\textwidth}
\begin{multicols*}{2}
{\footnotesize
\begin{verbatim}
\color{navy}
\setshadowoffset{2pt}
\shadowbox{%
\fontencoding{T1}%
\fontfamily{pag}%
\fontseries{b}%
\fontsize{32}{32}%
\selectfont%
Section \arabic{section}%
}
\end{verbatim}}
%
\color{navy}%
\setshadowoffset{2pt}%
\shadowbox{%
\fontencoding{T1}%
\fontfamily{pag}%
\fontseries{b}%
\fontsize{32}{32}%
\selectfont%
Section \arabic{section}%
}
\phantom{}\\
\phantom{}\\
\phantom{}\\
\phantom{}\\
\end{multicols*}
\end{minipage}
%
\end{document}
The reason your code doesn't compile is because it uses PSTricks and you are trying to compile it with pdflatex
. PSTricks code uses Postcript commands that cannot be interpreted by pdflatex
, so you need to compile it using the sequence of latex
+ dvips
+ ps2pdf
.
Depending on your editor, there are different ways to do this. Since you are using a Mac, I'll outline how to do it in both TeXShop and TeXworks.
TeXworks
TeXworks is not set up to be able to compile with latex+dvips
by default, so you first need to add to its preferences to create a "latex" compilation command. See this question for how to do that:
configure latexmk in Texworks 0.2.3
Once you've done this, you can choose "latex" instead of "pdfLaTeX" from the dropdown menu in the document window.
Alternatively, you can put
% !TeX program = latex
as the first line of your file.
TeXShop
In TeXShop, you need to choose "TeX and DVI" from the Typeset menu instead of "pdfTeX".
Alternatively, you can put
% !TEX TS-program = latex
as the first line of your file.
Unlike some other answers, the result is not in a box, and so it can work across line-breaks, paragraph breaks, and page breaks.
In that sense, it is somewhat like Karl's answer. But unlike Karl's answer, it can be interspersed with normal text on a word by word basis. Ligatures are, however, lost.
The settable options are:
\setlength\shadowHoffset{.3pt}
\setlength\shadowVoffset{-.2pt}
\def\primarycolor{white}
\def\secondarycolor{black}
Here is the MWE:
\documentclass{article}
\usepackage{stackengine,xcolor}
\newcommand\shadowfy[1]{\expandafter\shadowfypars#1\par\relax\relax}
\long\def\shadowfypars#1\par#2\relax{%
\ifx#1\relax\else
\shadowfywords#1 \relax\relax%
\fi%
\ifx\relax#2\else\par\shadowfypars#2\relax\fi%
}
\def\shadowfywords#1 #2\relax{%
\ifx#1\relax\else
\shadowfyletters#1\relax\relax%
\fi%
\ifx\relax#2\else\ \shadowfywords#2\relax\fi%
}
\def\shadowfyletters#1#2\relax{%
\shadow{#1}%
\ifx\relax#2\else\shadowfyletters#2\relax\fi}
\newlength\shadowHoffset
\newlength\shadowVoffset
\setlength\shadowHoffset{.3pt}
\setlength\shadowVoffset{-.2pt}
\def\primarycolor{white}
\def\secondarycolor{black}
\def\shadow#1{\kern\shadowHoffset%
\raisebox{\shadowVoffset}{%
\stackinset{c}{-\shadowHoffset}{c}{-\shadowVoffset}%
{\textcolor{\primarycolor}{#1}}{\textcolor{\secondarycolor}{#1}}}%
\kern-\shadowHoffset}
\begin{document}
\def\mytext{%
Problem is, there doesn't appear any shadow next to the text. Any idea how to
setup shadows to a string on a way that really works?
And for my second paragraph, the problem is, there doesn't appear any shadow
next to the text. Any idea how to setup shadows to a string on a way that
really works?
}%
\shadowfy{\mytext}
\def\primarycolor{black}%
\def\secondarycolor{black!30}%
\setlength\shadowHoffset{.3pt}
\setlength\shadowVoffset{-.3pt}
\shadowfy{\mytext}
\def\shadowVoffset{-1pt}%
And it should line up with text: \shadowfy{\mytext}
\LARGE\sffamily%
\def\primarycolor{blue!70!black}%
\def\secondarycolor{cyan!25}%
\def\shadowHoffset{.5pt}%
\def\shadowVoffset{-.8pt}%
And color: \shadowfy{\mytext}
\end{document}
Here is somewhat of a zoom on the result:
Here I demonstrate line and paragraph breaking.
Here is a mid-line transition from normal to shadow text, exaggerated shadowing to demonstrate that the primary baselines line up.
And here is color: