![在自定义定理环境中缩进段落](https://linux22.com/image/379716/%E5%9C%A8%E8%87%AA%E5%AE%9A%E4%B9%89%E5%AE%9A%E7%90%86%E7%8E%AF%E5%A2%83%E4%B8%AD%E7%BC%A9%E8%BF%9B%E6%AE%B5%E8%90%BD.png)
问题:在我的自定义定理环境中,我希望定理环境中新段落的起始行紧跟其上方的行并缩进:
梅威瑟:
\documentclass{book}
\usepackage{amsthm}
\usepackage{enumitem}
\usepackage{xparse}
\usepackage{hyperref}
\usepackage{lipsum}
\newtheoremstyle{fctaylor}% name
{\topsep}% Space above
{\topsep}% Space below
{\normalfont}% Body font
{}% Indent amount (empty = no indent, \parindent = para indent)
{\bfseries}% Thm head font
{}% Punctuation after thm head
{\newline}% Space after thm head: " " = normal interword space;
{\makethmhead{#1}{#2}{#3}}
\newlength\fctaylortheoremindent
\AtBeginDocument{\setlength\fctaylortheoremindent{3em}} % <- customize here
\newlength\fctaylorlabelsep
\AtBeginDocument{\setlength\fctaylorlabelsep{1em}} % <- customize here
\makeatletter
\newcommand{\makethmhead}[3]{%
\gdef\thisthmhead{%
\makebox[\fctaylortheoremindent][l]{\bfseries#2}%
{\bfseries#1}%
\@ifnotempty{#3}{ (#3)}%
\hspace{\fctaylorlabelsep}%
\phantomsection%%% THIS LINE ADDED
}%
}
\makeatother
\newenvironment{fctayloritemize}
{\list{}{%
\leftmargin=\fctaylortheoremindent
\labelwidth=\dimexpr\fctaylortheoremindent-\labelsep\relax
\itemindent=0pt
}}
{\endlist}
\NewDocumentCommand{\newfctaylortheorem}{smomo}{%
\IfBooleanTF{#1}
{\newtheorem*{fctaylor@#2}{#4}}
{\IfNoValueTF{#3}
{\IfNoValueTF{#5}
{\newtheorem{fctaylor@#2}{#4}}
{\newtheorem{fctaylor@#2}{#4}[#5]}}
{\newtheorem{fctaylor@#2}[fctaylor@#3]{#4}}}%
\NewDocumentEnvironment{#2}{o}
{\IfNoValueTF{##1}{\begin{fctaylor@#2}}{\begin{fctaylor@#2}[##1]}%
\begin{fctayloritemize}\item[\thisthmhead\hfill]}
{\end{fctayloritemize}\end{fctaylor@#2}}%
}
\theoremstyle{fctaylor}
\newfctaylortheorem{thm}{Theorem}[section]
\newfctaylortheorem*{defn}{Definition}
\begin{document}
\section{One}
\begin{defn}
\lipsum*[2]
\end{defn}
\begin{thm}\label{A}
\lipsum*[2]
\end{thm}
\begin{thm}[Somebody]\label{B}
Something that should show how the text is split across line boundaries
and is correctly indented. And some equivalent conditions:
\begin{enumerate}[label=\upshape(\alph*),ref=(\alph*)]
\item a condition
\item another
\item and another
\end{enumerate}
which show the point made.
\indent\textbf{This line, which begins a new paragraph, should immediately follow the above line but be indented.}
\end{thm}
Here are the references: \ref{A} and \ref{B}.
\end{document}
\newtheoremstyle{fctaylor}%
{\topsep}%
{\topsep}%
{\normalfont}%
{}%
{\bfseries}%
{}%
{0pt}% Space after thm head: " " = normal interword space;
{\makethmhead{#1}{#2}{#3}}
到
\newtheoremstyle{fctaylor}%
{\topsep}%
{\topsep}%
{\normalfont}%
{}%
{\bfseries}%
{}%
{\newline}% The one thing I changed which seemed to work in the other answer
{\makethmhead{#1}{#2}{#3}}
有什么想法可以完成我想要做的事情吗?(我只是尝试通过添加来修改有问题的行\indent
,但这没有任何作用。)
答案1
您实际上是将定理/定义放入其中,list
并将其标题显示为描述项。您设置此格式的方式看似复杂,我怀疑这是否是实现目标的最佳方式。
但是,根据您当前的代码,您所需要的只是\listparindent
。不过,我还做了一些额外的调整:
- 没有必要使用
\phantomsection
。 - 我在关键的那一行之前补充
\relax
道。\itemindent=0pt
\listparindent=\parindent
- 我删除
\hfill
了\item[\thisthmhead\hfill]
。 - 由于我不完全理解您关于 的要求
\newline
,我\strut\par
立即在 之后添加了\item[\thisthmhead]
。这将导致标题后的文本排版在新段落中(\fctaylorlabelsep
当然,这将变得毫无用处)。如果这不是您想要的,只需删除\strut\par
。
再次,我想知道是否存在适合您的格式的更好的代码。
\documentclass{book}
\usepackage{amsthm}
\usepackage{enumitem}
\usepackage{xparse}
\usepackage{hyperref}
\usepackage{lipsum}
\newtheoremstyle{fctaylor}% name
{\topsep}% Space above
{\topsep}% Space below
{\normalfont}% Body font
{}% Indent amount (empty = no indent, \parindent = para indent)
{\bfseries}% Thm head font
{}% Punctuation after thm head
{\newline}% Space after thm head: " " = normal interword space;
{\makethmhead{#1}{#2}{#3}}
\newlength\fctaylortheoremindent
\AtBeginDocument{\setlength\fctaylortheoremindent{3em}} % <- customize here
\newlength\fctaylorlabelsep
\AtBeginDocument{\setlength\fctaylorlabelsep{1em}} % <- customize here
\makeatletter
\newcommand{\makethmhead}[3]{%
\gdef\thisthmhead{%
\makebox[\fctaylortheoremindent][l]{\bfseries#2}%
{\bfseries#1}%
\@ifnotempty{#3}{ (#3)}%
\hspace{\fctaylorlabelsep}%
%\phantomsection%%% THIS LINE ADDED% <-- This line commented out
}%
}
\makeatother
\newenvironment{fctayloritemize}
{\list{}{%
\leftmargin=\fctaylortheoremindent
\labelwidth=\dimexpr\fctaylortheoremindent-\labelsep\relax
\itemindent=0pt\relax% <-- \relax added
\listparindent=\parindent% <-- What you missed
}}
{\endlist}
\NewDocumentCommand{\newfctaylortheorem}{smomo}{%
\IfBooleanTF{#1}
{\newtheorem*{fctaylor@#2}{#4}}
{\IfNoValueTF{#3}
{\IfNoValueTF{#5}
{\newtheorem{fctaylor@#2}{#4}}
{\newtheorem{fctaylor@#2}{#4}[#5]}}
{\newtheorem{fctaylor@#2}[fctaylor@#3]{#4}}}%
\NewDocumentEnvironment{#2}{o}
{\IfNoValueTF{##1}{\begin{fctaylor@#2}}{\begin{fctaylor@#2}[##1]}%
\begin{fctayloritemize}\item[\thisthmhead]\strut\par}% <-- \hfill removed.
{\end{fctayloritemize}\end{fctaylor@#2}}%
}
\theoremstyle{fctaylor}
\newfctaylortheorem{thm}{Theorem}[section]
\newfctaylortheorem*{defn}{Definition}
\begin{document}
\section{One}
\begin{defn}
\lipsum*[2]
\end{defn}
\begin{thm}\label{A}
\lipsum*[2]
\end{thm}
\begin{thm}[Somebody]\label{B}
Something that should show how the text is split across line boundaries
and is correctly indented. And some equivalent conditions:
\begin{enumerate}[label=\upshape(\alph*),ref=(\alph*)]
\item a condition
\item another
\item and another
\end{enumerate}
which show the point made.
\indent\textbf{This line, which begins a new paragraph, should immediately follow the above line but be indented.}
\end{thm}
Here are the references: \ref{A} and \ref{B}.
\end{document}