1

I have made a heading for my final degree project where an image appears, my name and the name of the project, but it only appears on the first page of each chapter, in the others the heading that LaTeX puts by default appears. This is the code for my header:

\fancypagestyle{plain}{
       % Nombre del documento 
         \newcommand{\titulo}{\textsc{Búnker portátil para radiología industrial}}
        % Nombre de la Unidad en concreto
         \newcommand{\autor}{\textsc{Juan Francisco Molina Pérez}}
        % Nombre del módulo (asignatura)
         \newcommand{\seccion}{\leftmark}
        \lhead{
            {\color{light-gray} \footnotesize \titulo} \\
            {\color{light-gray} \footnotesize \autor}  \\
            \color{light-gray} \seccion 
            }
        \rhead{\includegraphics[width=4cm]{tfg/img/img3.png}}
        \let\oldheadrule\headrule % Copy \headrule into \oldheadrule
        \renewcommand{\headrule}{\color{orange}\oldheadrule} % Add colour to \headrule       
        \rfoot{Página \thepage\ de \pageref{LastPage}}  % Número de página
        \cfoot{} %para vaciar número de página que viene por defecto
        \renewcommand{\headrulewidth}{0.03cm}

}

It should be noted that I have divided the work into parts in LaTeX, making a file only for the header and calling it in the general file of the TFG.

4
  • 5
    Hello and welcome to Text.Se. The common language used here is english. So please ask your question in english so that other people can help you with your problem.
    – Roland
    Mar 13 at 13:30
  • 1
    ¿Puede por favor, hacer su pregunta en Inglés?
    – Ingmar
    Mar 13 at 13:31
  • I run your text in an online translator. Next time please do it yourself.
    – campa
    Mar 13 at 14:04
  • 3
    Please specify at least what document class you are using. Most document classes specify the plain style only for the first page of a chapter, and a different style (often headers) for all other pages. Mar 13 at 16:05
4

You are making the adjustments only to the pagestyle plain, which by default appears on title and chapter pages only. There are two options to change where the header appears.

1.

If you want to use your header definition as it is for every page, you can add

\pagestyle{plain}

after the definition, to make 'normal' pages also use the plain style.

2.

If you want the header to appear on all pages, except at the beginning of a chapter (wich is the default and usually the desired behavior), you can set your header definition for a different style, like in this MWE:

\documentclass{book}
\usepackage{blindtext}

\usepackage{fancyhdr}

\fancypagestyle{fancy}{%
    \lhead{left head}
    \rhead{right head}
    \rfoot{\thepage}
    \cfoot{}
    \renewcommand{\headrulewidth}{0.03cm}   
}
\pagestyle{fancy}

\begin{document}
    \Blinddocument
\end{document}
1
3

I prepared a document with two chapters and seven pages. Usually you define two styles: plain and fancy.

With the standard classes every \chapter invokes the plain style. The fancy style is applied to the normal pages.

You can also define others styles (I used the name withphoto for the third) that can be called in particular pages using \thispagestyle{withphoto}

Choice one: you want your photo at the beginning of every chapter.

You need to define two pagestyles: plain, that is invoked by chapter, and fancy for rest of the pages.

Choice two: you want your photo only at the beginning of the first chapter.

You need three styles: withphoto to be invoked once as \thispagestyle{withphoto}, plain called by every other chapter and fancy the style used by normal pages.

A

B

This is the code for the second choice. Note he use of the package geometry to create space for the photo.

\documentclass[12pt,a4paper]{report}

\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage[top=4cm, bottom=3cm, left=2.5cm, right=2cm, headheight=1.5cm]{geometry}

\usepackage{lastpage}
\usepackage{fancyhdr}

\usepackage[spanish]{babel}
\usepackage{xcolor}

\usepackage{kantlipsum} % dummy texto

% Nombre del documento 
\newcommand{\titulo}{\textsc{Búnker portátil para radiología industrial}}
% Nombre de la Unidad en concreto
\newcommand{\autor}{\textsc{Juan Francisco Molina Pérez}}
% Nombre del módulo (asignatura)
\newcommand{\seccion}{\textsc{Asignatura}}

\let\oldheadrule\headrule% Copy \headrule into \oldheadrule
\renewcommand{\headrule}{\color{red}\oldheadrule}% Add colour to \headrule
\renewcommand{\headrulewidth}{0.5pt}

\fancypagestyle{plain}{% first page of chapters after the first
\fancyhf{}  
\fancyhead[L]{}
\fancyhead[R]{} 
    \fancyfoot[R]{Página \thepage\ de \pageref{LastPage}}  % Número de página
    \renewcommand{\headrulewidth}{0pt}
}

\fancypagestyle{fancy}{% normal pages
\fancyhf{}
\fancyhead[L]{\leftmark}
%\fancyhead[L]{Sección \rightmark}  % ALTERNATIVE
\fancyhead[R]{Página \thepage\ de \pageref{LastPage}}
}

\fancypagestyle{withphoto}{% only first chapter
    \fancyhf{}  
    \fancyhead[L]{%
        {\color{gray} \footnotesize \titulo} \\
        {\color{gray} \footnotesize \autor}  \\
        {\color{gray} \footnotesize \seccion }
    }
    \fancyhead[R]{\includegraphics[width=4cm]{example-grid-100x100pt}} 
    \fancyfoot[R]{Página \thepage\ de \pageref{LastPage}}  % Número de página
}

\pagestyle{fancy} % set fancy headers for normal pages

\begin{document}
\chapter{El primero}
\thispagestyle{withphoto}   
1.  \kant[1-3]  
\section{A} 
2.  \kant[4-8]          
\section{B} 
3.  \kant[2-5]  
\chapter{El segundo}    
4.  \kant[9-12]     
\section{C} 
5. \kant[15-20] 
\end{document}

If want the Choice one convert withphoto in plain and comment \thispagestyle{withphoto}.

c

3
  • Thank you very much for your help! Mar 16 at 18:30
  • I have remake the header how you said to me, but now I have a new probblem. With the new code, Latex say to me this: Timed out. Sorry, your compile took too long to run and timed out. This may be due to a LaTeX error, or a large number of high-res images or complicated diagrams. I have convert the image in the header to pdf, but this not solved the problem. ¿What can I do?. Thanks. Mar 16 at 18:53
  • I think you should ask a new question. The problem you mention is not coming from the image of the header, but form the code you are running. Meanwhile comment it part by part to try to pinpoint the origin. Mar 16 at 20:28

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.