这似乎是我最喜欢的,我想我会发布我的解决方案,看看是否有可以改进的地方
因此,我四处寻找,发现parano
其中的参考资料已经从互联网上消失了 - 不过我找到了一份副本这里- 尝试它有点像车祸 - 这并不奇怪,因为它显然还处于测试阶段
我确实向前迈出了一大步这里- 但它总是有点偏离 - 我花了几个小时尝试使用 marginpar 来做一些事情,以避免不得不做一个负面的 parindent -我还是想避免那种消极的父母
这是我现在可以使用的 MWE - 注意由于 parindent kludge 低位数字无法正常工作 - 计数器采用章节号和段落号
\documentclass[twoside]{report}
\usepackage[left=3.50cm, right=3.50cm, top=3.00cm, bottom=3.00cm, marginparwidth=20pt]{geometry}
\usepackage{lipsum}
\usepackage{etoolbox}
\usepackage{xcolor}
\usepackage{indentfirst}
\newcounter{para}
\newcommand*{\numberedparagraph}{%
{\color{gray}\textit{\thechapter.\refstepcounter{para}\thepara}\space}
}
\setlength{\parindent}{-25pt}
\makeatletter
\preto\chapter{\everypar{}}
\preto\section{\everypar{}}
\preto\subsection{\everypar{}}
\preto\subsubsection{\everypar{}}
\renewcommand{\@afterheading}{%
\@nobreaktrue
\everypar{%
\if@nobreak
\@nobreakfalse
\clubpenalty\@M
\if@afterindent
\else
{\setbox\z@\lastbox}%
\fi
\else
\clubpenalty\@clubpenalty
\everypar{\numberedparagraph}%
\fi
\numberedparagraph
}%
}
\makeatother
\begin{document}
\chapter{title}
\section{Sample Section}
\lipsum[1-4]
\subsection{Sample Subsection}
\lipsum[11-15]
\section{Another Section}
\lipsum[16-18]
\end{document}
答案1
此代码将段落编号包裹在一个框中,然后将该框移至左边距。结果与字体大小或固定负空间无关。
您可以选择数字的高度和颜色。
\documentclass[12pt, twoside]{report}
\usepackage[left=3.50cm, right=3.50cm, top=3.00cm, bottom=3.00cm, marginparwidth=20pt]{geometry}
\usepackage{lipsum}
\usepackage{etoolbox}
\usepackage{xcolor}
\usepackage{indentfirst}
%***************************************************** changed<<<<<<<<<<<<<<<<<<<
\usepackage{graphicx}
\usepackage{showframe}% only to show the margins <<<<<<
\newcounter{para}
\preto\chapter{\everypar{}}
\preto\section{\everypar{}}
\preto\subsection{\everypar{}}
\preto\subsubsection{\everypar{}}
\newlength{\parnumberheight}
\setlength{\parnumberheight}{1.5ex} % set paragraph numbers height <<<<<<<<<<
\definecolor{paranumcolor}{rgb}{0.82, 0.1, 0.26} % set color of numbers (red) <<<<<<<<<<<<<<<
%\definecolor{paranumcolor}{rgb}{0.52, 0.52, 0.51}% set color of numbers (gray)
\makeatletter
\newsavebox{\setnumberedparagraph}
\newsavebox{\numberedparagraph}
\newcommand{\numberedparagraph@set}[1][2ex]{%
\sbox{\setnumberedparagraph}{\resizebox{!}{#1}
{\color{paranumcolor}\itshape\thechapter.\refstepcounter{para}\thepara\space}%
}%
\usebox{\setnumberedparagraph}
}
\newcommand{\parnumber@insert}[1][2ex]{%
\sbox{\numberedparagraph}{\numberedparagraph@set[#1]}%
\makebox[-\parindent][r]{\makebox[0pt][r]{\usebox\numberedparagraph}}%
}
\renewcommand{\@afterheading}{%
\@nobreaktrue
\everypar{%
\bgroup%
\everypar{}%
\if@nobreak%
\@nobreakfalse%
\clubpenalty\@M%
\if@afterindent%
\else%
{\setbox\z@\lastbox}%
\fi%
\else%
\clubpenalty\@clubpenalty%
\fi%
\parnumber@insert[\parnumberheight]%
\egroup%
}%
}
\makeatother
%***************************************************** changed<<<<<<<<<<<<<<<<<<<
\begin{document}
\chapter{Title}
\section{Sample Section}
\lipsum[1-4]
\subsection{Sample Subsection}
\lipsum[11-15]
\section{Another Section}
\lipsum[18-26]
\end{document}