LaTeX forum ⇒ Graphics, Figures & TablesHow do I line up the text in my table of contents? Topic is solved

Information and discussion about graphics, figures & tables in LaTeX documents.
latex_git
Posts: 4
Joined: Sat Sep 28, 2024 4:55 am

How do I line up the text in my table of contents?

Postby latex_git » Sat Sep 28, 2024 5:07 am

So I've include a sample for the document below and if you look at the table of contents, you'll see that the section numbers are nicely left aligned but the text following these numbers is not vertically aligned - its starting column position depends on the length of the section number (which varies).
Can someone advise what to do so I get the text in the table of contents lined up vertically please?

Thank you



\documentclass{amsart}
% Theorem like environments
\newtheorem{theorem}{Theorem}
\theoremstyle{plain}
\newtheorem{acknowledgement}{Acknowledgement}
\newtheorem{algorithm}{Algorithm}
% quite a few of these ...
\numberwithin{equation}{section}

\begin{document}
\begin{titlepage}
Fabulous title for my great output (it's actually got better formatting than this but ...
\end{titlepage}
\newpage
\section*{Preface}
%... some stuff
\newpage
\tableofcontents
\newpage
% the main stuff
\section{First section}
some wise words
\subsection{A subsection}
some lesser thoughts
\section{Second section}
More wisdom.
\subsection{Another subsection}
just quietly
\section{my third section}
quite confident here
\subsection{yet another subsection}
\par
and it continues for quite a bit (lots of sections, sub, equations, a few figures, a bibliography ...
until ...
\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics
User avatar
Stefan Kottwitz
Site Admin
Posts: 10220
Joined: Mon Mar 10, 2008 9:44 pm

How do I line up the text in my table of contents?

Postby Stefan Kottwitz » Sat Sep 28, 2024 2:20 pm

Hi,

welcome to the forum!

I see that you are using the amsart document class. This is for publishing in American Mathematical Society (AMS) journals. If you publish there, you should keep their standard table of contents layout instead of changing it. If you don't publish in AMS journals, you don't need that class, but you can use article or scrartcl instead. I would use scrartcl because it is very modern and maintained, with a vast number of options to customize it. The table of contents would be aligned by default.

For mathematics, you can load the amsmath and amsthm packages.

Stefan
LaTeX.org admin

latex_git
Posts: 4
Joined: Sat Sep 28, 2024 4:55 am

How do I line up the text in my table of contents?

Postby latex_git » Sun Sep 29, 2024 1:12 am

Hi Stefan,
Thanks.
I'm a little lost at this point.
- The article class gives a nice toc, but several figures will need fixing (they've moved left) and I get a blank page before the title page (I borrowed a complex command to generate the title page and don't understand the detail of it).
- scrartcl plus amsthm packages (amsmath was already there) gives about 20 error messages like the two posted at the bottom.
- I was hoping to finish soonish which wouldn't really leave a lot of time to improve my very basic latex knowledge.

Perhaps I will just live with the toc as is.
Kind regards


! Undefined control sequence.<argument> \tocsection{}{}{Preface} ...e {section}{\tocsection {}{}{Preface}}{1}{}
...
! Undefined control sequence.<argument> \tocsubsubsection{}{1.1.1}{[content removed]}}{8}{}

User avatar
Stefan Kottwitz
Site Admin
Posts: 10220
Joined: Mon Mar 10, 2008 9:44 pm

How do I line up the text in my table of contents?  Topic is solved

Postby Stefan Kottwitz » Sun Sep 29, 2024 2:06 am

latex_git wrote:several figures will need fixing (they've moved left) and I get a blank page before the title page


You can use the \centering command inside the figure environment. Or, once, in the preamble:

\makeatletter
\g@addto@macro\@floatboxreset{\centering}
\makeatother


Regarding the blank page, there's probably a reason that I can see when you post the code here (reduced, without too much content).

latex_git wrote:scrartcl plus amsthm packages (amsmath was already there) gives about 20 error messages like the two posted at the bottom.
! Undefined control sequence.<argument> \tocsection{}{}{Preface} ...e {section}{\tocsection {}{}{Preface}}{1}{}
! Undefined control sequence.<argument> \tocsubsubsection{}{1.1.1}{[content removed]}}{8}{}


That's because of amsart commands in the old table of contents (.toc) file. If you do another LaTeX run and re-generate the .toc file, the errors will disappear.

Also, as amsart is old :-) there's an solution from 14 years ago here: Formatting the amsart table of contents.

Anyway, don't worry too much about TOC alignment, because your content matters. In any case, we gladly help here with such and more LaTeX questions.

Stefan
LaTeX.org admin

latex_git
Posts: 4
Joined: Sat Sep 28, 2024 4:55 am

How do I line up the text in my table of contents?

Postby latex_git » Sun Sep 29, 2024 3:03 am

Thanks Stefan!
- the old solution worked (I did comment out the following line to suppress an error \setcounter{tocdepth}{3}).
- I will have a look at your more up to date solutions too.
Kind regards

latex_git
Posts: 4
Joined: Sat Sep 28, 2024 4:55 am

How do I line up the text in my table of contents?

Postby latex_git » Mon Sep 30, 2024 3:58 am

Hi again Stefan,
just to let you know, I ended up going with the scrartcl document class - all your suggestions worked very well, the issue with the title page command was just some unnecessary newlines.
Thanks again for your awesome help!
Kind regards


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 18 guests