Page Layoutprinting section numbers in the margin in LaTeX

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
audreyk
Posts: 23
Joined: Fri Nov 14, 2008 5:57 am

printing section numbers in the margin in LaTeX

Post by audreyk »

Hello,

Can somebody tell me how to create hanging section numbers in the left margin of a document?

An example of what I am looking for appears here: http://unicast.org/misc/marginsec.png

I would appreciate seeing an example provided, with the document tex code in its entirety, as I am still fairly new to learning LaTeX.

I look forward to hearing from anyone ... soon :) .

Thanks,
audreyk

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
localghost
Site Moderator
Posts: 9201
Joined: Fri Feb 02, 2007 12:06 pm

printing section numbers in the margin in LaTeX

Post by localghost »

audreyk wrote:[...] I would appreciate seeing an example provided, with the document tex code in its entirety, as I am still fairly new to learning LaTeX. [...]
Make a first approach on your own by looking at the titlesec package. In its documentation you will find some examples including the code.


Best regards
Thorsten¹
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes[/size]

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

printing section numbers in the margin in LaTeX

Post by phi »

Here is a similar thread, including a solution for the standard classes:
http://www.latex-community.org/viewtopic.php?f=5&t=3573
If you use a KOMA-Script class, it's a bit easier. Search the manual for \othersectionlevelsformat, an example is given there.
audreyk
Posts: 23
Joined: Fri Nov 14, 2008 5:57 am

printing section numbers in the margin in LaTeX

Post by audreyk »

Thanks to all who have provided relevant links w/information, but after all that reading, I'm still not sure what I need to change in the code to get an elegant hanging section with as little code manipulation as possible.

Have a look at my Makefile code (set up to run sixteen units of a course filled with numerous chemical structures):

Code: Select all

\documentclass{book}
\usepackage{fancyhdr}
\usepackage[asymmetric, total={336pt,624pt}, top=96pt, left=208pt, reversemp]{geometry}
\usepackage[fleqn]{amsmath}
\usepackage{chemarrow}
\usepackage{amssymb,amsfonts,wrapfig,amscd,times,curves,amsthm}
\usepackage{enumerate}
\usepackage{mdwlist}
\usepackage{sectsty}
\usepackage{fancyvrb}
\usepackage{paralist}
\usepackage{picinpar}
\usepackage{graphicx}
\usepackage{array}
\usepackage[hang,bottom]{footmisc}
\usepackage{dcolumn}
\usepackage{titlesec}
\usepackage{varioref}
\usepackage{array}
\usepackage{makeidx}
\usepackage[hang,bf,nooneline,justification=raggedright]{caption}
\usepackage{polynom}
\usepackage[T1]{fontenc}
\usepackage{mathpazo}
\usepackage{xymtexps,chmst-ps,lewis}

%--------------------------------------------------------------------------------
\pagestyle{fancy} \fancyhf{}
\renewcommand{\footrulewidth}{0.25pt}
\renewcommand{\headrulewidth}{0pt}
\fancyfoot[LE,RO]{\footnotesize \thepage}
\fancyfoot[LO]{\footnotesize{\itshape Organic Chemistry I}}
\fancyfoot[RE]{\footnotesize Chemistry $350$ / \textbf{Study Guide}}
\fancyfootoffset[LE,LO]{120pt} \fancypagestyle{plain}

\setlength{\marginparwidth}{6em}

\makeatletter
\renewcommand\footnoterule{
\vspace{1.5em} \kern-3\p@\hrule\@width.4\columnwidth \kern6\p@}
\makeatother

\makeatletter
 \newlength{\myFootnoteWidth}
 \newlength{\myFootnoteLabel}
 \setlength{\myFootnoteLabel}{0.4em}
 \renewcommand{\@makefntext}[1]{
 \setlength{\myFootnoteWidth}{\columnwidth}
 \addtolength{\myFootnoteWidth}{-\myFootnoteLabel}
 \noindent
 \makebox[\myFootnoteLabel][r]{\@makefnmark\ }
 \parbox[t]{\myFootnoteWidth}{#1}
 } \makeatother

\interfootnotelinepenalty=10000

\tolerance 1414
 \hbadness 1414
 \emergencystretch 1.5em
 \hfuzz 0.3pt
\widowpenalty=10000
 \vfuzz
  \hfuzz
   \raggedbottom

\renewcommand{\arraystretch}{1.5}

\newcommand{\Tiny}{\fontsize{4pt}{4pt}}

\renewcommand{\textbullet}{\small{$\bullet$}}

\newcolumntype{d}{D{.}{.}{-1}}

\clubpenalty=10000 \widowpenalty=10000

\raggedright
\parindent=0pt
\setlength{\parskip}{2ex} \footskip=24pt \hoffset=0pt
\paperwidth=597pt
\renewcommand\chaptertitlename{Unit}
\setcounter{secnumdepth}{0} \frenchspacing

\newcommand{\degree}{\ensuremath{^\circ}}

\titleformat{\chapter}[display]
   {\normalfont\filright\bf}
   {\vspace{-7pc}
   \huge{\chaptertitlename} \thechapter}
   {1pc}
   {\vspace{-2pc}
   \LARGE\rm}

%------------------------------------------------------------------------------
\vfuzz2pt % Don't report over-full v-boxes if over-edge is small
\hfuzz2pt % Don't report over-full h-boxes if over-edge is small
% THEOREMS -------------------------------------------------------

\renewcommand{\thefigure}{\thechapter.\arabic{figure}}

% typesets single, double, or triple bond
%(e.g., C\bond2{O} gives C=O
%
\def\bond#1{\relax
    \hbox \bgroup
       \kern 0.1em
       \setbox0=\hbox{X}%
       \vbox to \ht0 \bgroup
          \vss
          \ifcase#1
          \or
             \hrule width 1.4em depth 0pt height 0.03em
          \or
             \hrule width 1.4em depth 0pt height 0.03em
             \vskip 0.2em%changed jms89 from 0.1
             \hrule width 1.4em depth 0pt height 0.03em
          \or
             \hrule width 1.4em depth 0pt height 0.03em
             \vskip 0.2em%changed jms89 from 0.1
             \hrule width 1.4em depth 0pt height 0.03em
             \vskip 0.2em%changed jms89 from 0.1
             \hrule width 1.4em depth 0pt height 0.03em
          \fi
          \vss
          \egroup
       \kern 0.1em
       \egroup
    }%

\makeindex

\begin{document}

%\include{350intro}
%\include{350unit01}
%\include{350unit02}
%\include{350unit03}
%\include{350unit04}
%\include{350unit05}
%\include{350unit06}
%\include{350unit07}
%\include{350unit08}
%\include{350unit09}
%\include{350unit10}
%\include{350unit11}
%\include{350unit12}
%\include{350unit13}
%\include{350unit14}
%\include{350unit15}
%\include{350unit16}

 \printindex

\end{document}
This is the code I'm using now to get the chapter title:

Code: Select all

\chapter{Structure and Bonding}
\vspace{-3.5pc}
\hspace{-120pt}\rule{456pt}{0.25pt}
\vspace{0.25pc}
This is the code I'm using now in my document to get a hanging section:

Code: Select all

\section{\hspace{-3em}1.12{\hspace{1em}}\rm{Drawing Chemical Structures}}
\rule{336pt}{0.25pt}
The trouble with my section code is that when the amount of section digits change, e.g., 1.1, 1.11, 10.12, etc. ..., I need to readjust the \hspace to align the titles with the rule, esp. for titles running on two lines or more. Also, I am manually typing in the section numbers.

Please see the sample PDFs for the \chapter and \section styles.

Note that I am also using the XyMTeX postscript package to create chemical structures throughout.

I would appreciate any help I can get at this point.

Thanks,
audreyk
Attachments
pg23.pdf
(66.05 KiB) Downloaded 628 times
pg3.pdf
(67.98 KiB) Downloaded 422 times
Post Reply