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 want to add the following header to my chapters:

enter image description here

I do not want to use fancyhdr because when I use it, it moves all my previous page settings (principally the table of contents layout), I tried using /thispagestyle{fancy} but it does not work.

My code looks as follows:

\documentclass[letterpaper,12pt,oneside,onecolumn,final,openany]{report}

\usepackage{alltt}
\usepackage{times}                   
\usepackage{graphicx}
\usepackage{listings}
\usepackage{apalike}
\usepackage{verbatim}
\usepackage[spanish]{babel}
\usepackage[left=2.7cm,top=2.5cm,right=2.2cm]{geometry}
\usepackage{titlesec}
\usepackage{titletoc}
\usepackage{tocloft}

\AtBeginDocument{\renewcommand{\contentsname}{\hfill\rule{.7\textwidth}{3pt} \hspace*{.3\textwidth} \\ \hspace*{.3\textwidth} Contenido}}
\AtBeginDocument{\renewcommand{\listfigurename}{\hfill\rule{.7\textwidth}{3pt} \hspace*{.3\textwidth} \\ \hspace*{.3\textwidth} Lista de Figuras}}
\AtBeginDocument{\renewcommand{\listtablename}{\hfill\rule{.7\textwidth}{3pt} \hspace*{.3\textwidth} \\ \hspace*{.3\textwidth} Lista de Tablas}}

\pagestyle{myheadings}

\begin{document}

\pagenumbering{roman}
\tableofcontents
\clearpage
\listoffigures
\clearpage
\listoftables
\clearpage
\pagenumbering{arabic}

\thispagestyle{myheadings}

\chapter{Introduction}
\label{chap:intro}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam convallis accumsan tempor. Etiam adipiscing gravida sollicitudin. Suspendisse potenti. Donec risus lectus, ultricies at varius in, accumsan quis sapien. Duis at arcu turpis, lacinia dapibus orci. Etiam pharetra turpis et diam volutpat in dapibus lorem facilisis. Vestibulum adipiscing, metus quis scelerisque pulvinar, purus quam iaculis felis, ac porta nulla justo nec dui. Donec condimentum pulvinar augue, varius placerat quam pharetra in. Vestibulum velit ante, feugiat imperdiet scelerisque in, posuere eu purus.

\section{Lorem ipsum}
\label{sec:intro:lorem}

Pellentesque sit amet dui non nunc venenatis tempus vel id libero. Etiam consectetur metus fringilla nibh 

\subsection{Ipsum}
\label{sec:intro:ipsum}

Etiam iaculis ante vitae diam egestas egestas. Nullam sed odio id mi consequat porttitor. Ut ut libero augue, 

\chapter{Things 2}
\label{chap:intro2}

\subsection{Pallentesque}
\label{sec:intro:pallen}

Pellentesque sit amet dui non nunc venenatis tempus vel id libero. Etiam consectetur metus fringilla nibh 

\end{document}

Currently it looks like this:

enter image description here

Any suggestions?

share|improve this question
    
add \pagestyle{myheadings} –  Yiannis Lazarides May 20 '12 at 5:54
add comment

2 Answers

up vote 5 down vote accepted

I do not want to use fancyhdr because when I use it, it moves all my previous page settings (principally the table of contents layout),

You can use fancyhdr without any worries and that is the easiest way out. Look at the following code:

\documentclass[letterpaper,12pt,oneside,onecolumn,final,openany]{report}

\usepackage{alltt,fancyhdr}
\usepackage{mathptmx}
\usepackage{graphicx}
\usepackage{listings}
\usepackage{apalike}
\usepackage{verbatim}
\usepackage[spanish]{babel}
\usepackage[left=2.7cm,top=2.5cm,right=2.2cm,bottom=2.5cm,headsep=.5cm]{geometry}
\usepackage{titlesec}
\usepackage{titletoc}
\usepackage{tocloft}

\AtBeginDocument{\renewcommand{\contentsname}{\hfill\rule{.7\textwidth}{3pt} \hspace*{.3\textwidth} \\ \hspace*{.3\textwidth} Contenido}}
\AtBeginDocument{\renewcommand{\listfigurename}{\hfill\rule{.7\textwidth}{3pt} \hspace*{.3\textwidth} \\ \hspace*{.3\textwidth} Lista de Figuras}}
\AtBeginDocument{\renewcommand{\listtablename}{\hfill\rule{.7\textwidth}{3pt} \hspace*{.3\textwidth} \\ \hspace*{.3\textwidth} Lista de Tablas}}

\fancypagestyle{myheadings}{%
\fancyhead{}
\fancyhead[L]{\bfseries\itshape\nouppercase\leftmark}
\fancyhead[R]{\bfseries\nouppercase\thepage}
\renewcommand{\headrulewidth}{1pt}
\renewcommand{\footrulewidth}{0pt}
\addtolength{\headheight}{15pt}
}
\begin{document}

\pagenumbering{roman}
\tableofcontents
\clearpage
\listoffigures
\clearpage
\listoftables
\clearpage
\pagenumbering{arabic}

\pagestyle{myheadings}

\chapter{Introduction}
\label{chap:intro}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam convallis accumsan tempor. Etiam adipiscing gravida sollicitudin. Suspendisse potenti. Donec risus lectus, ultricies at varius in, accumsan quis sapien. Duis at arcu turpis, lacinia dapibus orci. Etiam pharetra turpis et diam volutpat in dapibus lorem facilisis. Vestibulum adipiscing, metus quis scelerisque pulvinar, purus quam iaculis felis, ac porta nulla justo nec dui. Donec condimentum pulvinar augue, varius placerat quam pharetra in. Vestibulum velit ante, feugiat imperdiet scelerisque in, posuere eu purus.

\section{Lorem ipsum}
\label{sec:intro:lorem}

Pellentesque sit amet dui non nunc venenatis tempus vel id libero. Etiam consectetur metus fringilla nibh
\clearpage

\subsection{Ipsum}
\label{sec:intro:ipsum1}

Etiam iaculis ante vitae diam egestas egestas. Nullam sed odio id mi consequat porttitor. Ut ut libero augue,
\clearpage
\subsection{Ipsum}
\label{sec:intro:ipsum2}

Etiam iaculis ante vitae diam egestas egestas. Nullam sed odio id mi consequat porttitor. Ut ut libero augue,

\chapter{Things 2}
\label{chap:intro2}

\subsection{Pallentesque}
\label{sec:intro:pallen}

Pellentesque sit amet dui non nunc venenatis tempus vel id libero. Etiam consectetur metus fringilla nibh

\end{document}

enter image description here

You can see that the TOC layout is untouched.

Note Instead of outdated times you must be using mathptmx.

share|improve this answer
    
This is exactly what I was trying to achieve, thanks! –  aljndrrr May 20 '12 at 12:52
add comment

If the problem is with the height of the header when you use the fancyhdr package, remember that you can redefine the height of the header with the geometry package:

\usepackage[head=30pt,foot=...]{geometry}

You can play with this height and the whole page layout to minimize the impact of using fancyhdr.

share|improve this answer
1  
You can load geometry with the option showframe in order to see the changes. –  leo May 20 '12 at 18:11
add comment

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.