Text FormattingAligned Numbers in Margin

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
Laurentius
Posts: 132
Joined: Wed Feb 11, 2009 11:38 pm

Aligned Numbers in Margin

Post by Laurentius »

I'm using \marginpar to give section numbers from a certain edition and so want them to be aligned towards the text and have used

Code: Select all

\reversemarginpar
\marginpar{\hfill 4}
and I was just wondering whether this is the best solution, since it is somewhat cumbersome to have to fill in \hfill every time. No big problem, but if there happened to be an easy and better solution, I'd be glad to know.

Recommended reading 2024:

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

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

cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Aligned Numbers in Margin

Post by cgnieder »

Could you elaborate that a bit more and best post a Infominimal working example? At least to me it's not totally clear what you want...

It seems to, though, that the titlesec package would be what you need.

Code: Select all

\documentclass{scrartcl} 
\usepackage{titlesec}
\usepackage{kantlipsum}% create dummy text

\titleformat{\section}
{\normalfont\Large\sffamily\bfseries}
{\llap\thesection}{1.5pc}{}
\titlespacing{\section}
{-1.5pc}{2pc plus .1ex minus .2ex}{1pc}

\begin{document}

\section{A Test}
\kant[1]

\section{Yet Another Test}
\kant[2]

\end{document}
Regards
site moderator & package author
Post Reply