我正在尝试制作一个需要由 5 个子级别构成的文档,其中文档中的每个句子前面都需要有一个标签,例如 1.2.4 或 1.4.5.6.4。最好的方法是什么(我知道它看起来不太好,但这是我需要的)。此外,我希望在示例代码中显示的范围内控制每个级别。
我所做的是使用article
文档类和格式paragraph
并subparagraph
本质上给我subsubsubsection
和subsubsubsubsection
。
还有其他方法可以做到这一点吗?截至目前,整个文档没有文本,只有章节标题,这正如我所希望的那样,但我想知道是否有更好的方法。
\documentclass[letterpaper]{article}
\usepackage{titlesec}
\titleformat{\section}
{\normalfont\fontfamily{phv}\fontsize{13}{16}\bfseries}{\thesection}{1em}{}
\titleformat{\subsection}
{\normalfont\fontfamily{phv}\fontsize{12}{14}\selectfont}{\thesubsection}{1em}{}
\titleformat{\subsubsection}
{\normalfont\fontfamily{phv}\fontsize{12}{14}\selectfont}{\thesubsubsection}{1em}{}
\setcounter{secnumdepth}{5}
\titleformat{\paragraph}
{\normalfont\fontfamily{phv}\fontsize{12}{14}\selectfont}{\theparagraph}{1em}{}
\titleformat{\subparagraph}
{\normalfont\fontfamily{phv}\fontsize{12}{14}\selectfont}{\thesubparagraph}{1em}{}
\titlespacing*{\section}{0pt}{1.5ex}{1.5ex}
\titlespacing*{\subsection}{30pt}{1.5ex}{1.5ex}
\titlespacing*{\subsubsection}{60pt}{1.5ex}{1.5ex}
\titlespacing*{\paragraph}{100pt}{1.5ex}{1.5ex}
\titlespacing*{\subparagraph}{120pt}{1.5ex}{1.5ex}
\begin{document}
\section{Hello}
\subsection{Hello}
\subsubsection{Hey There}
\paragraph{Yes sir}
\subparagraph{Good morning}
\end{document}
\documentclass{article}
\newcounter{depth}
\setcounter{depth}{1}
\newcounter{pi}
\newcounter{pii} [pi] \renewcommand\thepii{\thepi.\arabic{pii}}
\newcounter{piii}[pii] \renewcommand\thepiii{\thepii.\arabic{piii}}
\newcounter{piv} [piii]\renewcommand\thepiv{\thepiii.\arabic{piv}}
\newcounter{pv} [piv] \renewcommand\thepv{\thepiv.\arabic{pv}}
\def\psetdepth#1#2\relax{%
\ifx+#1\relax\addtocounter{depth}{#2}%
\else\ifx-#1\relax\addtocounter{depth}{-#2}%
\else\setcounter{depth}{#1#2}\fi\fi}
\newcommand\sentence[2][+0]{%
\par
\psetdepth#1\relax\relax
\vspace{\csname pspace\roman{depth}\endcsname}%
\hspace{\csname phspace\roman{depth}\endcsname}%
\hangindent=\csname pindent\roman{depth}\endcsname
\hangafter=1
\indent\refstepcounter{p\roman{depth}}\llap{\csname thep\roman{depth}\endcsname\ }%
{\csname pstyle\roman{depth}\endcsname#2\par}}
\newcommand\phspacei{20pt}
\newcommand\phspaceii{40pt}
\newcommand\phspaceiii{65pt}
\newcommand\phspaceiv{100pt}
\newcommand\phspacev{140pt}
\newcommand\pindenti{5ex}
\newcommand\pindentii{10ex}
\newcommand\pindentiii{15ex}
\newcommand\pindentiv{23.5ex}
\newcommand\pindentv{32.5ex}
\newcommand\pspacei{15pt}
\newcommand\pspaceii{15pt}
\newcommand\pspaceiii{10pt}
\newcommand\pspaceiv{10pt}
\newcommand\pspacev{10pt}
\newcommand\pstylei{\Large\bfseries}
\newcommand\pstyleii{\bfseries\itshape}
\newcommand\pstyleiii{\normalfont}
\newcommand\pstyleiv{\normalfont}
\newcommand\pstylev{\normalfont}
\begin{document}
\raggedright
\sentence{This is a sentence.}
\sentence{This is another sentence. Just like any other sentence one would think but perhaps not.}
\sentence[+1]{This sentence is similar to the others, but longer. This sentence is similar to the others, but longer.This sentence is similar to the others, but longer.}
\sentence{This is a sentence.This sentence is similar to the others, but longer.This sentence is similar to the others, but longer.This sentence is similar to the others, but longer.}
\sentence[+1]{This is another sentence.This sentence is similar to the others, but longer.This sentence is similar to the others, but longer.This sentence is similar to the others, but longer.}
\sentence[+1]{This sentence is similar to the others, but longer.This sentence is similar to the others, but longer.This sentence is similar to the others, but longer.This sentence is similar to the others, but longer.}
\sentence{This is a sentence.This sentence is similar to the others, but longer.This sentence is similar to the others, but longer.This sentence is similar to the others, but longer.}
\sentence{This is another sentence.This sentence is similar to the others, but longer.This sentence is similar to the others, but longer.This sentence is similar to the others, but longer.}
\sentence{This sentence is similar to the others, but longer.}
\sentence[+1]{Hey there how is it going my good friend. Hey there how is it going my good friend.}
\sentence[-2]{This is a sentence hey.}
\sentence{This is another sentence.}
\sentence{This sentence is similar to the others, but longer.}
\sentence[-1]{This is a sentence.}
\end{document}
答案1
如果您想要一个基本上只包含编号句子且格式最少的最小方案,那么您可以在文档中使用非常少的标记。
\documentclass{article}
\newcounter{depth}
\setcounter{depth}{1}
\newcounter{pi}
\newcounter{pii} [pi] \renewcommand\thepii{\thepi.\arabic{pii}}
\newcounter{piii}[pii] \renewcommand\thepiii{\thepii.\arabic{piii}}
\newcounter{piv} [piii]\renewcommand\thepiv{\thepiii.\arabic{piv}}
\newcounter{pv} [piv] \renewcommand\thepv{\thepiv.\arabic{pv}}
\newcommand\pdown{\addtocounter{depth}{1}\setcounter{p\roman{depth}}{0}}
\newcommand\pup{\addtocounter{depth}{-1}}
\makeatletter
\begin{document}
\everypar{%
\refstepcounter{p\roman{depth}}\llap{\csname thep\roman{depth}\endcsname\ }}
This is a sentence.
This is another sentence.
\pdown
This sentence is similar to the others, but longer.
This is a sentence.
\pdown
This is another sentence.
\pdown
This sentence is similar to the others, but longer.
This is a sentence.
This is another sentence.
This sentence is similar to the others, but longer.
\pup
\pup
This is a sentence.
This is another sentence.
This sentence is similar to the others, but longer.
\pup
This is a sentence.
\pdown
This is another sentence.
This sentence is similar to the others, but longer.
This is a sentence.
\pdown
This is another sentence.
This sentence is similar to the others, but longer.
This is a sentence.
This is another sentence.
\pup
This sentence is similar to the others, but longer.
\pdown
This is a sentence.
This is another sentence.
\pup\pup
This sentence is similar to the others, but longer.
This is a sentence.
\pdown
This is another sentence.
This sentence is similar to the others, but longer.
\end{document}
如果您想要可自定义的字体和间距,我会使用更类似于以下的方案。您可以使用相对值(例如[+1]
或)将句子向上或向下移动一层[-1]
,或者跳转到特定层(例如[1]
返回顶层)。您可以在每一层指定垂直间距命令和字体(或颜色或其他)命令。
\documentclass{article}
\newcounter{depth}
\setcounter{depth}{1}
\newcounter{pi}
\newcounter{pii} [pi] \renewcommand\thepii{\thepi.\arabic{pii}}
\newcounter{piii}[pii] \renewcommand\thepiii{\thepii.\arabic{piii}}
\newcounter{piv} [piii]\renewcommand\thepiv{\thepiii.\arabic{piv}}
\newcounter{pv} [piv] \renewcommand\thepv{\thepiv.\arabic{pv}}
\def\psetdepth#1#2\relax{%
\ifx+#1\relax\addtocounter{depth}{#2}%
\else\ifx-#1\relax\addtocounter{depth}{-#2}%
\else\setcounter{depth}{#1#2}\fi\fi}
\newcommand\sentence[2][+0]{%
\par
\psetdepth#1\relax\relax
\vspace{\csname pspace\roman{depth}\endcsname}%
\indent\refstepcounter{p\roman{depth}}\llap{\csname thep\roman{depth}\endcsname\ }%
{\csname pstyle\roman{depth}\endcsname#2\par}}
\newcommand\pspacei{\baselineskip}
\newcommand\pspaceii{.5\baselineskip}
\newcommand\pspaceiii{.5\baselineskip}
\newcommand\pspaceiv{0pt}
\newcommand\pspacev{0pt}
\newcommand\pstylei{\Large\bfseries}
\newcommand\pstyleii{\bfseries\itshape}
\newcommand\pstyleiii{\normalfont}
\newcommand\pstyleiv{\normalfont}
\newcommand\pstylev{\normalfont}
\begin{document}
\raggedright
\sentence{This is a sentence.}
\sentence{This is another sentence.}
\sentence[+1]{This sentence is similar to the others, but longer.}
\sentence{This is a sentence.}
\sentence[+1]{This is another sentence.}
\sentence[+1]{This sentence is similar to the others, but longer.}
\sentence{This is a sentence.}
\sentence{This is another sentence.}
\sentence{This sentence is similar to the others, but longer.}
\sentence[-2]{This is a sentence.}
\sentence{This is another sentence.}
\sentence{This sentence is similar to the others, but longer.}
\sentence[-1]{This is a sentence.}
\sentence[+1]{This is another sentence.}
\sentence{This sentence is similar to the others, but longer.}
\sentence{This is a sentence.}
\sentence[+1]{This is another sentence.}
\sentence{This sentence is similar to the others, but longer.}
\sentence{This is a sentence.}
\sentence{This is another sentence.}
\sentence[-1]{This sentence is similar to the others, but longer.}
\sentence[+1]{This is a sentence.}
\sentence{This is another sentence.}
\sentence[-2]{This sentence is similar to the others, but longer.}
\sentence{This is a sentence.}
\sentence[+1]{This is another sentence.}
\sentence{This sentence is similar to the others, but longer.}
\end{document}