我有以下内容章节图像命令,基于本书模板(Jenny Lantair 撰写的 ILM 报告)我仅通过这一行代码来使用它:\chapterimage{./res/headers/nature.jpg}
。
\newcommand{\thechapterimage}{}
\newcommand{\chapterimage}[1]{\renewcommand{\thechapterimage}{#1}}
\def\thechapter{\arabic{chapter}}
\def\@makechapterhead#1{
\thispagestyle{empty}
{\centering
\ifnum \c@secnumdepth >\m@ne
\if@mainmatter
\startcontents
\begin{tikzpicture}[remember picture,overlay]
\node at (current page.north west)
{\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north west,inner sep=0pt] at (0,0) {\includegraphics[width=\paperwidth]{\thechapterimage}};
\draw[anchor=west] (16cm,-25px) node [fill=white!10!white,text opacity=1,draw=white,draw opacity=1,line width=1pt,fill opacity=.6,inner sep=12pt]{\huge\bfseries\textcolor{black}{#1\strut\makebox[22cm]{}}};
\end{tikzpicture}};
\end{tikzpicture}}
\par\vspace*{180\p@}
\fi
\fi}
它运行良好,例如当我使用时:
\chapterimage{./res/headers/nature.jpg}
\chapter{Intakte Natur}
它输出:
我的问题:目前章节标题后面的白色框的不透明度设置为0.6当我将其设置为例如0.8它将全局应用。我如何通过不透明度参数来扩展它,即:\chapterimage[0.8]{./res/headers/nature.jpg}
?我希望能够将某些(不是全部)章节的不透明度设置为单个值(而不是0.6)。
答案1
也许这个方法可以解决问题:
\newcommand\MyExchange[2]{#2#1}%
\newcommand{\MyOpacity}{}
\newcommand{\thechapterimage}{}
\newcommand{\chapterimage}[2][0.6]{%
\edef\MyOpacity{\unexpanded{#1}}%
\edef\thechapterimage{\unexpanded{#2}}%
}
\def\thechapter{\arabic{chapter}}
\def\@makechapterhead#1{%
\thispagestyle{empty}%
{\centering
\ifnum \c@secnumdepth >\m@ne
\if@mainmatter
\startcontents
\begin{tikzpicture}[remember picture,overlay]
\node at (current page.north west)
{\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north west,inner sep=0pt] at (0,0) {\includegraphics[width=\paperwidth]{\thechapterimage}};
\expandafter\MyExchange
\expandafter{\MyOpacity}{%
\draw[anchor=west] (16cm,-25px) node [fill=white!10!white,text opacity=1,draw=white,draw opacity=1,line width=1pt,fill opacity=%
},inner sep=12pt]{\huge\bfseries\textcolor{black}{#1\strut\makebox[22cm]{}}};
\end{tikzpicture}};
\end{tikzpicture}}%
\par\vspace*{180\p@}%
\fi
\fi}
...
\chapterimage[0.8]{./res/headers/nature.jpg}
\chapter{Intakte Natur}
如果您还想更改“填充不透明度”键以外的键的值:
\newcommand\MyExchange[2]{#2#1}%
\newcommand{\MyMoreKeyVals}{}
\newcommand{\thechapterimage}{}
\newcommand{\chapterimage}[2][]{%
\edef\MyMoreKeyVals{\unexpanded{#1}}%
\edef\thechapterimage{\unexpanded{#2}}%
}
\def\thechapter{\arabic{chapter}}
\def\@makechapterhead#1{%
\thispagestyle{empty}%
{\centering
\ifnum \c@secnumdepth >\m@ne
\if@mainmatter
\startcontents
\begin{tikzpicture}[remember picture,overlay]
\node at (current page.north west)
{\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north west,inner sep=0pt] at (0,0) {\includegraphics[width=\paperwidth]{\thechapterimage}};
\expandafter\MyExchange
\expandafter{\MyMoreKeyVals}{%
\draw[anchor=west] (16cm,-25px) node [fill=white!10!white,text opacity=1,draw=white,draw opacity=1,line width=1pt,fill opacity=.6,inner sep=12pt,%
}]{\huge\bfseries\textcolor{black}{#1\strut\makebox[22cm]{}}};
\end{tikzpicture}};
\end{tikzpicture}}%
\par\vspace*{180\p@}%
\fi
\fi}
...
\chapterimage[fill opacity=0.8]{./res/headers/nature.jpg}
\chapter{Intakte Natur}
这是未经测试的,因为您没有提供足够的代码/上下文进行测试。