schattierte Buchstaben im Kapitel

schattierte Buchstaben im Kapitel

Diese Woche habe ich dieses Wort geschrieben:

\documentclass{book}
\usepackage{xcolor}

\definecolor{Monvert}{RGB}{229,36,36}

\definecolorseries{MONVERT}{rgb}{last}{Monvert}{black}

\resetcolorseries[15]{MONVERT}
\begin{document}

\chapter{Test}
  \Huge
\textcolor{MONVERT!!+}{P}\textcolor{MONVERT!!+}{s}\textcolor{MONVERT!!+}{y}\textcolor{MONVERT!!+}{c}\textcolor{MONVERT!!+}{h}\textcolor{MONVER
T!!+}{o}\textcolor{MONVERT!!+}{P}\textcolor{MONVERT!!+}{a}\textcolor{MONVERT!!+}{t}\textcolor{MONVERT!!+}{h}\textcolor{MONVERT!!+}{o}\textcolor{MONVERT!!+}{l}\textcolor{MONVERT!!+}{o}\textcolor{MONVERT!!+}{g}\textcolor{MONVERT!!+}{y}
\end{document}   

meine Frage ist: Wenn ich Kapitel und Abschnitte auf die gleiche Weise anpassen möchte, wie kann ich das tun? Jede Einsicht oder Lösung wird geschätzt

Antwort1

Eine vorläufige Version, ohne \sectionTeile. Sie wird höchstwahrscheinlich scheitern, wenn der Kapiteltitel Makros statt nicht erweiterbarem Material enthält.

\documentclass{book}
\usepackage{xcolor}

\definecolor{Monvert}{RGB}{229,36,36}

\definecolorseries{MONVERT}{rgb}{last}{Monvert}{black}

\resetcolorseries[50]{MONVERT}

\usepackage{xpatch}

\usepackage{pgffor}

\usepackage{xstring}

\usepackage{xparse}

\NewDocumentCommand{\shadetitle}{+m}{%
  \StrLen{#1}[\titlelength]
  \foreach \x in {1,...,\titlelength} {%
    \textcolor{MONVERT!!+}{\StrChar{#1}{\x}}%
  }%
}

\makeatletter
\xpatchcmd{\@makechapterhead}{\Huge \bfseries #1\par\nobreak}{\Huge \bfseries \shadetitle{#1}\par\nobreak}{}{}
\makeatother
\begin{document}



\chapter{Test it with a very long title}
  \Huge
  \textcolor{MONVERT!!+}{P}\textcolor{MONVERT!!+}{s}\textcolor{MONVERT!!+}{y}\textcolor{MONVERT!!+}{c}\textcolor{MONVERT!!+}{h}\textcolor{MONVERT!!+}{o}\textcolor{MONVERT!!+}{P}\textcolor{MONVERT!!+}{a}\textcolor{MONVERT!!+}{t}\textcolor{MONVERT!!+}{h}\textcolor{MONVERT!!+}{o}\textcolor{MONVERT!!+}{l}\textcolor{MONVERT!!+}{o}\textcolor{MONVERT!!+}{g}\textcolor{MONVERT!!+}{y}
\end{document}   

Bildbeschreibung hier eingeben

BearbeitenEinige verbesserte Version

\documentclass{book}
\usepackage{xcolor}

\definecolor{Monvert}{RGB}{229,36,36}

\definecolorseries{MONVERT}{rgb}{last}{Monvert}{black}

\resetcolorseries[100]{MONVERT}

\usepackage{xpatch}
\usepackage{pgffor}
\usepackage{xstring}
\usepackage{xparse}
\usepackage{blindtext}

\NewDocumentCommand{\shadetitle}{+m}{%
  \StrLen{#1}[\titlelength]%
  \foreach \x in {1,...,\titlelength} {%
    \textcolor{MONVERT!!+}{\StrChar{#1}{\x}}%
  }%
}

\makeatletter

%\xpatchcmd{\@ssect}{\hskip #1\relax #5}{#4{\hskip #1\relax \shadetitle{#5}}}{\typeout{Patch success}}{\typeout{Patch failure}}

% Does not work so far :-(
%\xpatchcmd{\@ssect}{\@svsechd{#4{\hskip #1\relax #5}}}{\@svsechd{#4{\hskip #1\relax \shadetitle{#5}}}}{\typeout{Patching ssect}}{}


% Patching the section header command
\xpatchcmd{\@sect}{\def\@svsechd{%
    #6{\hskip #3\relax
      \@svsec #8}%
  }}{%
    \def\@svsechd{%
      #6{\hskip #3\relax
        \@svsec \shadetitle{#8}}%
    }}{}{}
\xpatchcmd{\@sect}{\interlinepenalty \@M #8\@@par}{          \interlinepenalty \@M \shadetitle{#8}\@@par}{}{}
\xpatchcmd{\@makechapterhead}{\Huge \bfseries #1\par\nobreak}{\Huge \bfseries \shadetitle{#1}\par\nobreak}{}{}
\xpatchcmd{\@makeschapterhead}{\Huge \bfseries #1\par\nobreak}{\Huge \bfseries \shadetitle{#1}\par\nobreak}{}{}
\xpatchcmd{\@makechapterhead}{\huge\bfseries \@chapapp\space \thechapter}{\huge\bfseries \shadetitle{\@chapapp}\space \shadetitle{\thechapter}}{}{}

\makeatother
\begin{document}



\chapter{Test it with a very  title}
\section{And a shorter title}
  \Huge
  \textcolor{MONVERT!!+}{P}\textcolor{MONVERT!!+}{s}\textcolor{MONVERT!!+}{y}\textcolor{MONVERT!!+}{c}\textcolor{MONVERT!!+}{h}\textcolor{MONVERT!!+}{o}\textcolor{MONVERT!!+}{P}\textcolor{MONVERT!!+}{a}\textcolor{MONVERT!!+}{t}\textcolor{MONVERT!!+}{h}\textcolor{MONVERT!!+}{o}\textcolor{MONVERT!!+}{l}\textcolor{MONVERT!!+}{o}\textcolor{MONVERT!!+}{g}\textcolor{MONVERT!!+}{y}

\chapter*{Some other chapter}
\section*{Some other section}
\end{document}   

Bildbeschreibung hier eingeben

Mir ist durchaus bewusst, dass dies nur ein Hack ist. Natürlich muss es bessere Möglichkeiten geben. Wahrscheinlich ist es besser, die Tokens einzufärben und nicht zu versuchen, jedes Zeichen in der Eingabe zu identifizieren.

verwandte Informationen