[英]Suppress indentation after environment in LaTeX
我正在嘗試在我的LaTeX文檔中創建一個新環境,其中抑制了環境之后的下一段中的縮進。
我被告知(TeXbook和LaTeX源碼)通過將\\everypar
設置為{\\setbox0\\lastbox}
,TeX排版器將在下一段的開頭執行此操作,從而刪除縮進:
\everypar{\setbox0\lastbox}
所以這就是我做的,但沒有效果(以下段落仍然縮進):
\newenvironment{example}
{\begin{list}
{}
{\setlength\leftmargin{2em}}}
{\end{list}\everypar{\setbox0\lastbox}}
我研究過LaTeX的內部結構以及我可以管理的內容。 似乎\\end
例程在某個時刻表示\\endgroup
和\\par
,這可能是LaTeX忽略my \\everypar
設置的原因。 \\global
也沒有幫助。 我知道\\noindent
但是想要自動執行此操作。
示例文檔片段:
This is paragraph text. This is paragraph text, too.
\begin{example}
\item This is the first item in the list.
\item This is the second item in the list.
\end{example}
This is more paragraph text. I don't want this indented, please.
感興趣的內部例程和開關似乎是\\@endpetrue
, \\@endparenv
和其他人。 謝謝你的幫助。
沒有重新定義\\end
,我無法得到任何工作,但我當然不是專家。
以下是非常hacky,但在我的有限測試中工作。 當然這會干擾嵌套環境(如果遇到問題,你應該可以重新定義\\begin
恢復舊的\\end
)。
\newenvironment{example}{%
\bgroup
\let\oldend=\end
\def\end##1{\oldend{##1}\csname @afterindentfalse\endcsname
\csname @afterheading\endcsname}
\begin{list}{}
{\setlength\leftmargin{2em}}
}{%
\end{list}
\egroup
}
這件事對我來說很簡單:
\makeatletter
\newenvironment{example}{%
\bgroup
\list{}{}
}{%
\endlist
\@afterindentfalse
\@afterheading
\egroup
}
\makeatother
但是,它在調用第一個\\ section之前不起作用(或者在“book”和“report”類的情況下為\\ chapter)。 我不知道為什么。
你不能在你的環境和下一行之間沒有空行來避免這種情況嗎?
This is paragraph text. This is paragraph text, too.
\begin{example}
\item This is the first item in the list.
\item This is the second item in the list.
\end{example}
% (No blank line)
This is more paragraph text. I don't want this indented, please.
\\end
情況下執行此操作 \makeatletter
\newenvironment{example}
{\begin{list}
{}
{\setlength\leftmargin{2em}}}
{\end{list}%
\def\if@endpe{%
\@doendpe
\let\par\@@par
\iffalse}}
\makeatother
\\end
的變化\\everypar
擴大后 \\endexample
。 為了使事情變得更復雜,它設置\\par
來恢復\\everypar{}
。 顯然\\@doendpe
是確保如果段落在環境之后繼續沒有縮進,但是如果在環境之后存在\\par
(或空行)則恢復正常行為。
您可能希望避免更改\\end
因為它必須在環境開始時進行更改,因此可能會干擾嵌套環境。 幸運的是, \\end
的定義包含\\expandafter\\endgroup\\if@endpe
。 我們可以使用\\if@endpe
作為鈎子將我們的代碼注入外部作用域。 在\\endgroup
\\if@endpe
之后, \\if@endpe
自動恢復。
我嘗試了伊萬的答案 ,但這對我不起作用。 但我確實讓它運轉了! 這是我做的:
\makeatletter
\renewenvironment{quotation}{%
\bgroup%
\let\oldend=\end%
\def\end##1{\oldend{##1}\csname @afterindentfalse\endcsname%
\csname @afterheading\endcsname}%
\list{}{\listparindent 1.5em%
\itemindent \listparindent%
\leftmargin 1.5em% This controls the size of the indentation
\rightmargin \leftmargin
\parsep \z@ \@plus\p@}% This line reduces inter-paragraph space to normal values.
\item\relax%
}{%
\endlist%%
\egroup%
}
\makeatother
這樣做的好處是它可以很好地排版你的blockquotes,並在blockquote之后刪除段落中的縮進。
在定義的末尾加上\\ @afterindentfalse \\ @afterheading。
我有同樣的問題。 我剛用過這個:
\noindent \newenvironment
你不應該弄亂\\everypar
令牌列表,除非你確切知道你在做什么。 使用
\setlength{\parindent}{0pt}
擺脫整個文件中的縮進。
使用\\ noindent結束您的環境可以幫助您
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.