Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.


Writing a manual using KOMA Script. The default fonts are perfect and should not be changed.


KOMA Script produces the following section outline:

enter image description here

The desired outline looks similar to the following (gradient extended to left and right margins):

enter image description here

The troubles I have encountered:

  • The fount for numerals and text changes.
  • Retaining the text spacing.
  • Expanding or extending the gradient box to:
    • the left and right margins (\textwidth?); and
    • a bit larger than the section (or subsection) text's top and bottom margins.

Source Code

My first attempt resembles:

    \tikz[background rectangle/.style={left color=blue!20,right color=white},
    show background rectangle] 
    \node [inner sep=0pt] (0,0) {#1};%

This produces:

enter image description here


Changing the text width for the node helps:

\node [text width=\textwidth, inner sep=0pt] (0,0) {#1};%

This produces:

enter image description here



How would you implement a margin-to-margin gradient (preferably using TikZ) that is slightly larger than the text?

share|improve this question

1 Answer 1

up vote 22 down vote accepted

This is relatively easy to achieve using the titlesec package:


\usepackage{blindtext}      % for a test document

     \tikz[overlay] \shade[left color=blue!20,right color=white] (0,-1ex) rectangle (\textwidth,1em);}%    



Note the following:

  • \usekomafont{sectioning}\usekomafont{section} sets the font to whatever is chosen using the KOMA Script styling mechanism.

  • The [overlay] option of \tikz means that TikZ won't take any space.

  • This breaks if the title is longer than a line.

Edit: Here is second version, that works with long lines and does not ignore ascenders and descenders. The code is more complicated, though. It draws the whole section heading with TikZ.



    \begin{tikzpicture}[inner sep=0pt, inner ysep=0.3ex]
        \node[anchor=base west] at (0,0) (counter) {\thesection};
        \path let \p1 = (counter.base east) in node[anchor=base west, text width={\textwidth-\x1-0.33em}] (content) at ($(counter.base east)+(0.33em,0)$) {#1};
            \shade[left color=blue!20,right color=white] let \p1=(counter.north), \p2=(content.north) in
            (0,{max(\y1,\y2)}) rectangle (content.south east);


\section{a very long section entry a very long section entry a very long section entry a very long section entry a very long section entry}


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.