GeneralModifying Layout of ToC

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
MeineKekse
Posts: 6
Joined: Sat Mar 03, 2012 12:55 pm

Modifying Layout of ToC

Post by MeineKekse »

Hello,

I need to change the layout of my tableofcontents. The first problem is, that I included a section(called Vorwort) with the *-symbol in order to get ride of the number in front of it. But then in the tableofcontents "Vorwort" appears at the same height as all other section, beginning with a number. They are all aligned on the left side. How can I chnage this appearance so that the section Vorwort appears on the same height as the E from the section "Einleitung".

Furthermore as you can see on the image the section "Vorwort" has a roman page number. The thing is again, that all page numbers are aligned on the right side. I want the middle of the "I" from "Vorwort" to be on the same height as the middle of the "1" from the section "Einleitung".

Thanks for helping :)
Attachments
this is my table of contents
this is my table of contents
tableofcontents.JPG (14.74 KiB) Viewed 5144 times

Recommended reading 2024:

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

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

Stefan Kottwitz
Site Admin
Posts: 10348
Joined: Mon Mar 10, 2008 9:44 pm

Modifying Layout of ToC

Post by Stefan Kottwitz »

Hi,

welcome to the board!

A solution depends on the document class you are using and your packages and settings. It may be that all things in your document are default, but maybe not. For such questions it's usually goo to post a Infominimal working example, so the readers can see all settings and implement the desired change. In this special case it could be just some lines. Otherwise it's quite theoretical. I could give you a theoretical solution if code really doesn't matter. ;-)

Stefan
LaTeX.org admin
MeineKekse
Posts: 6
Joined: Sat Mar 03, 2012 12:55 pm

Modifying Layout of ToC

Post by MeineKekse »

Hi,

so I just created a minimal working example and left all packages i used in the file.(It's also uploaded as an atachment)

Code: Select all

\documentclass[12pt]{article}

%German language
\usepackage[english,ngerman]{babel}
\usepackage{ngerman}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

% Das Euro
\usepackage{eurosym}


%Gener layout
\usepackage{geometry}
\geometry{a4paper}
\geometry{left=3cm,top=2cm,bottom=2cm}

% Times New Roman
\usepackage{mathptmx}
\usepackage{setspace}
\setstretch{1.5}
\usepackage{titlesec}
\fontfamily{ptm}\selectfont

%C-Code
\usepackage{listings}
\usepackage{courier}
\usepackage{caption}
\usepackage{color}
\usepackage{xcolor}
\usepackage{MnSymbol}

% Grafics
\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage{picins}









\begin{document}
\section*{Vorwort}
\addcontentsline{toc}{section}{Vorwort}

\renewcommand{\thepage}{\Roman{page}}
\setcounter{page}{1} 
\thispagestyle{empty}
\newpage
\thispagestyle{empty}
\tableofcontents
\newpage


\renewcommand{\thepage}{\arabic{page}}
\setcounter{page}{1} 
\section{Einleitung}


\end{document}
Attachments
MWE.tex
(1013 Bytes) Downloaded 205 times
User avatar
Stefan Kottwitz
Site Admin
Posts: 10348
Joined: Mon Mar 10, 2008 9:44 pm

Modifying Layout of ToC

Post by Stefan Kottwitz »

Very good! It would be even better to make it without packages which obviously are not related to the problem, such as graphics packages.

A general approach for designing a table of contents would be using a package, such as tocloft, titletoc, or KOMA-Script features - I would always prefer a KOMA-Script class such as scrartcl over base classes.

The specific approach, as we can now see your class, is looking at the class code, what can be redefined. I noticed, here it's very simple. You could easily write

Code: Select all

\addcontentsline{toc}{section}{\numberline{}Vorwort}
after \section*{Vorwort}, so the correct space for the number is reserved, even without no given number.

Regarding the page numbers, they are of course right aligned. Later you will have numbers with two digits, should they also be centered in relation to the other numbers? I guess it would look strange. I would let the I right aligned for consistency, if all the other numbers stay right aligned. In such cases, just look at some good books, how they do the table of contents.

Stefan
LaTeX.org admin
MeineKekse
Posts: 6
Joined: Sat Mar 03, 2012 12:55 pm

Modifying Layout of ToC

Post by MeineKekse »

Hi, thanks very much.

When using scrartcl. My font changes to something different even when using the font packages. I need a font being similar to Times New Roman.

Code: Select all

\documentclass[12pt]{scrartcl}



% Times New Roman
\usepackage{mathptmx}
\usepackage{setspace}
\setstretch{1.5}
\usepackage{titlesec}
\fontfamily{ptm}\selectfont


\begin{document}
\section*{Vorwort}
\addcontentsline{toc}{section}{Vorwort}

\renewcommand{\thepage}{\Roman{page}}
\setcounter{page}{1} 
\thispagestyle{empty}
\newpage
\thispagestyle{empty}
\tableofcontents
\newpage


\renewcommand{\thepage}{\arabic{page}}
\setcounter{page}{1} 
\section{Einleitung}


\end{document}
User avatar
Stefan Kottwitz
Site Admin
Posts: 10348
Joined: Mon Mar 10, 2008 9:44 pm

Modifying Layout of ToC

Post by Stefan Kottwitz »

No problem, scrartcl just has some different (and meaningful) defaults. You can easyily change it:

Code: Select all

\setkomafont{sectioning}{\normalfont\bfseries}
\setkomafont{descriptionlabel}{\normalfont\bfseries}
The first line changes the sans-serif headings to serif (roman) headings which you know from the base classes, the second one does it for description labels.

Stefan
LaTeX.org admin
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Modifying Layout of ToC

Post by localghost »

Just for information to other users to be aware of possibly already existing solutions. The question has also been posted to the goLaTeX.
Post Reply