由于某种原因,我无法使用\subsubsection{}
该选项缩进由包格式化的段落。run-in 选项用于使段落紧跟在标题之后,在本例中,我将其留空并仅使用数字。titlesec
[runin]
\subsubsection{}
文件:
\documentclass{article}
\usepackage{titlesec}
\setcounter{secnumdepth}{3}
\titleformat{\subsection}[runin]{}{\thesubsection.}{3pt}{}
\titleformat{\subsubsection}[runin]{}{\thesubsubsection.}{3pt}{}
\begin{document}
\section{This is a section}
\subsection{} This is a paragraph:
\begin{quote}
\subsubsection{} This is a sub-paragraph I want to indent.
\end{quote}
{\addtolength{\leftskip}{5mm}
\subsubsection{} This is a sub-paragraph I want to indent.
}
\end{document}
这将生成以下输出:
请注意,第一种方法有效,但是会产生错误:
出现问题 — — 可能缺少某个 \item。
第二种方法什么也不做。
现在,如果我删除该[runin]
选项,这两种方法都会按预期工作。似乎该[runin]
选项会干扰缩进。但是,尽管存在错误,但第一种方法似乎可以生成所需的文档。有什么想法可以消除错误吗?
答案1
最好使用\titlespacing
。最后两个参数取自中的值article.cls
。
\documentclass{article}
\usepackage{titlesec}
\usepackage{lipsum}
\setcounter{secnumdepth}{3}
\titleformat{\subsection}[runin]{}{\thesubsection.}{3pt}{}
\titleformat{\subsubsection}[runin]{}{\thesubsubsection.}{3pt}{}
\titlespacing{\subsubsection}{\parindent}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
\begin{document}
\section{This is a section}
\lipsum[2]
\subsection{} This is a paragraph:
\lipsum[2]
\subsubsection{} This is a sub-paragraph I want to indent.
\lipsum[2-3]
\end{document}
如果你想缩进整个块,那么adjustwidth
可以这样做,但出于实现原因,你需要发出\mbox{}\vspace{-\baselineskip}
。问题是adjustwidth
作为列表实现的,这与运行标题冲突。
\documentclass{article}
\usepackage{titlesec}
\usepackage{changepage}
\usepackage{lipsum}
\setcounter{secnumdepth}{3}
\titleformat{\subsection}[runin]{}{\thesubsection.}{3pt}{}
\titleformat{\subsubsection}[runin]{}{\thesubsubsection.}{3pt}{}
\begin{document}
\section{This is a section}
\lipsum[2]
\subsection{} This is a paragraph:
\lipsum[2]
\begin{adjustwidth}{\parindent}{0pt}\mbox{}\vspace{-\baselineskip}
\subsubsection{} This is a sub-paragraph I want to indent.
\lipsum[2-3]
\end{adjustwidth}
\end{document}
在适当的环境下可能更好的实现:
\documentclass{article}
\usepackage{titlesec}
\usepackage{changepage}
\usepackage{xpatch}
\usepackage{lipsum}
\setcounter{secnumdepth}{3}
\let\subsubaw\adjustwidth
\xpatchcmd{\subsubaw}
{\topsep}
{\labelwidth=0pt \labelsep=0pt \topsep}
{}{}
\xpatchcmd{\subsubaw}
{\item[]}
{\refstepcounter{subsubsection}\item[\thesubsubsection.\hspace{3pt} ]}
{}{}
\newenvironment{subsub}
{\par\addvspace{3.25ex plus 1ex minus .2ex}%
\subsubaw{\parindent}{0pt}}
{\endadjustwidth}
\titleformat{\subsection}[runin]{}{\thesubsection.}{3pt}{}
\begin{document}
\section{This is a section}
\lipsum[2]
\subsection{} This is a paragraph:
\lipsum[2]
\begin{subsub}
This is a sub-paragraph I want to indent.
\lipsum[2-3]
\end{subsub}
\end{document}