我想创建一个按钮并更改其背景颜色。这可行吗?如何做?
这是我的 MWE:
\documentclass[a4paper, 12pt]{article}
\usepackage{xcolor}
\usepackage{hyperref}
\begin{document}
\begin{Form}
\PushButton[
name=additem,
borderwidth=0.5pt,
bordercolor=blue,
backgroundcolor=red % why doesn't this work ?
]{\textcolor{blue}{Add an item}}
\end{Form}
\end{document}
答案1
hyperref 不包含在此处设置背景颜色的代码。理论上可以添加它,但它的副作用是覆盖按钮上的文本。我建议改用颜色框:
\documentclass[a4paper, 12pt]{article}
\usepackage{xcolor}
\usepackage{hyperref}
\usepackage{etoolbox}
\begin{document}
\begin{Form}
{ % not so good ...
\makeatletter
\patchcmd\PDFForm@Push{/BC[\Fld@bordercolor]}{/BC[\Fld@bordercolor]/BG[\Fld@bcolor]}{}{\fail}
\PushButton[
name=additem,
borderwidth=0.5pt,
bordercolor=blue,
backgroundcolor=red,
]{\textcolor{blue}{\strut Add an item}}
}
\bigskip
\fboxsep=0pt
\colorbox{red}{%
\PushButton[
name=additem,
borderwidth=0.5pt,
bordercolor=blue,
]{\textcolor{blue}{\strut Add an item}}}
\end{Form}
\end{document}