2

I'm trying to use a slightly adapted version of the "real 'decorative line'" example from the fancyhdr documentation (p. 17, bottom) in a two-column book document. However, straight from the pdf, the line only spans one column. Thus I've tried the following to achieve the desired effect, namely a line going across the whole page width:

\documentclass[twocolumn]{book}

\usepackage{lipsum}

\usepackage[top=3cm,bottom=3cm,left=2cm,right=2cm]{geometry}
\usepackage{fancyhdr}

\fancyhead{}
\fancyhead[RO]{Text1}
\fancyhead[LE]{Text2}
\renewcommand\headrule{%
  \onecolumn%
  \vspace{-2\baselineskip}%
  \vspace{1.3mm}%
  \hrulefill%
  \raisebox{-2.1pt}{\fbox{OK}}%
  \hrulefill%
  \twocolumn%
}
\pagestyle{fancy}

\begin{document}
\lipsum[1-16]
\end{document}

This looks sort of okay, although I'm not too happy about the fiddling with \vspaces. What's worse, though, is that it only looks as expected on the first page. In all subsequent pages, there's too much white space between the line and the text.

Here is a comparison of a "regular" line (achieved by commenting out the \renewcommand portion in the above example) with the result I'm getting for page 2.

Regular line:

enter image description here

My decorative line:

enter image description here

Note that the space between the bottom line of the box around "OK" and the text is larger in the second picture than the space between the line and the text in the first example.

Obviously, adding more \vspace fiddling after the \twocolumn command won't do me any good because then the first page, which currently looks fine, will get messed up.

Is there a generally better approach to get a decorative line across the whole page for a two-column book document, or if not, is there a way to adapt my code so far to achieve the desired result?

3

I would not redefine \headrule.

\documentclass[twocolumn]{book}

\usepackage{lipsum}

\usepackage[top=3cm,bottom=3cm,left=2cm,right=2cm]{geometry}
\usepackage{fancyhdr}

\newcommand{\decoration}[1]{%
  \raisebox{\dimexpr-\dp\strutbox-1pt}[0pt][0pt]{%
    \makebox[0pt][#1]{%
      \makebox[\textwidth][s]{%
        \hrulefill\raisebox{-2.1pt}{\fbox{OK}}\hrulefill
      }%
    }%
  }%
}
\fancyhead{}
\fancyhead[RO]{Text1\decoration{r}}
\fancyhead[LE]{\decoration{l}Text2}
\renewcommand{\headrulewidth}{0pt}
\pagestyle{fancy}

\begin{document}
\lipsum[1-16]
\end{document}

enter image description here

  • Great, thanks! It seems though that the line does not fully extend to the left margin and (hence?) the OK-box does not seem to be completely in the center? – Thomas Apr 6 at 14:26
  • @Thomas Now it's fixed – egreg Apr 6 at 16:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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