Article 14046 of comp.text.tex:
Newsgroups: comp.text.tex
Path: sifon!newsflash.concordia.ca!utcsri!utnut!cs.utexas.edu!sdd.hp.com!caen!batcomputer!cornell!uw-beaver!pauld
From: pauld@cs.washington.edu (Paul Barton-Davis)
Subject: Re: \section in margin (was Re: parboxes with rubber length in LaTeX)
Message-ID: <1993Jun3.204246.14752@beaver.cs.washington.edu>
Keywords: \section,\marginpar,\insert,\vtop, help!
Sender: news@beaver.cs.washington.edu (USENET News System)
Organization: Precipitating Pendulums Postal Party Poopers
References: <1993Jun2.145834.25228@informatik.uni-bremen.de> <2JUN199318372669@reg.triumf.ca> <C826yM.LCq@noose.ecn.purdue.edu>
Date: Thu, 3 Jun 93 20:42:46 GMT
Lines: 265


James Mccauley asked about a style to put \section in the margin.
Enclosed below is "marginhead.sty", which will do just that. It is not
well documented, since its operation is supposed to be largely
transparent. I use it mostly as the basis for my own "manual"
documentstyle, which looks exactly like the PostScript manuals.

Three new dimens you will care about: 

\textmargin 5cm     %% width of left margin for headings
\textmarginsep 10pt %% gap between marginal headings and text
\partoffset 13ex    %% amount of right shift for \part headings

The last one is there so that you can make \part headings look a
little more distinctive. See the PS books for an example.

-- paul
---- cut here -----------------------------------------------
%% marginhead.sty
%% Put section headings in the margin.
%%
%% Modifications of LaTeX style files which include the notice:
%% Copyright (C) 1985 by Leslie Lamport

%% based on a style file by Peter Ilieve (memex)
%% Paul Davis <davis%scr%sdr.slb.com@relay.cs.net> %% ah, sweet history
%% Paul Barton-Davus <pauld@cs.washington.edu>

%     *****************************************
%     *              SECTIONING               *
%     *****************************************
%
% \@startsection {NAME}{LEVEL}{INDENT}{BEFORESKIP}{AFTERSKIP}{STYLE}{LEFTSKIP}
%            optional * [ALTHEADING]{HEADING}
%    Generic command to start a section.  
%    NAME       : e.g., 'subsection'
%    LEVEL      : a number, denoting depth of section -- e.g., chapter=1,
%                 section = 2, etc.
%    INDENT     : Indentation of heading from left margin
%%		  In AFTERSKIP = 0 case if INDENT is zero then set
%%		  heading flush right in text margin, text is assumed to
%%		  be short and will not be broken.
%%		  If INDENT is non-zero then it is the width of a box
%%		  containing the heading in the text margin, this text can
%%		  be long.
%    BEFORESKIP : Absolute value = skip to leave above the heading.  
%                 If negative, then paragraph indent of text following 
%                 heading is suppressed.
%    AFTERSKIP  : if positive, then skip to leave below heading, else 
%                 negative of skip to leave to right of run-in heading.
%%		  if zero then Sun-style special controlled by INDENT.
%    STYLE      : commands to set style
%    LEFTSKIP	: Amount of \leftskip to use for this section.
%  If '*' missing, then increments the counter.  If it is present, then
%  there should be no [ALTHEADING] argument.
%  Uses the counter 'secnumdepth' whose value is the highest section
%  level that is to be numbered.

\def\@manstartsection#1#2#3#4#5#6{\if@noskipsec \leavevmode \fi
   \par \@tempskipa #4\relax
   \@afterindenttrue
   \ifdim \@tempskipa <\z@ \@tempskipa -\@tempskipa \@afterindentfalse\fi
   \if@nobreak \everypar{}\else
     \addpenalty{\@secpenalty}\addvspace{\@tempskipa}\fi \@ifstar
     {\@manssect{#3}{#4}{#5}{#6}}{\@dblarg{\@mansect{#1}{#2}{#3}{#4}{#5}{#6}}}}

\def\@mansect#1#2#3#4#5#6[#7]#8{\ifnum #2>\c@secnumdepth
  \def\@svsec{}\else 
  \refstepcounter{#1}\edef\@svsec{\csname the#1\endcsname\hskip 1em }\fi
  \@tempskipa #5\relax\@tempdima #3\relax
  \ifdim \@tempskipa>\z@ 
    \begingroup #6\relax
    \@manhangfrom{\hskip #3\relax\@svsec}{\interlinepenalty \@M #8\par}
    \endgroup
    \csname #1mark\endcsname {#7}%
    \addcontentsline{toc}{#1}{\ifnum #2>\c@secnumdepth \else
                             \protect\numberline{\csname the#1\endcsname}%
                                  \fi #7}%
  \else
    \ifdim \@tempskipa=\z@
      \ifdim \@tempdima=\z@
        \def\@svsechd{#6\llap{#8\hskip \textmarginsep}%
        \csname #1mark\endcsname {#7}%
        \addcontentsline{toc}{#1}{\ifnum #2>\c@secnumdepth \else
                             \protect\numberline{\csname the#1\endcsname}%
                                    \fi #7}}%
      \else
        \def\@svsechd{#6\@manmarginbox{#3}{\@svsec #8}%
        \csname #1mark\endcsname {#7}%
        \addcontentsline{toc}{#1}{\ifnum #2>\c@secnumdepth \else
                             \protect\numberline{\csname the#1\endcsname}%
                                    \fi #7}}%
      \fi
    \else
      \def\@svsechd{#6\hskip #3\@svsec #8\csname #1mark\endcsname {#7}%
      \addcontentsline{toc}{#1}{\ifnum #2>\c@secnumdepth \else
                             \protect\numberline{\csname the#1\endcsname}%
                                    \fi #7}}%
    \fi
  \fi
  \@manxsect{#5}}

\def\@manxsect#1{\@tempskipa #1\relax
      \ifdim \@tempskipa>\z@
       \par \nobreak
       \vskip \@tempskipa
       \@afterheading
    \else \global\@nobreakfalse \global\@noskipsectrue
      \ifdim \@tempskipa=\z@
        \everypar{\if@noskipsec \global\@noskipsecfalse
                    \clubpenalty\@M \hskip -\parindent
                    \begingroup \@svsechd \endgroup \unskip
                    \if@afterindent \hskip \parindent\fi
                  \else \clubpenalty \@clubpenalty
                    \everypar{}%
                  \fi}%
      \else
        \everypar{\if@noskipsec \global\@noskipsecfalse
                    \clubpenalty\@M \hskip -\parindent
                    \begingroup \@svsechd \endgroup \unskip
                    \hskip -#1
                  \else \clubpenalty \@clubpenalty
                    \everypar{}%
                  \fi}%
      \fi
    \fi\ignorespaces}

\def\@manssect#1#2#3#4#5{\@tempskipa #3\relax\@tempdima #1\relax
  \ifdim \@tempskipa>\z@
    \begingroup #4\@manhangfrom{\hskip #1}{\interlinepenalty \@M #5\par}%
    \endgroup
  \else
    \ifdim \@tempskipa=\z@
      \ifdim \@tempdima=\z@
        \def\@svsechd{#4\llap{#5\hskip \textmarginsep}}%
      \else
        \def\@svsechd{#4\@manmarginbox{#1}{#5}}%
      \fi
    \else
      \def\@svsechd{#4\hskip #1\relax #5}%
    \fi
  \fi
  \@manxsect{#3}}

%%
%% \@manhangfrom{TEXT} : Puts TEXT in a box, and makes a hanging indentation 
%%    of the following material up to the first \par.  Should be used
%%    in vertical mode.
%%
%%

\def\@manhangfrom#1{\setbox\@tempboxa=\hbox{#1}
      \hangindent 1\wd\@tempboxa\noindent\box\@tempboxa}

%% \@manmarginbox{WIDTH}{TEXT} : Sets TEXT in a box of width WIDTH and
%%	puts it in the left margin with a gap of \textmarginsep between
%%	it and the text. The baseline of the top line of TEXT is at the
%%	vertical position of the call of \@manmarginbox.
%%

%%
%% if you don't want \section headings set flush ragged left, use
%% \secleft
%%

\def\secleft{\def\@secleft{\relax}}

\def\@manmarginbox#1#2{\setbox\@tempboxa=\vtop{\hsize #1%
			\@ifundefined{@secleft}%
			 {\raggedleft #2}%
			 {\raggedright #2}}%
    \dp\@tempboxa=\z@\llap{\box\@tempboxa\hskip \textmarginsep}}

%%
%% Sectioning commands. Note the addition of \part: this gives us the
%% right number of levels for this type of headings layout.
%%

\def\partfont{\sf}
\def\sectionfont{\bf}
\def\ssectionfont{\rm}
\def\sssectionfont{\it}
\newdimen\secafterskip

\def\part{\@manstartsection
{part}{1}{\partindent}
{4.25ex plus 1ex minus .2ex}{3ex plus 1ex minus .2ex}{\large\partfont}}

\def\section{\@manstartsection
{section}{2}{\textmargin}
{-1.25ex plus -1ex minus -.2ex}{\z@}{\normalsize\sectionfont}}

\def\subsection{\@manstartsection
{subsection}{3}{\textmargin}
{-3.25ex plus -1ex minus -.2ex}{\z@}{\normalsize\ssectionfont}}

\def\subsubsection{\@manstartsection
{subsubsection}{4}{\textmargin}
{-2.25ex plus -1ex minus -.2ex}{\z@}{\normalsize\sssectionfont}}

\def\paragraph{\@manstartsection
{paragraph}{5}{\z@}
{-3.25ex plus 1ex minus .2ex}{\z@}{\normalsize\bf}}

\def\subparagraph{\@manstartsection
{subparagraph}{5}{\parindent}
{3.25ex plus 1ex minus .2ex}{-1em}{\normalsize\bf}}

\setcounter{secnumdepth}{1}
\def\thepart{\arabic{part}}

\def\partmark#1{\markboth {\ifnum \c@secnumdepth >\z@
      \thepart\ --- \fi #1}{}}

%%
%% Page dimensions
%%

\oddsidemargin -20pt
\evensidemargin -20pt
\newdimen\textmargin
\newdimen\textmarginsep
\newdimen\partindent
\newdimen\partoffset
\textmargin 5cm %% width of left margin for headings
\textmarginsep 10pt %% gap between marginal headings and text
\partoffset 13ex %% amount of right shift for \part headings
\partindent = -\textmargin
\advance\partindent by \partoffset

%% Now a redefined \@makecaption to put tag in heading margin

\long\def\@makecaption#1#2{%
 \@manmarginbox{\textmargin}{{\it #1:} #2}}%

\def\@outputpage{\begingroup\catcode`\ =10 \if@specialpage 
  \global\@specialpagefalse\@nameuse{ps@\@specialstyle}\fi
  \if@twoside 
    \ifodd\count\z@ \let\@thehead\@oddhead \let\@thefoot\@oddfoot
      \let\@themargin\oddsidemargin
    \else
      \let\@thehead\@evenhead \let\@thefoot\@evenfoot
      \let\@themargin\evensidemargin
  \fi\fi
  \@tempdima \textmargin %% calculate total page width
  \advance\@tempdima \textmarginsep
  \advance\@tempdima \textwidth
  \shipout
  \vbox{\normalsize \baselineskip\z@ \lineskip\z@
        \vskip \topmargin \moveright\@themargin
        \vbox{\setbox\@tempboxa
              \vbox to\headheight{\vfil%
                                  \hbox to\@tempdima{\strut\@thehead}}%
              \box\@tempboxa
              \vskip \headsep
              \hbox to\@tempdima{\hss\box\@outputbox}%% move the body text over
              \baselineskip\footskip
              \hbox to\@tempdima{\@thefoot}}}%
  \global\@colht\textheight\endgroup
  \stepcounter{page}\let\firstmark\botmark}
-- 
Nonviolence is not a land of milk and honey.  Nonviolence is tough.  You don't
practice nonviolence by attending conferences, you practice it on picket
lines, and that can he hard when you are faced with people who may be ready to
attack you with rocks, baseball bats, knives, even guns. [ Cesar Chavez ]



