无论计数器的宽度如何,段落左边距的缩进都是固定的

无论计数器的宽度如何,段落左边距的缩进都是固定的

因此,我想要做的是在左边距和文本开始位置之间有一个固定的量。我已经能够使用以下代码为部分和子集实现这一点:

\usepackage{titlesec}
\titleformat{\section}[hang]{\bfseries}{\makebox[0.5in][l]{\thesection}}{0pt}{}
\titleformat{\subsection}[hang]{\itshape}{\makebox[0.5in][l]{\textup{\thesubsection}}}{0pt}{}

我无法使这个工作适用于以下段落

\titleformat{\paragraph}[runin]{\normalfont\normalsize}{\makebox[0.5in][l]{\theparagraph}}{0pt}{}

产生 0.5 英寸的空间计数器。我猜这是因为 [runin],但我不知道如何修复它。

编辑:这是我的MWE:

\documentclass[a4paper,10pt]{article}
\setcounter{secnumdepth}{4}
\usepackage{titlesec}
\titleformat{\section}[hang]{\bfseries}{\makebox[0.5in][l]{\thesection}}{0pt}{}
\titleformat{\subsection}[hang]{\itshape}{\makebox[0.5in][l]{\textup{\thesubsection}}}{0pt}{}
\titleformat{\paragraph}[runin]{\normalfont\normalsize}{\makebox[0.5in][l]{\theparagraph}}{0pt}{}
\setcounter{secnumdepth}{4}
\renewcommand{\thesection}{\Roman{section}.}
\renewcommand{\thesubsection}{\thesection\Alph{subsection}.}
\renewcommand{\theparagraph}{[\arabic{paragraph}]}
\begin{document}
\noindent\rule{.5in}{2pt}
\section{SECTION}
\subsection{SubSection}
\paragraph{} Text that follows
\end{document}

导致: 在此处输入图片描述

我希望文本中的 T 与章节和小节中的 S 对齐,因为我的段落没有标题,它们只是编号(接下来我还想使段落编号不会为新的小节重置,但我假设我应该将其作为新帖子)。

答案1

现在 OP 已经提供了 MWE,我修改了我的答案。\theparagraph从段落框 1 的大小中减去 的宽度,以计算runin

\documentclass[a4paper,10pt]{article}
\setcounter{secnumdepth}{4}
\usepackage{titlesec}
\titleformat{\section}[hang]{\bfseries}{\makebox[0.5in][l]{\thesection}}{0pt}{}
\titleformat{\subsection}[hang]{\itshape}{\makebox[0.5in][l]{\textup{\thesubsection}}}{0pt}{}
\titleformat{\paragraph}[runin]{\normalfont\normalsize}{%
  \sbox0{\theparagraph}\makebox[\dimexpr0.5in-\wd0][l]{\theparagraph}}{0pt}{}
\setcounter{secnumdepth}{4}
\renewcommand{\thesection}{\Roman{section}.}
\renewcommand{\thesubsection}{\thesection\Alph{subsection}.}
\renewcommand{\theparagraph}{[\arabic{paragraph}]}
\begin{document}
\noindent\rule{.5in}{2pt}
\section{SECTION}
\subsection{SubSection}
\paragraph{} Text that follows
\end{document}

在此处输入图片描述


补充

针对 OP 的评论/问题,我们能否让段落编号不重置每个部分?只需使用不同的计数器,在 内部对其进行 ref-step\titleformat并使其成为 的一部分\theparagraph。我展示了它即使在目录中也能工作,当tocdepth设置为 4 时。

编辑:我将其更改为,\sbox0{\theparagraph}因为\sbox0{[0]}似乎runin根据的初始值计算一次,\theparagraph并且不会随着\theparagraph宽度的增加而重新计算。

\documentclass[a4paper,10pt]{article}
\setcounter{secnumdepth}{4}
\setcounter{tocdepth}{4}
\usepackage{titlesec}
\newcounter{globalparagraph}
\titleformat{\section}[hang]{\bfseries}{\makebox[0.5in][l]{\thesection}}{0pt}{}
\titleformat{\subsection}[hang]{\itshape}{\makebox[0.5in][l]{\textup{\thesubsection}}}{0pt}{}
\titleformat{\paragraph}[runin]{\normalfont\normalsize}{%
  \refstepcounter{globalparagraph}%
  \sbox0{[0]}\makebox[\dimexpr0.5in-\wd0][l]{\theparagraph}}{0pt}{}
\setcounter{secnumdepth}{4}
\renewcommand{\thesection}{\Roman{section}.}
\renewcommand{\thesubsection}{\thesection\Alph{subsection}.}
\renewcommand{\theparagraph}{[\arabic{globalparagraph}]}
\begin{document}
\tableofcontents
\noindent\rule{.5in}{2pt}

\paragraph{xyz}
\section{SECTION}
\subsection{SubSection}
\paragraph{} Text that follows
\section{SECTION}
\subsection{SubSection}
\paragraph{} Text that follows
\end{document}

在此处输入图片描述

相关内容