Tikz を使用して章タイトルオーバーレイのさまざまな画像用のマクロを作成する

Tikz を使用して章タイトルオーバーレイのさまざまな画像用のマクロを作成する

章の画像オーバーレイを作成したいと思います。これまでのところ、このコードを見つけましたが、定義で画像を直接指定すると機能します。

\newcommand\chapterlabel{}
\titleformat{\chapter}
  {\gdef\chapterlabel{}
   \normalfont\sffamily\Huge\bfseries\scshape}
  {\gdef\chapterlabel{\thechapter\ }}{0pt}
  {\begin{tikzpicture}[remember picture,overlay]
    \node[below right=4.8cm and 0cm of current page.north east] (a)
      {\begin{tikzpicture}[remember picture, overlay]
        \fill[fill overzoom image=
!!!!!!!!!!!!HERE IS THE IMAGE NAME!!!!!!!!!!!!!!
]
 (current page.north west) rectangle
          (a);
        \node[below right=2.5cm and 2cm of current page.north
     west,color=blue]
              {\color{white}\chapterlabel#1};
       \end{tikzpicture}
      };
   \end{tikzpicture}
  }

しかし、マクロとして作成する方法がわかりません。つまり、画像の名前にプレースホルダーとして「#2」を入れて、後で引数としてカスタム画像名を渡すことができるようにしたいのです。

答え1

最小限の動作例ではなく、単なるコードスニペットしか提供していないため、出力がどのようになるかわかりません。とにかく、ネストは避けるべきです。tikzpicture環境のネストは避けるべきです。

コメントで提案したように、\myimagename現在の画像の名前を保存するカスタム コマンドを作成してはいかがでしょうか。同じことが章のラベルにも適用できますが、コードからこれをどのように使用するのか理解できませんでした。

MWE:

\documentclass{report}
\usepackage{titlesec, tikz, tikzfill}
\usetikzlibrary{positioning, shadows}

\newcommand\mychapterlabel{}
\newcommand\myimagename{example-image-a}
\titleformat{\chapter}
  {\normalfont\sffamily\Huge\bfseries\scshape}
  {\gdef\chapterlabel{\thechapter\ }}{0pt}
  {\begin{tikzpicture}[remember picture, overlay]
    \coordinate[below right=4.8cm and 0cm of current page.north east] (a);
    \fill[fill overzoom image=\myimagename] (current page.north west) rectangle (a);
    \node[below right=2.5cm and 2cm of current page.north west, color=blue]
        {\color{white}\chapterlabel\mychapterlabel};
   \end{tikzpicture}}

\begin{document}

\renewcommand\mychapterlabel{Foo}
\chapter{One}

\renewcommand\mychapterlabel{Bar}
\renewcommand\myimagename{example-image-b}
\chapter{Two}

\end{document}

ここに画像の説明を入力してください

関連情報