我想创建一个newenvironment
包含 的minipage
。但是,我发现在\noindent
其中插入命令时minipage
,它会在行首创建额外的空格。此外,当文本很长时,这些空格似乎会有所不同!
此外,在小页面内部和外部,垂直间距似乎表现不同。
有人能解释为什么会发生这种情况吗?
以下是创建此图片的代码:
\documentclass[11pt]{amsart}
\newenvironment{sample_text_with_noindentation}{\begin{minipage}{0.5\textwidth}\noindent}{\end{minipage}}
\newenvironment{sample_text_without_noindentation}{\begin{minipage}{0.5\textwidth}}{\end{minipage}}
\begin{document}
\hrulefill
\begin{center}minipage in document\end{center}
\hrulefill
\begin{minipage}{0.5\textwidth}
\noindent random short text............
\end{minipage}
Horizontal spacing looks fine here,
\begin{minipage}{0.5\textwidth}
random short text............
\end{minipage}
but the first row seems further apart
\begin{minipage}{0.5\textwidth}
\noindent random text which very long long long very long very long and it goes beyond the margins so it reaches the other line............
\end{minipage}
\begin{minipage}{0.5\textwidth}
random text which very long long long very long very long and it goes beyond the margins so it reaches the other line............
\end{minipage}
\hrulefill
\begin{center}minipage with {$\backslash$}noindent in {$\backslash$}newenvironment in preamble\end{center}
\hrulefill
\begin{sample_text_with_noindentation}
\noindent random short text............
\end{sample_text_with_noindentation}
Seems there is an extra space
\begin{sample_text_with_noindentation}
random short text............
\end{sample_text_with_noindentation}
even with {$\backslash$}noindent
\begin{sample_text_with_noindentation}
\noindent random text which very long long long very long very long and it goes beyond the margins so it reaches the other line............
\end{sample_text_with_noindentation}
which is bigger for long text
\begin{sample_text_with_noindentation}
random text which very long long long very long very long and it goes beyond the margins so it reaches the other line............
\end{sample_text_with_noindentation}
again even with {$\backslash$}noindent
\hrulefill
\begin{center}minipage without {$\backslash$}noindent in {$\backslash$}newenvironment in preamble\end{center}
\hrulefill
\begin{sample_text_without_noindentation}
\noindent random short text............
\end{sample_text_without_noindentation}
However, if you remove {$\backslash$}noindent
\begin{sample_text_without_noindentation}
random short text............
\end{sample_text_without_noindentation}
from the custom environment,
\begin{sample_text_without_noindentation}
\noindent random text which very long long long very long very long and it goes beyond the margins so it reaches the other line............
\end{sample_text_without_noindentation}
everything looks fine
\begin{sample_text_without_noindentation}
random text which very long long long very long very long and it goes beyond the margins so it reaches the other line............
\end{sample_text_without_noindentation}
(except the vertical spacing)
\hrulefill
\end{document}
答案1
发生的事情是,\noindent
在 的末尾将您置于水平模式,\begin{sample_text_with_noindentation}
因此后面的新行将\begin{sample_text_with_noindentation}
被解释为空格。简单的解决方案是\ignorespaces
在 后面添加\noindent
。