I am in the process of switching a large document to lualatex for various reasons, and I noticed an issue with the table of contents when the packages fontspec and titletoc are loaded together, AND the font size is larger than the default 10pt.

When the page number to display in the TOC is above 3 digits, it protudes over the right margin.

A quick search have yielded this similar issue (http://www.macfreek.nl/memory/LaTeX_package_conflicts#XeTeX_and_titletoc) but it is with XeTeX, so I am not sure it is related.







    \chapter{Chapter 1}
    \section{Section 1.1}
    \section{Section 1.2}
    \section{Section 1.3}

    \chapter{Chapter 2}
    \section{Section 2.1}
    \section{Section 2.2}
    \section{Section 2.3}

    \chapter{Chapter 3}
    \section{Section 3.1}
    \section{Section 3.2}
    \section{Section 3.3}

This yields this result on the first page. Notice how the 3-digits page numbers extend outside of the text area (for sections lines only, not chapter lines though...) Erroneous result

Changing to 10pt, or commenting either \usepackage{fontspec} or \usepackage{titletoc} removes the issue.

With 10pt: enter image description here

12pt, no fontspec: enter image description here

12pt, no titletoc: enter image description here

1 Answer 1


I guess your question is "What's going on here?"

Loading fontspec changes the current font from Computer Modern to Latin Modern. And the length governing the width of the page number in the ToC, given by \@pnumwidth, is defined in terms of the font using ems.

To isolate the problem, compile the following document with either XeLaTeX or LuaLaTeX:


\showthe\nofontspecem% Length of 1em in Computer Modern


\showthe\fontspecem% Length of 1em in Latin Modern


The .log shows

> 11.74988pt.
l.5 \showthe\nofontspecem
                    % Length of 1em in Computer Modern


> 10.0pt.
l.11 \showthe\fontspecem
                    % Length of 1em in Latin Modern

So, Computer Modern has a slightly wider em under 12pt font than that of Latin Modern. As such \@pnumwidth has a little more room to place the ToC page numbers, not making them spill into the right margin.

How can you fix this? Provide an adequate value for \@pnumwidth that is larger than the default of 1.55em, so 2em, or something non-font-related, like 25pt. With titletoc loaded, simply issue

  • I see.. I would have thought this was detected somehow automatically.. Thanks for guessing the question and answering it ! I think I've managed to get rid of all warnings now =)
    – AElfwine
    Nov 4, 2015 at 1:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .