When compiling a LaTeX document, I get two pages numbered at "1": the front page and the first of the table of contents. Here's a MWE:
\documentclass[12pt,a4paper]{report}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{hyperref}
\title{Title}
\begin{document}
\maketitle
\tableofcontents
\chapter{Chapter one}
\end{document}
When compiling this (using simply pdflatex file.tex), I get this:
But when I remove the line \usepackage{hyperref}, page numbers are fine. Note that I need this package to have links to pages in my table of contents, but maybe there's a better way to do so. What is happening here ? How do I get normal page numbers ?
Thanks in advance.
\maketitle under the report class sets the page number to 1 on the title page, but also restarts it from 1 for the following page. That's why you achieve a virtual page number 1 for the title, followed by an actual page number one for the ToC. I emphasize virtual here because \maketitle sets the title on an empty page style so that nothing is printed in the header/footer. However, these page numbers still appear in the toolbar when viewed in Adobe Acrobat.
One way around it would be to manually change the page display to something more appropriate just for the title page. For example, let's make the title page be called T:
\documentclass{report}
\usepackage{hyperref}
\title{Title}
\author{Author}
\begin{document}
\begingroup
\renewcommand{\thepage}{T}
\maketitle % Page T
\endgroup
\tableofcontents % Page 1
\chapter{A chapter} % Page 2
\end{document}
Related
I added a page header with the following command in LaTeX:
\pagestyle{fancy} \fancyhead[L]{\rightmark} \fancyhead[R]{\leftmark}
Here is a minimal reproducible example:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\title{Titlepage}
\date{October 2021}
\pagestyle{fancy} \fancyhead[L]{\rightmark} \fancyhead[R]{\leftmark}
\usepackage{graphicx}
\usepackage{titlesec}
\usepackage{lipsum} %just to generate text for the example
\newcommand*\HUGE{\Huge}
\newcommand*\chapnamefont{\normalfont\LARGE\MakeUppercase CHAPTER}
\newcommand*\chapnumfont{\normalfont\HUGE}
\newcommand*\chaptitlefont{\normalfont\HUGE\bfseries}
\newlength\beforechapskip
\newlength\midchapskip
\setlength\midchapskip{\paperwidth}
\addtolength\midchapskip{-\textwidth}
\addtolength\midchapskip{-\oddsidemargin}
\addtolength\midchapskip{-1in}
\setlength\beforechapskip{18mm}
\titleformat{\section}[display]
{\normalfont\filleft}
{{\chapnamefont}%
\makebox[0pt][l]{\hspace{.8em}%
\resizebox{!}{\beforechapskip}{\chapnumfont\thesection}%
\hspace{.8em}%
\rule{\midchapskip}{\beforechapskip}%
}%
}%
{25pt}
{\chaptitlefont}
\titlespacing*{\section}
{0pt}{40pt}{40pt}
\begin{document}
\maketitle
\newpage
blank page
\newpage
\section{Introduction}
the page header should not be visible here
\newpage
\subsection{Test2}
only the section should be visible in the page header (1 INTODUCTION)
\newpage
only the subsection should be visible in the page header (1.1 Test2)
\end{document}
With this command there is the problem that it appears on all pages, but for my thesis I would like to remove it from pages where the section shows up for the first time
here is an example how it currently looks:
this is how it should look like, when the section appears for the first time:
Also I would like the header to adapt, according to which side it is on (even or odd). For example I would want to have on the left page the section name only (even page) and on the right side the subsection name should show up (odd page):
I would use another documentclass. This would automatically solve most of your problems:
in report or book class, the first pages of a chapter automatically use another page style without the header
if you use a two-sided document, you can define the fancyhead depending on E(ven) or O(dd) pages
\documentclass[twoside]{report}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\title{Titlepage}
\date{October 2021}
\pagestyle{fancy}
\fancyhead{}
\fancyhead[LE]{\leftmark}
\fancyhead[RO]{\rightmark}
\usepackage{graphicx}
\usepackage{titlesec}
\usepackage{lipsum} %just to generate text for the example
\newcommand*\HUGE{\Huge}
\newcommand*\chapnamefont{\normalfont\LARGE\MakeUppercase CHAPTER}
\newcommand*\chapnumfont{\normalfont\HUGE}
\newcommand*\chaptitlefont{\normalfont\HUGE\bfseries}
\newlength\beforechapskip
\newlength\midchapskip
\setlength\midchapskip{\paperwidth}
\addtolength\midchapskip{-\textwidth}
\addtolength\midchapskip{-\oddsidemargin}
\addtolength\midchapskip{-1in}
\setlength\beforechapskip{18mm}
\titleformat{\chapter}[display]
{\normalfont\filleft}
{{\chapnamefont}%
\makebox[0pt][l]{\hspace{.8em}%
\resizebox{!}{\beforechapskip}{\chapnumfont\thechapter}%
\hspace{.8em}%
\rule{\midchapskip}{\beforechapskip}%
}%
}%
{25pt}
{\chaptitlefont}
\titlespacing*{\chapter}
{0pt}{40pt}{40pt}
\begin{document}
\maketitle
\newpage
blank page
\newpage
\chapter{Introduction}
the page header should not be visible here
\newpage
\section{Test2}
only the section should be visible in the page header (1 INTODUCTION)
\newpage
only the subsection should be visible in the page header (1.1 Test2)
\end{document}
I am currently writing my thesis using scrbook and changed the footer layout. However, I also want to change the footer on Part and Chapter pages as well. What do I need to change for this? Currently, it basically looks like this right now. I want to have the page number in the center of the Chapter/Part page as well.
Example code:
\documentclass[english, 12pt]{scrbook}
\usepackage[utf8]{inputenc}
\usepackage[automark,ilines]{scrlayer-scrpage}
\usepackage{blindtext}
\pagestyle{scrheadings}
\ohead{}
\ihead{\headmark}
\chead{}
\cfoot{-~\pagemark~-}
\ofoot{}
\ifoot{}
\begin{document}
\chapter{Introduction}
\blindtext[5]
\end{document}
Thanks in advance for your help!
You can use an optional argument to set the styles for the plain pages:
\documentclass[english, 12pt]{scrbook}
\usepackage[utf8]{inputenc}
\usepackage[automark,ilines]{scrlayer-scrpage}
\usepackage{blindtext}
\pagestyle{scrheadings}
\ohead[]{}
\ihead[whatever]{\headmark}
\chead[]{}
\cfoot[something]{-~\pagemark~-}
\ofoot[]{}
\ifoot[]{}
\begin{document}
\chapter{Introduction}
\blindtext[5]
\end{document}
I am new to latex and I wrote the below tex code on Texmaker editor.
What I want to do is to add the "University" section without any numbering preceeding it and to be centered horizontally, because when I run the code I find that the word "University" is displayed but it is preceeded by a number and I do not want to display any number preceeding that word.
code:
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{graphicx}
\usepackage{kpfonts}
\author{Anan}
\pagestyle{plain}
\begin{document}
\section{University}
\end{document}
\section*{\centering University}
% * removes numbering for _this_ \section instance,
% \centering within environment centres the title.
Note however, that this is a local solution, and that it's better practice (and easier for you to make later document-global changes) to re-define the \section, \subsection, ... environments using the titlesec package, as is described well in Alan Munn:s answer in the following tex.stackexchange thread:
https://tex.stackexchange.com/questions/8546/section-heading-centering-problem
All you have to do is to edit your line 9:
\section{University}
this way:
\section*{\centering University}
since the command \section* produces unnumbered sections.
Further, if you want to to include an unnumbered section to your table of contents, you can add
\addcontentsline{toc}{section}{University}
(this time without \centering) just after. The resulting code:
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{graphicx}
\usepackage{kpfonts}
\author{Anan}
\pagestyle{plain}
\begin{document}
\tableofcontents
\section*{\centering University}
\addcontentsline{toc}{section}{University}
Text.
\end{document}
I am writing my thesis in Latex, document class: report. I have got front matter containing of abstract, acknowledgement and so on.
I want to add header only to my main matter which starts with my first chapter:Introduction. I want the header to be the chapter number without the word "chapter" and the chapter title next to it. I also want the page number to appear in the centre on the bottom of the page in all pages of the main matter.
I don't want any header or line in any page of my front matter.
Can you please guide me? Thanks
Here it is the sample code that I am applying.
\documentclass[a4paper,12pt,titlepage]{report}
\usepackage{amsfonts}
\usepackage[english]{babel}
\usepackage{graphicx}
\usepackage{color}
\usepackage{colordvi}
\usepackage{amssymb}
\usepackage{natbib}
\usepackage[nottoc,notlot,notlof]{tocbibind}
\usepackage{setspace}
\usepackage{amsmath}
\usepackage{theorem}
\usepackage{lineno}
\usepackage{multirow}
\usepackage [toc,page]{appendix}
\usepackage{framed}
\usepackage{setspace}
\doublespacing
\usepackage[left=1.5in,top=2in,right=1in,bottom=2in]{geometry}
\begin{document}
\title{xxx}
\author{xxx}
\date{xxx}
\maketitle
\thispagestyle{empty}
\renewcommand{\thepage}{\roman{page}}
% here it comes my front matter for example:
\clearpage
\addcontentsline{toc}{chapter}{Abstract}
\chapter*{Abstract}
ABSTRACT CONTENTS
%then:
\clearpage
\cleardoublepage
\pagenumbering{arabic}
% here it starts my main matter:
\chapter{Introduction} %first chapter
\chapter{First Esssay in XXX} %second chapter
\end{document}
You have a number of options to set headers in a document. The most frequently-used package is fancyhdr.
First of all, you need to remove the word Chapter from the regular chapter mark. For this, add
\usepackage{etoolbox}
\makeatletter
%\newcommand{\updatechaptermark}{%
\appto\ps#fancy{%
\patchcmd{\chaptermark}% <cmd>
{\#chapapp\ }{}% <search><replace>
{}{}% <success><failure>
}%}
\makeatother
to your preamble. The above strips out \#chapapp\ (note the space) from \chaptermark as part of the call to \pagestyle{fancy}. That's required as fancyhdr may update \chaptermark upon calling \pagestyle{fancy}.
Second, you need to set the headers/footers. Here's a setting that yields what you're after:
\usepackage{fancyhdr}
\fancyhf{}% Clear header/footer
\fancyhead[C]{\leftmark}% Chapter mark
\fancyfoot[C]{\thepage}% Footer contains the page number
\renewcommand{\headrulewidth}{.4pt}% Header rule width
The above sets the header as \leftmark, which contains the \chaptermark setting (since \chaptermark actually issues \markboth{<leftmark>}{<rightmark>} with an empty <rightmark>).
\documentclass{report}
\usepackage{fancyhdr,lipsum}
\usepackage{etoolbox}
\makeatletter
%\newcommand{\updatechaptermark}{%
\appto\ps#fancy{%
\patchcmd{\chaptermark}% <cmd>
{\#chapapp\ }{}% <search><replace>
{}{}% <success><failure>
}%}
\makeatother
\fancyhf{}% Clear header/footer
\fancyhead[C]{\leftmark}
\fancyfoot[C]{\thepage}
\renewcommand{\headrulewidth}{.4pt}
\begin{document}
%\frontmatter
\pagenumbering{roman}
\title{xxx}
\author{xxx}
\date{xxx}
\maketitle
\thispagestyle{empty}
% here it comes my front matter for example:
\cleardoublepage
\tableofcontents
\cleardoublepage
\addcontentsline{toc}{chapter}{Abstract}%
\chapter*{Abstract} \lipsum[1]
\cleardoublepage
\pagenumbering{arabic}
\pagestyle{fancy}
\chapter{Introduction} \lipsum[1-50] % first chapter
\chapter{Methodology} \lipsum[1-50] % second chapter
\chapter{Conclusion} \lipsum[1-50] % last chapter
\end{document}
Note that \chapters are set by default using the plain style. If you wish this to be different, you'll have to redefine the plain page style.
You can achieve the same output using a different header/footer package like titleps.
I am trying to create a reference to a float that doesn't use a caption. If I include \label{foo} within the float and reference it using \pageref{foo}, the correct page number is displayed in my pdf document but the hyperlink created by the hyperref package links to a different page (the first page of the section). If I include a caption before the label in the float, the hyperref link goes to the correct page.
Is there a way to get the hyperref link to work correctly without including a caption in the float? Or else is there a way to suppress the display of a caption so I can include one without it being shown?
Below is a minimal example. If I process it using pdflatex, I get three pages. The "figure" is shown on the second page, and the third page says, correctly, "See figure on page 2." But the hyperlink on the '2' says "Go to page 1", and if I click it it takes me to page 1.
If I put an empty \caption{} before the \label{foo}, then the hyperlink works correctly, but I don't want to show a caption for my float.
\documentclass[11pt]{memoir}
\usepackage{hyperref}
\begin{document}
some text
\clearpage
\begin{figure}
a figure
\label{foo}
\end{figure}
more text
\clearpage
See figure on page \pageref{foo}.
\end{document}
The \label command references the last invocation of \refstepcounter. \caption recognises that it is in a figure environment and calls \refstepcounter{figure}. You can call \refstepcounter by yourself.
To avoid skipping a number in the series of figures, you may create an own, meaningless counter with \newcounter{dummy}. The result:
\documentclass{scrreprt}
\usepackage{hyperref}
\newcounter{dummy}
\begin{document}
\chapter{First}
\newpage
\begin{figure}
{\Huge FIGURE}
\refstepcounter{dummy}
\label{fig:figure}
\end{figure}
\chapter{Second}
Goto \pageref{fig:figure}
\end{document}
Creates an hyperlink to the end of the figure. (works on my machine :-)
Note than \ref{fig:figure} is meaningless.
Right before the label, use \phantomsection, like so:
\documentclass{memoir}
\usepackage{hyperref}
\begin{document}
some text
\clearpage
\begin{figure}
a figure
\phantomsection
\label{foo}
\end{figure}
more text
\clearpage
See figure on page \pageref{foo}.
\end{document}
:)
Loading the caption package should suppress caption output of empty captions. The labels for floats are always determined by the caption command preceding the label command.