GeneralRedefine ToC entry style without packages

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
c1b3rz
Posts: 6
Joined: Fri Sep 28, 2012 8:01 pm

Redefine ToC entry style without packages

Post by c1b3rz »

I've redefined the section, subsection and subsubsection styles in my preamble as

Code: Select all

\renewcommand\section{%
  \@startsection{section}{1}
                {\z@}%
                {-3.5ex \@plus -1ex \@minus -.2ex}%
                {2.3ex \@plus.2ex}%
                {\normalfont\normalsize\bfseries\uppercase}%
}

\renewcommand\subsection{%
  \@startsection{subsection}{2}
                {\z@}%
                {-3.25ex\@plus -1ex \@minus -.2ex}%
                {2.3ex \@plus.2ex}%
                {\normalfont\normalsize\MakeUppercase}
}

\renewcommand\subsubsection{%
  \@startsection{subsubsection}{3}
                {\z@}%
                {-3.25ex\@plus -1ex \@minus -.2ex}%
                {2.3ex \@plus.2ex}%
                {\normalfont\normalsize\bfseries}
}
And I want this style to be applied to the ToC. I've tried using tocloft but it messes around with other stuff. How could I do it without the use of any package?

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

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Redefine ToC entry style without packages

Post by localghost »

Just for information to other users for awareness of possibly already existing solutions. The question has also been posted to {TeX} SX. Please read what our administrator thinks about that.
Board Rules wrote:A crossposting is always contra-productive. But there is nothing really against it as long as it is mentioned. This means that a direct link has to be added. So other users who want to help are preserved from double efforts and waste of time.
This kind of x-posting represents a direct violation of our rules and has to be prevented in future questions.
c1b3rz wrote:[…] I've tried using tocloft but it messes around with other stuff. How could I do it without the use of any package?
How do your trials look like? Any good reasons against a package (also for customization of headings)?


Thorsten
c1b3rz
Posts: 6
Joined: Fri Sep 28, 2012 8:01 pm

Redefine ToC entry style without packages

Post by c1b3rz »

localghost wrote:How do your trials look like? Any good reasons against a package (also for customization of headings)?

I'm actually stuck right now.
What I'm writing now is kind of a "frankenstein", with pieces of code caught from here and there. I am not professional or LaTeX mastermind, so I just search for anything that looks like what I need and try to modify/adapt that.

When I tried using the tocloft package I got an error when compiling if I try making anything uppercase either by \MakeUppercase or \uppercase. Funny thing is that even when I define how the section looks at the body (with the aforementioned piece of code) I get an error with \MakeUppercase, whilst no error when \uppercase (hence the choice).

Since I don't know how all the packages behave together and what is causing the errors I had before, I decided to try my luck without them. So far I couldn't really try anything because I didn't find anything similar, so...
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Redefine ToC entry style without packages

Post by localghost »

c1b3rz wrote:[…] What I'm writing now is kind of a "frankenstein", with pieces of code caught from here and there. […]
The conceivably worst method to write a document even if you want to customize some settings. Targeted questions would be more helpful.

When you are asked to show your own efforts, this always means that you have to provide a self-contained and minimal example in order to give an adequate problem description instead of some vague descriptions. Since you are not new to the forum, it can be assumed that you already know this.
c1b3rz
Posts: 6
Joined: Fri Sep 28, 2012 8:01 pm

Re: Redefine ToC entry style without packages

Post by c1b3rz »

Dear localghost,
I just cared enough to answer your question, although it was completely unrelated to my primary question.

If you want to be all bigot about this, let get things straight:

1 - I've searched the forum and nothing addressed, in any way, my doubt.
2 - Ergo, I had to post a new thread, and did so with a clear and objective title, explaining what I wanted to do.
3 - Since I'm not addressing a PROBLEM, but a "HOW TO", there is clearly no need nor point in providing a MWE.

Concerning the conciseness of my question:

I have defined a section, subsection and subsubsection style for the body, and I'd like to know how to apply this same style to the entries at the ToC without the use of packages.
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Redefine ToC entry style without packages

Post by Johannes_B »

A minimal example (mwe) is a great thing, you can be sure, that we all see the same, and so, all have the same base. This is especially true with our writelatex-thingie. This MWE also provides the helpers with some basic stuff to work on and test possible solutions.

I read your question but i am not sure what you are trying to achieve.

Concerning the tocloft-problem: Maybe there was some small mistake, you just didn't see.

Best regards
Johannes
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Redefine ToC entry style without packages

Post by localghost »

c1b3rz wrote:[…] If you want to be all bigot about this, let get things straight:

[…]

3 - Since I'm not addressing a PROBLEM, but a "HOW TO", there is clearly no need nor point in providing a MWE. […]
This smug attitude is not helpful and exactly the reason why you didn't yet get what you call a "How-To" neither here nor on {TeX} SX. If you are not able to do your homework, please don't expect qualified answers. But now that you have found a partial solution by yourself, the rest may come gradually.

With a discussion about the sense of a minimal example you are wasting not only your time, but also the time of those who try to help but can't because there is a lack of information. If you think that this is the way to go, keep it up.
c1b3rz
Posts: 6
Joined: Fri Sep 28, 2012 8:01 pm

Redefine ToC entry style without packages

Post by c1b3rz »

Well, found a solution :)

At first I tried

Code: Select all

\let\stdl@section\l@section
\renewcommand*{\l@section}[2]{%
  \stdl@section{\normalfont\normalsize\bfseries\uppercase{#1}}
{\normalfont\normalsize\bfseries\uppercase{#2}}}
Did the deal. The same could be done to subsection and subsubsecion ;) There is only a small detail left: special characters don't get uppercase, such as:

Code: Select all

á é í ó ú à õ ô
Then it came to my attention that there is a problem with \MakeUppercase and hyperref package. I removed the hyperref package and changed all the \uppercase for \MakeUppercase and it works as charm. The codes I actually used to modify the ToC appearance is:

Code: Select all

\let\stdl@section\l@section
\renewcommand*{\l@section}[2]{%
  \stdl@section{\MakeUppercase{#1}}{#2}}

\let\stdl@subsection\l@subsection
\renewcommand*{\l@subsection}[2]{%
  \stdl@subsection{\normalfont\MakeUppercase{#1}}{#2}}

\let\stdl@subsubsection\l@subsubsection
\renewcommand*{\l@subsubsection}[2]{%
  \stdl@subsubsection{\bfseries{#1}}{#2}}
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Redefine ToC entry style without packages

Post by localghost »

c1b3rz wrote:Well, found a solution […]
Thanks for sharing.
Post Reply