Text FormattingAddtocontents not adding line to the top of page

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
ririya
Posts: 2
Joined: Sun Mar 29, 2020 5:48 am

Addtocontents not adding line to the top of page

Post by ririya »

I'm getting a weird behavior where addtocontents is not adding the line to the top of the page. Basically it's supposed to be a header which indicates figure and page on my list of figures. How can I fix this?

Code: Select all

\addcontentsline{toc}{part}{LIST OF TABLES}
\listoftables
\addtocontents{lot}{Table~\hfill Page \par}

\newpage
\addcontentsline{toc}{part}{LIST OF FIGURES}
\listoffigures
\addtocontents{lof}{Figure~\hfill Page \par}
\newpage
example2.png
example2.png (89.64 KiB) Viewed 2460 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

kaiserkarl13
Posts: 707
Joined: Tue Mar 25, 2008 5:02 pm

Addtocontents not adding line to the top of page

Post by kaiserkarl13 »

It has to do with when each file is read and written. Try this:

Code: Select all

\makeatletter
  \immediate\write\@auxout{\noexpand\@writefile{lof}{%
    \figurename~\hfill Page \par}%
  }%
A better way would be to redefine the list of figures; I had a similar document that I solved by doing this:

Code: Select all

\renewcommand\listoffigures{%
    \if@twocolumn
      \@restonecoltrue\onecolumn
    \else
      \@restonecolfalse
    \fi
    \chapter{\listfigurename}%
      \@mkboth{\MakeUppercase\listfigurename}%
              {\MakeUppercase\listfigurename}%
    {\normalsize\parindent\z@\textbf{\figurename\hfill Page}\par}%
    {\hyphenpenalty=\list@hyphen@penalty\@starttoc{lof}}%
    \if@restonecol\twocolumn\fi
}
User avatar
Ijon Tichy
Posts: 640
Joined: Mon Dec 24, 2018 10:12 am

Addtocontents not adding line to the top of page

Post by Ijon Tichy »

Note: The shown code depends on the used document class and packages. It can destroy several things if you do not use class report or class book or if you use a packages, that already redefines \listoffigure.

BTW: LoF and LoT at part level is very unusual. For book and report level chapter (for the \addcontentsline command in ririya's post) would be correct. If this is neither book nor report see my note above.

A Infominimal working example would help us to make better suggestions.
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:
Post Reply