2

I'm creating a new CV using moderncv at the moment. But I'm modifying the package to get a (at least in my opinion) better fitting result.

I'm looking for a way to make the section heading with a color gradient. Below is an example for how it looks at the moment. I would like to have a gradient from the left sight of the bar to the end of the last word.

Example for section heading

The main part of the section heading layout is defined in "moderncvstyleclassic.sty" which I'm using:

\RenewDocumentCommand{\section}{sm}{%
  \par\addvspace{2.5ex}%
  \phantomsection{}% reset the anchor for hyperrefs
  \addcontentsline{toc}{section}{#2}%
  \parbox[t]{\hintscolumnwidth}{\strut\raggedleft\raisebox{\baseletterheight}{\color{color1}\rule{\hintscolumnwidth}{0.95ex}}}%
  \hspace{\separatorcolumnwidth}%
  \parbox[t]{\maincolumnwidth}{\strut\sectionstyle{#2}}%
  \par\nobreak\addvspace{1ex}\@afterheading}% to avoid a pagebreak after the heading

with the following renewcommands included:

\renewcommand*{\sectionfont}{\Large\mdseries\upshape}

\renewcommand*{\sectionstyle}[1]{{\sectionfont\textcolor{color1}{#1}}}

I already found a way to write text with a color gradient. But I couldn't combine it with a bar to the left of the text (as in the picture) and the same gradient stretching across both the bar on the left and the text on the right.

This is how I found to to normal color gradient sections:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fadings,patterns}
\begin{document}
\newsavebox{\tempbox}
\newcommand\tikzsection[1]{%
  \begin{tikzfadingfrompicture}[name=tikzsection]
    \node [text=white] {\normalfont \Large \bfseries #1};
  \end{tikzfadingfrompicture}
  \begin{lrbox}{\tempbox}%
    \begin{tikzpicture}
      \node [text=white,inner sep=0pt,outer sep=0pt] (textnode) {\normalfont \Large \bfseries #1};
      \shade[path fading=tikzsection,fit fading=false,left color=blue,right color=black]
      (textnode.south west) rectangle (textnode.north east);
    \end{tikzpicture}%
  \end{lrbox}
  % Now we use the fading in another picture:
  \section{\usebox\tempbox{}}%
}

\tikzsection{First section}
Some text
\tikzsection{Second section}
Some text


\end{document}

Now I need a way to combine this with a bar to the left of the text and to include this in my moderncv documentclass (but I guess this is the least problematic thing).

1 Answer 1

4

You could try this but the alignment is not quite right:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fadings,patterns,positioning,fit}
\tikzset{
  zero sep/.style = {inner sep=0pt, outer sep=0pt},
}
\begin{document}
  \newsavebox{\tempbox}
  \newcommand\tikzsection[1]{%
    \begin{tikzfadingfrompicture}[name=tikzsection]
      \node [minimum width=50mm, minimum height=2.5mm, fill=white, zero sep] (box node) {};
      \node (text node) [text=white, right=10pt of box node.east, anchor=west,  zero sep] {\normalfont \Large \bfseries #1};
      \node [fit=(box node.north west) (text node.south east) (text node.north west) (box node.south east)] {};
    \end{tikzfadingfrompicture}
    \begin{lrbox}{\tempbox}%
      \begin{tikzpicture}
        \node [text width=50mm, minimum height=2.5mm, fill=white, zero sep] (boxnode) {};
        \node [text=white, right=10pt of boxnode.east, anchor=west,  zero sep] (textnode) {\normalfont \Large \bfseries #1};
        \node (fitnode) [fit=(boxnode.north west) (textnode.south east) (textnode.north west) (boxnode.south east)] {};
        \shade[path fading=tikzsection, fit fading=false,left color=blue, right color=black]
        (fitnode.north west) rectangle (fitnode.south east);
      \end{tikzpicture}%
    \end{lrbox}
    % Now we use the fading in another picture:
    \section{\usebox\tempbox{}}%
  }

  \tikzsection{First section}
  Some text
  \tikzsection{Second section}
  Some text


\end{document}

faded headings

Personally, I'm not convinced this is a good idea for a CV. If it were me, I would think about what this will look like after being printed on an office printer (in black-and-white) and photocopied (in black-and-white). But perhaps you are in a more graphics-orientated field than me!

6
  • Thanks! This looks quite like what I was looking for. Now I'm working to integrate this in moderncv which is more difficult than expected since I can't just override the definition of \sectionin moderncv. Commented Dec 7, 2014 at 22:54
  • If you see the style of my CV I think you would realize that a color gradient in the sections fits quite well. I also won't use the colors in your example, I will look for better matching ones ;-) Commented Dec 7, 2014 at 22:56
  • @AdrianPfeifle My concern would not be whether the colours fitted but what they would look like when printed in black-and-white and run through a photocopier.
    – cfr
    Commented Dec 7, 2014 at 23:47
  • I happen to know that where I'm going to apply they are printing in color ;-) Commented Dec 8, 2014 at 6:41
  • How can I modify your version so that the color gradient is fixed to the page boundaries? I mean right now for short sections I have a "fast transition" and for long section headings a longer one. To make it more uniform I'd like to have fixed gradient so that the left color starts with the left page boundary and the right color is reached at the right page boundary. If a section heading ends in the middle of the page the last letter gets a in the middle between left and right color. Commented Dec 8, 2014 at 6:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .