Generalfixing the horizontal space of section headings

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
voodojoe
Posts: 2
Joined: Wed Dec 31, 2008 10:16 pm

fixing the horizontal space of section headings

Post by voodojoe »

In my document I have section headings that looks like this:

1. Section
1.1 Subsection
1.1.1 Subsubsection
1.1.1.1 Subsubsubsection

I want to fix the "indent" of all the "section" headings so they all line up.
what I want to do is something like this:

\makebox[8mm][l]{\thesection.\thesubsection.} ...

So all the section headings would start exactly 8mm from the left margin or whatever.

I tired the titlesec package, but the sep option lets me set the distance between the numbers and the title, but that space is kind of dynamic unless i use a monospaced font, which I don't want to do.

any ideas?

thanks

Recommended reading 2024:

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

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

phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

fixing the horizontal space of section headings

Post by phi »

If you use a standard document class, you can redefine an internal macro:

Code: Select all

\documentclass[english]{article}

\usepackage{babel}
\usepackage{blindtext}

\makeatletter
\def\@seccntformat#1{\hb@xt@ 36pt{\hfil\csname the#1\endcsname}\quad}
% \def\@seccntformat#1{\llap{\csname the#1\endcsname\quad}}
\makeatother


\begin{document}

\tableofcontents

\blinddocument

\end{document}
The second definition prints the section numbers in the margin.
voodojoe
Posts: 2
Joined: Wed Dec 31, 2008 10:16 pm

Re: fixing the horizontal space of section headings

Post by voodojoe »

Ahh thanks, after a bit of searching I figured out what each part of the command means except for the "\hb@xt@" part.

what does that bit of code do?
phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

fixing the horizontal space of section headings

Post by phi »

\hb@xt@ is an "abbreviation" for \hbox to, which creates a horizontal box of the given width. If you don't want to use these low-level primitives, you can also use LaTeX's \makebox command:

Code: Select all

\makebox[36pt][r]{...}
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

fixing the horizontal space of section headings

Post by Stefan Kottwitz »

Hi,

it's defined this way in latex.ltx:

Code: Select all

\def\hb@xt@{\hbox to}
Stefan
LaTeX.org admin
mulander
Posts: 5
Joined: Wed Jan 28, 2009 2:28 pm

Re: fixing the horizontal space of section headings

Post by mulander »

Hi,

as an addition to the above I would like to align the numbering in the margin to the left. Is it possible?

Thanks in advance!

/MIcke
phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

Re: fixing the horizontal space of section headings

Post by phi »

please reread my first posting in this thread.
mulander
Posts: 5
Joined: Wed Jan 28, 2009 2:28 pm

Re: fixing the horizontal space of section headings

Post by mulander »

I´ve done that but I can´t get it right. After applying the code in your first post it looks like this:

____1__Text
__1.1__Text
1.1.1__Text

But I want it to look like this:
1______Text
1.1____Text
1.1.1__Text
phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

fixing the horizontal space of section headings

Post by phi »

OK, then use:

Code: Select all

\def\@seccntformat#1{\rlap{\hskip-36pt\csname the#1\endcsname}}
mulander
Posts: 5
Joined: Wed Jan 28, 2009 2:28 pm

Re: fixing the horizontal space of section headings

Post by mulander »

Great! :D

Thanks!
Post Reply