Paragraph page number misalignment in table of contents - latex

I am using the Ph.D. dissertation .cls file. When I create a paragraph there is a misalignment in the paragraph page number in TOC.
Below is the minimal code:
\documentclass[final]{USC-Thesis_Minimal}
\usepackage[lofdepth,lotdepth,caption=false]{subfig}
\begin{document}
\title{Some title}
\author{Some Name}
\major{Some Engineering}
\month{May}
\year{2019}
\setcounter{secnumdepth}{5}
\setcounter{tocdepth}{5}
\maketitle
% Table Of Contents
\cleardoublepage\phantomsection
\renewcommand{\contentsname}{Table of Contents}
\tableofcontents
% List of tables
\listoftables
% List of figures
\listoffigures
% Begin Body
\mainmatter
\chapter{Chapter 1}
\section{A very long section, very long text section}
\subsection{A very long subsection, very long text subsection}
\subsubsection{A very long subsubsection Very long text subsubsection}
\paragraph{A long paragraph}
\end{document}
Below is the relevant part of the cls file.
%Margins of Table of Contents - so that the page listings for toc do
%not align with page number
\cftsetrmarg{0.7in}
\newlength{\numtomarg}
\setlength{\numtomarg}{0.2in}
\renewcommand{\cftchapafterpnum}{\hspace{\numtomarg}\mbox{}}
\renewcommand{\cftsecafterpnum}{\hspace{\numtomarg}\mbox{}}
\renewcommand{\cftsubsecafterpnum}{\hspace{\numtomarg}\mbox{}}
\renewcommand{\cftsubsubsecafterpnum}{\hspace{\numtomarg}\mbox{}}
\renewcommand{\cftfigafterpnum}{\hspace{\numtomarg}\mbox{}}
\renewcommand{\cftsubfigafterpnum}{\hspace{\numtomarg}\mbox{}}
\renewcommand{\cfttabafterpnum}{\hspace{\numtomarg}\mbox{}}
\renewcommand{\cftsubtabafterpnum}{\hspace{\numtomarg}\mbox{}}
I couldn't find an alternative for the paragraph. Similar to:
\renewcommand{\cftparagraphafterpnum}{\hspace{\numtomarg}\mbox{}}
Here is the link to the class file. Can somebody please help me to fix this issue?

Using the below LaTeX command did the trick:
\renewcommand{\cftparaafterpnum}{\hspace{\numtomarg}\mbox{}}

Related

Adding list of figure/list of table pushing away the mitoc of one chapter to another in latex

I am using an existing template in Latex and trying to modify it according to my needs. This is how the code looks like and everything works fine, minitoc also works fine.
% Instead of "de" you can also use "en" if the work is written in English
% Either "darkstyle" or "lightstyle"
\documentclass[en, darkstyle]{unirostock}
% For the sources, more information https://de.overleaf.com/learn/latex/Bibliography_management_with_biblatex
\usepackage[backend=biber,style=ieee,maxbibnames=99,backref=true,citestyle=ieee]{biblatex}
\addbibresource{lit.bib}
% creative-commons: Creative Commons license, attribution - redistribution permitted under the same conditions
% private: publication and modification only after consultation with the author
\license{creative-commons}
\author{}
\enrolmentnumber{123456789} % Matrikelnummer
\title{}
\type{}
\course{}
\workperiod{}
\supervisor{}
\primaryreviewer{}
\secondaryreviewer{} % Falls es keinen gibt, einfach weglassen
\faculty{}
\institute{}
\workinggroup{}
\begin{document}
\maketitle
\makelicense
\pagenumbering{Roman}
\setstretch{1.263}
\pagenumbering{gobble}
\include{chapter/abstract}
\pagenumbering{arabic}
\clearpage
\tableofcontents
\clearpage
\include{chapter/introduction.tex}
\include{chapter/background.tex}
\include{chapter/analysis.tex}
\include{chapter/implmentation.tex}
\include{chapter/evaluation.tex}
\include{chapter/conclusion-future-work.tex}
% List of figures
\clearpage
\phantomsection
\addcontentsline{toc}{chapter}{List of Figures}
\listoffigures
% List of tables
\clearpage
\phantomsection
\addcontentsline{toc}{chapter}{List of Tables}
\listoftables
\cleardoublepage
\phantomsection
\addcontentsline{toc}{chapter}{Bibliography}
\printbibliography
\clearpage
\include{chapter/declaration}
\end{document}
But if I want to add the list of figures and list of tables before the chapter, like this
\clearpage
\tableofcontents
% List of figures
\clearpage
\phantomsection
\addcontentsline{toc}{chapter}{List of Figures}
\listoffigures
% List of tables
\clearpage
\phantomsection
\addcontentsline{toc}{chapter}{List of Tables}
\listoftables
\clearpage
\include{chapter/introduction.tex}
\include{chapter/background.tex}
\include{chapter/analysis.tex}
\include{chapter/implmentation.tex}
\include{chapter/evaluation.tex}
\include{chapter/conclusion-future-work.tex}
then the minitoc of first chapter is showing nothing.
and it is appearing on third chapter.
That means minitoc of one chapter is appearing after two chapter and it continues.
This is the code of minitoc.
\newcommand{\printmyminitoc}[1]{%
\vspace{-2cm}%
\noindent\hspace{-4.5cm}%
\colorlet{black}{white}%
\begin{tikzpicture}
\node[rounded corners,align=left,fill=uniblau, blur shadow={shadow blur steps=5}, inner sep=5mm]{%
\hspace{3.8cm}
\color{white}%
\begin{minipage}{8.5cm}%minipage trick
\hypersetup{linkcolor=white}
\minitoc
\hypersetup{linkcolor=uniblau}
\end{minipage}};
\end{tikzpicture}
\vspace{1cm}%
}
Could someone help about this issue. I am almost new in Latex.

Add line numbers to Rmarkdown text and have it restart on each page

I am knitting my markdown file and I have included the following in my header, which produces line numbers in my text. How can I make the numbering reset at the beginning of each new page?
header-includes:
\usepackage{lineno}
\linenumbers
The lineno package has an option to restart the line number automatically for each page:
\usepackage[pagewise]{lineno}
Minimal working example:
\documentclass{article}
\usepackage[pagewise]{lineno}
\linenumbers
\usepackage{lipsum}
\begin{document}
\lipsum
\end{document}

toc links point to wrong pages

i have a simple tex file. when i compile it with $ pdflatex test.tex it generates a pdf. the table of contents has clickable links but they don't work!
the page numbering is correct, but when i click a line it directs me to the wrong page.
has anyone an idea how i can fix it?
here is my code:
\documentclass[12pt,titlepage]{scrartcl}
\usepackage[nottoc,numbib]{tocbibind}
\usepackage{graphicx}
\usepackage[section]{placeins}
\usepackage{float}
\usepackage{amsmath}
\usepackage[autostyle=false,german=quotes]{csquotes} %% for \enquote{}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\usepackage[]{hyperref}
\title{test}
\author{me}
\date{\today}
\begin{document}
\pagenumbering{roman}
\begin{titlepage}
\maketitle
\end{titlepage}
\setcounter{section}{-1}
\section[]{Abstract}
blabla bla
\newpage
\tableofcontents
\newpage
\pagenumbering{arabic}
\part{part1}
\setcounter{section}{-1}
\section[]{Abstract}
\section{sec a 1}
bla bla
\subsection{sec a 1.1}
bla blub
\section{sec a 2}
\newpage
\part{part2}
\setcounter{section}{-1}
\section[]{Abstract}
\section{sec b 1} % the toc entry for this section points to page 1 but it is on page 2
blub blub
\section{sec b 2} % the toc entry for this section points to page 1 but it is on page 2
blub blub
\subsection{sec b 2.1} % the subsection in the toc points to the right 2nd page!
\end{document}
and here you see the toc. as you can see, the mouse over hint tells that the link points to page 1 but the number on the right says it is on page 2.
thanks in advance.
Whenever you reuse a hyperref counter that could make its way into a link, duplicate hyperlinks occur. Visually this is fine, but internal to the document, the jumps are ambiguous. So, you need to provide hyperref some help.
The easiest way to circumvent this problem and provide hyperref some assistance is to add to your preamble
\renewcommand{\theHsection}{\thepart.section.\thesection}
after loading hyperref. The above prepends \thepart. to the hyperref-related \section link. Since the re-use of \section counters is based on your use of \parts, this addition will make for a unique link and remove ambiguous destinations.

How can I get page numbers to link to the table of contents in latex?

I've seen a pdf LaTeX document where the page numbers at the bottom of the page are hyperref links, and clicking them causes you to jump to the contents table. I don't have the tex file and couldn't work out how it's done from the hyperref package. Can anyone help?
You could set an anchor at the toc and redefine \thepage to link to it. Here's an example:
\documentclass{report}
\usepackage[colorlinks]{hyperref}
\renewcommand*{\contentsname}{\hyperlink{contents}{Contents}}
\renewcommand*{\thepage}{\hyperref[contents]{\arabic{page}}}
\begin{document}
\tableofcontents
\chapter{One}
Text
\end{document}
If you use babel and wish to redefine \contentsname, use the \addto command of babel or redefine \contentsname after \begin{document}.
Have you tried defining the page numbering using this?
\pagestyle{myheadings}
\markright{ ... }
where \markright specifies the page number with a link to the content page.
Here is how I did it
% !TEX encoding = UTF-8 Unicode
% !TEX TS-program = xelatex
\documentclass[UTF8, english]{article}
\usepackage{lipsum} %% produce dummy texts
\usepackage{hyperref}
\usepackage[pagestyles]{titlesec}
\newpagestyle{article}{
\setfoot
%% even pages
[]
[\footnotesize \hyperlink{toc}{\thepage}]
[]
%% odd pages
{}
{\footnotesize \hyperlink{toc}{\thepage}}
{}
}
\begin{document}
\title{example}
\date{}
\author{author}
\maketitle
\pagenumbering{roman}
\setcounter{tocdepth}{2}
\addtocontents{toc}{\protect\hypertarget{toc}{}}
\tableofcontents
\newpage
\pagenumbering{arabic}
\pagestyle{article}
\section{A}
\lipsum[1]
\subsection{a}
\lipsum[2]
\subsection{b}
\lipsum[3]
\subsection{c}
\lipsum[4]
\section{B}
\lipsum[5]
\subsection{d}
\lipsum[6]
\subsection{e}
\lipsum[7]
\section{C}
\lipsum[8]
\subsection{f}
\lipsum[9]
\subsection{g}
\lipsum[10]
\subsection{h}
\lipsum[11]
\end{document}
you can of course customize the link text back to table of contents however you like in the preamble, please read documentation of titlesec for more details.

No page number for divider pages in LaTeX

I have a report in LaTeX, and i have used the following commands to create my Appendix, however, my lecturer states that any divider pages should be unnumbered.
\documentclass{report}
\usepackage{appendix}
\begin{document}
\include{chap1}
\include{appendix}
\end{document}
Then in appendix.tex
\appendix
\pagestyle{empty}
\appendixpage
\noappendicestocpagenum
\addappheadtotoc
This creates the Appendices divider page, but still puts a page number on it in the footer. There is no page number in the TOC, as expected.
How can I remove it from the footer?
I looked at the appendix.sty source, and I see the problem: line 74, in the definition of \#chap#pppage, issues a \thispagestyle{plain} command, thus overriding your \pagestyle{empty} for this page. The inelegant but direct way to fix this is to redefine the command without this line - issue the following code after importing the package.
Revised, tested version
\documentclass{report}
\usepackage{appendix}
%==== The action ================
\makeatletter
\def\#chap#pppage{%
\clear#ppage
\if#twocolumn\onecolumn\#tempswatrue\else\#tempswafalse\fi
\null\vfil
\markboth{}{}%
{ \centering \interlinepenalty \#M
\normalfont \Huge \bfseries \appendixpagename\par}%
\if#dotoc#pp\addappheadtotoc\fi
\vfil\newpage
\if#twoside
\if#openright \null \thispagestyle{empty}\newpage\fi
\fi
\if#tempswa \twocolumn\fi
}
\makeatother
%==== Back to the document ========
\begin{document}
\tableofcontents
\chapter{Blah}
Rhubarb, rhubarb, rhubarb.
\appendix
\pagestyle{empty}
\appendixpage
\noappendicestocpagenum
\addappheadtotoc
\chapter{Boff}
Cabbages, cabbages, cabbages.
\end{document}
The TeX FAQ might come in handy here:
I asked for “empty”, but the page is numbered
If you use \pagestyle{empty} and you
find some pages are numbered anyway,
you are probably encountering one of
the style decisions built into the
standard LaTeX classes: that certain
special pages should always appear
with \pagestyle{plain}, with a page
number at the centre of the page foot.
The special pages in question are
those (in article class) containing a
\maketitle, or (in book and report
classes) \chapter or \part commands.
The simple solution is to reissue the
page style after the command, with
effect for a single page, as, for
example (in article):
\maketitle
\thispagestyle{empty}
So give adding \thispagestyle{empty} after your \appendix a try.
try changing \pagestyle{empty} to \thispagestyle{empty} and put it after \addappheadtotoc.
Try instead:
\pagenumbering{gobble}
\begin{appendices} \newpage
\clearpage
\pagenumbering{arabic}
\addtocounter{page}{100}
\tableofcontents
\newpage
*Special thanks to https://tex.stackexchange.com/questions/6639/removing-page-numbers-but-not-headers!

Resources