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.

I am using fancyhdr for my header. The problem is, that some of my section names are too long and it looks quite stupid. I attached a screenshot.

  1. So how can I have this correctly? So it does not look that stupid anymore.

  2. Then my second question is: I want to have a line on the left and on the right (not above), I also attached a screenshot how it should look like (they should be the same as the line under it).

Here is my code:

\documentclass{book}
\usepackage{geometry}
\geometry{left=4cm,right=3cm, top=2cm, bottom=2cm} 
\usepackage[pagestyles]{titlesec}
\titlespacing*{\chapter}{0pt}{-30pt}{20pt}
\titleformat{\chapter}[display]{\color{headercolor}\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter}{20pt}{\Huge}

\titleformat{\section}
{\color{headercolor}\normalfont\Large\bfseries}{\thesection}{1em}{}

\titleformat{\subsection}
{\color{headercolor}\normalfont\Large\bfseries}{\thesubsection}{1em}{}

\titleformat{\subsubsection}
{\color{headercolor}\normalfont\large\bfseries}{\thesubsubsection}{1em}{}

\titleformat{\paragraph}
{\color{headercolor}\normalfont\normalsize\bfseries}{\theparagraph}{1em}{}
\usepackage[ngerman]{babel}
\usepackage{mathptmx}
\usepackage{helvet}
\usepackage{wallpaper}
\usepackage{color}
\usepackage[final]{pdfpages} 
%,bookmarksopenlevel={1}
%\usepackage[hidelinks,bookmarks=true,bookmarksopen=true,bookmarksnumbered=true,colorlinks=true,linkcolor=black,]{hyperref}
\usepackage[colorlinks,linkcolor=black,bookmarksopen=false,
hypertexnames=TRUE,pdfpagelabels=true]{hyperref}[2011/02/05]
\hypersetup{ 
  pdftitle={},
%  pdfauthor={\textcopyright },
  pdfsubject={Statistics book}, 
  pdfkeywords={}, 
  }
\usepackage{xcolor,bookmark}
\usepackage{scrextend}
\usepackage{titlepic}
\usepackage{shorttoc}
\usepackage{courier}
%\usepackage[titles]{tocloft}
\usepackage{type1cm}         
\usepackage{zref-abspage}
\usepackage{makeidx}         
\usepackage{graphicx}        
\usepackage{multicol}       
\usepackage[bottom]{footmisc}
\usepackage{tocstyle}
\usetocstyle{allwithdot} 
%\usepackage{thmbox}
\usepackage{shadethm}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{marginnote}
%\usetocstyle{KOMAlike}
\usepackage{wrapfig}
\usepackage{paralist}
\usepackage{amssymb}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{ulem}
\usepackage{fancyhdr}
%\usepackage{sectsty}

\definecolor{headercolor}{rgb}{0.6941,0.6745,0.4863}


\setlength{\headheight}{21pt}%

\begin{document}
\mainmatter%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pagestyle{fancy}
\fancyhf{}
%\fancyhead[L]{\parbox{0.7\textwidth}{\textbf{ \textcolor{headercolor}\leftmark\text{ }\textcolor{headercolor}{\rightmark}}}}
\fancyhead[L]{ \textcolor{headercolor}\leftmark \text{ }\textcolor{headercolor}{\rightmark}}%\thesection
\fancyhead[R]{\textcolor{headercolor}{\thepage}}
%\renewcommand{\headrule}{\vbox to 0pt{\hbox
%to\headwidth{\textcolor{headercolor}{\hrulefill}}\vss}} 
%%\renewcommand{\headrulewidth}{2pt}

 \renewcommand{\headrulewidth}{2pt}% 2pt header rule
  \renewcommand{\headrule}{\vbox to 0pt{\hbox
    to\headwidth{\textcolor{headercolor}{\rule{\linewidth}{\headrulewidth}}}\vss}} 

% here comes the sections part, I commented to have a running sample:

%\include{part1} 
%\include{chapter1}

% There I have those sections like
\section{very long text, really long, too long text, this looks not good but the names have to be like they are, yeah, really long, ..... ..... ..... ..... ..... ..... ..... ..}

text text\\text\\text\\text\\text and so on

\end{document}

Here is the screenshot: Problem 1:

enter image description here

enter image description here

Problem 2:

enter image description here

share|improve this question

2 Answers 2

\documentclass{article}
\usepackage{fancyhdr}
\usepackage{calc}
\usepackage{color}

\usepackage{lipsum}

\setlength{\headheight}{21pt}%
\fancyhf{}
\fancyhead[L]{\textcolor{red}{\hspace{2mm}\leftmark\rightmark\hfill\thepage\hspace{2mm}}}
\renewcommand{\headrule}{\vspace{-\headheight}\textcolor{red}{\vrule height \headheight width 4pt\relax\rule{\textwidth-8pt}{4pt}\vrule height \headheight width 4pt\relax}}


\begin{document}
\pagestyle{fancy}

\section[Short section name]{\lipsum[1]}
\lipsum[1]
\end{document}

enter image description here

share|improve this answer

For problem number one it is best if you provide a short title together with the section heading:

\section[Short section heading]{This is the equivalent long title that is typeset over several lines which is quite annoying. On a second note the title should probably be shorter}

I would highly recommend to limit your long titles, titles are titles, not self contained descriptions.

share|improve this answer
    
Ok, thanks a lot, and problem number 2? –  Heronimious Sep 4 '12 at 10:22

Your Answer

 
discard

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.