4

In PSTricks, the following code:

\documentclass{article}
\usepackage[usenames]{pstcol}
\usepackage{pst-plot}
\usepackage{pst-grad}

\begin{document}

\noindent
\psshadowbox[linecolor=Green,framearc=0.5,linewidth=0.3pt,fillstyle=gradient,
gradbegin=ForestGreen, gradend=GreenYellow,framesep=5pt,
shadowcolor=SpringGreen,
gradmidpoint=1]%{$\mathcal{P}_{113}$}\\[2.9cm]
{\huge{\textbf{P 113}}}\\
\psshadowbox[linecolor=Green,framearc=0.5,linewidth=0.3pt,fillstyle=gradient,
gradbegin=ForestGreen, gradend=GreenYellow,framesep=5pt,
shadowcolor=SpringGreen,
gradmidpoint=1]%{$\mathcal{P}_{113}$}\\[2.9cm]
{\Large{\textbf{P 113}}}\\

\end{document}

generates the following figure (300% zoom):

enter image description here

Is there any way to make the same figure with TikZ? I found a template with which I could do something similar, but with fixed width:

\documentclass[svgnames]{article}
\usepackage{tikz}
\usepackage{array}
\usetikzlibrary{shadows}
\newcommand{\pbox}[4]{%
  \begin{tikzpicture}
    \node[#3] {\begin{minipage}[t][#2][t]{#1}%
      #4
    \end{minipage}};
  \end{tikzpicture}}

\begin{document}

\pbox{0.21 \textwidth}{}{rectangle,drop shadow, fill=Red,rounded corners=5pt,inner sep=6pt, 
shade,top color=ForestGreen, bottom color=GreenYellow, draw=Green}
{\centering{\Huge{\textbf{P 113}}}}
\pbox{0.13 \textwidth}{}{rectangle,drop shadow, fill=Red,rounded corners=5pt,inner sep=6pt,
             shade,top color=ForestGreen, bottom color=GreenYellow, draw=Green}
             {\centering{\Large{\textbf{P 113}}}}

 \end{document}

enter image description here

What I want is that the width of the box to automatically adapt the text (as with \psshadowbox) without having to vary the fraction \textwidth individually. On the other hand, I would change the color of the shadow made with TikZ to be the most similar to done with PSTricks block.

3

By default, the width of a TikZ \node is the natural width of its contents plus some inner sep padding on both sides, so basically all you had to do was to get rid of the minipage:

\documentclass[svgnames]{article}
\usepackage{tikz}
\usetikzlibrary{shadows}

\definecolor{topColor}{RGB}{0,250,0}
\definecolor{botColor}{RGB}{170,255,46}
\definecolor{shaColor}{RGB}{180,234,90}

\tikzset{
mybox/.style={
  rectangle,
  drop shadow, 
  rounded corners=5pt,
  inner sep=6pt,
  draw=topColor,
  shade,
  top color=topColor, 
  every shadow/.append style={fill=shaColor}, 
  bottom color=botColor, 
  draw=Green
  }
}

\begin{document}

\begin{tikzpicture}
\node[mybox]
  {\Huge\textbf{P 113}};
\node[mybox] at (0,2)
  {Some other longer test};
\end{tikzpicture}

\end{document}

enter image description here

Or, defining a command:

\documentclass[svgnames]{article}
\usepackage{tikz}
\usetikzlibrary{shadows}

\definecolor{topColor}{RGB}{0,250,0}
\definecolor{botColor}{RGB}{170,255,46}
\definecolor{shaColor}{RGB}{180,234,90}

\tikzset{
mybox/.style={
  rectangle,
  drop shadow, 
  rounded corners=5pt,
  inner sep=6pt,
  draw=topColor,
  shade,
  top color=topColor,
  every shadow/.append style={fill=shaColor}, 
  bottom color=botColor, 
  draw=Green
  }
}

\newcommand\MyBox[2][]{%
  \tikz\node[mybox,#1] {#2}; 
}

\begin{document}

\MyBox{\Huge\textbf{P 113}}\par\medskip
\MyBox{Some other longer test}

\end{document}

enter image description here

By the way, \Huge is not a command with arguments; it's a font switch to be used as in {\Huge <text>} or {\Huge <text>\par}, if required.

|improve this answer|||||

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.