在PSTricks中,以下代码:
\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}
生成下图(300%缩放):
有没有办法用 TikZ 制作相同的图形?我找到了一个模板,可以做类似的事情,但宽度固定:
\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}
我想要的是框的宽度能够自动适应文本(就像 一样\psshadowbox
),而不必\textwidth
单独改变分数。另一方面,我会将使用 TikZ 制作的阴影的颜色更改为与使用 PSTricks 块制作的颜色最相似。
答案1
默认情况下,TikZ 的宽度\node
是其内容的自然宽度加上inner sep
两侧的一些填充,因此基本上您所要做的就是摆脱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}
或者,定义一个命令:
\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}
顺便一提,\Huge
,不是带有参数的命令;如果需要,它是一个可用作 {\Huge <text>}
或的字体开关。{\Huge <text>\par}