Sign up ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Using titlesec and/or komascript how do I format all headings so the number is left aligned in the margin, the title to the right, with a horizontal rule underneath it all (from margin to text width edge).

What's left of my hair is about to come out :(

|                             |
| 3.1  Section Title          |
| -------------------------   |
|      Text width paragraph   |
|      Blah blah blah blah    |
|                             |

  >-<  >------------------<
   |                |
   `-- Margin       ` Text
share|improve this question
have you seen Theorem Name/Numbering in Margin or How can I align section titles and list environments in the left margin? you should be able to adapt it to include titlerule which will give you the horizontal line... –  cmhughes Feb 14 '13 at 22:41
@cmhughes yes (and many more similar answers), but I haven't found anything that does left alignment and horizontal rule. I'm still working on it, just hoping a guru will through me a bone. –  h0tw1r3 Feb 14 '13 at 22:46

2 Answers 2

up vote 7 down vote accepted

Here's one possibility using titlesec:





\section{A Test Section with a Short Title}
\section{A Test Section with a Long Title Spanning More than One Line}


enter image description here

Of course, you can adjust the value for \mylen to get the desired positioning for the numbers; for example, using


you get

enter image description here

share|improve this answer
To understand your answer better, would you kindly elaborate how your solution works (except the rule part)? –  blackened Sep 15 at 17:33

Caveat: margin box size for number is not dynamic.

\titlespacing{\section}{-3em}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}
\chapter{Lorem Ipsem}
\section{Lorem Ipsum}
\section{Lorem Ipsum}
share|improve this answer
Also consider using \titlespacing*{...} if you wish to prevent the paragraph following the section from being indented. –  davidg Dec 13 '13 at 5:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.