2

I want to insert numbers into the margin next to paragraphs, in a way that the number does not impact the text of the document. I want the first letter of each line to be flush on the left. I am doing this

\usepackage{type1cm}
\usepackage{lettrine}
\newcommand*{\DefaultLhang}{1.34}

...

\lettrine{1}{} Here is the text of the paragraph

The problem is that the hang of 1.34 works for numbers less than 10, but not for numbers greater than 10. Is there a way to make lettrine fully place the number into the margin without impacting the text itself. Or is there a better easier way to solve this?

  • you should make a small but complete example, that makes it much easier to test your issue and possible solutions. – Ulrike Fischer May 19 '21 at 12:58
  • I am not sure I understand what you are asking. If I knew how to create an example of how to insert a number into the margin (such as how lettrine almost does) then I wouldn't have to ask how to do it. I simply want to insert numbers into the margin without interfering with the main text. – Megan Spencer May 19 '21 at 14:18
  • It might be clear to you what you are doing but what is \DefaultLhang? Please provide an MWE (from \documentclass... to `\end{document}) that we can process that shows your problem. --- GOM – Peter Wilson May 19 '21 at 17:48

2 Answers2

1

You can do it without lettrine.

\documentclass{article}
\usepackage{fix-cm}
\usepackage[T1]{fontenc}
\usepackage{adjustbox}

\usepackage{lipsum}

\newcounter{numpar} \newcommand{\numpar}{% \par \ifnum\value{numpar}>0 % not the first paragraph \ifnum\prevgraf<2 \addvspace{\baselineskip}% \fi \fi \stepcounter{numpar}% \noindent \raisebox{\dimexpr-\height+\fontcharht\font`T}[0pt][0pt]{% \makebox[0pt][r]{{\fontsize{2.5\baselineskip}{0}\selectfont\thenumpar} }% }\ignorespaces }

\begin{document}

\numpar\lipsum[1][1-4]

\numpar\lipsum[1][1]

\numpar\lipsum[2][1-4]

\setcounter{numpar}{9}

\numpar\lipsum[3][1-4]

\end{document}

An empty line is added automatically if the previous paragraph is less than two lines long.

enter image description here

egreg
  • 1,121,712
0

Here's a stripped down version of \lettrine (called \hangnum) that puts the number on the margin, regadless of its width. It uses lettrine's machinery to compute the font sizes, so it requires the package to be loaded:

enter image description here

\documentclass[12pt]{article}
\usepackage{type1cm}
\usepackage{lettrine}
\newcommand*{\DefaultNhang}{1.34}% controls the spacing

\makeatletter \DeclareRobustCommand\hangnum[1]{% \def\l@initial{#1\kern\DefaultNhang pt}% \setcounter{L@lines}{\value{DefaultLines}}% \renewcommand*{\L@oversize}{\DefaultLoversize}% \sbox{\L@tbox}{\LettrineTextFont{\LettrineSecondString}}% \setupL@lbox \setlength{\L@lraise}{\DefaultLraise\L@target@tht}% \ifnum\value{L@lines}=1 \else\addtolength{\L@lraise}{-\L@target@dp}\fi \par \noindent \smash{\llap{\raisebox{\L@lraise}{\usebox{\L@lbox}}}}% \ignorespaces} \makeatother

\begin{document}

\hangnum{1} Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

\hangnum{11} Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

\end{document}