0

I wanted to create a newenvironment which included a minipage. However, I discovered that when inserting the \noindent command inside this minipage it creates extra space in the beginning of the line. Additionally, this spaces seems to be different when the text is long!

Also, the vertical spacing seems to behave differently within and outside a minipage.

enter image description here

Can someone explain why this is happening?

Here is the code that created this picture:

\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}
0

What's happening is that the \noindent puts you into horizontal mode at the end of the \begin{sample_text_with_noindentation} so as a consequence the new line after \begin{sample_text_with_noindentation} is interpreted as a space. The simple solution is to add \ignorespaces after \noindent.

3
  • So, why is there a space of different length when the text is long? And why is the vertical spacing like this?
    – Jim
    Apr 13 '21 at 4:39
  • 1
    The space is an ordinary inter-word space. In your third case, the space is larger because it stretches to justfiy the line. The vertical spacing is because the minipage does not have any depth on the last line. You could add \strut before \end{minipage} and that would work, although you need to take care that the \strut doesn't go to a new line. Something like \ifhmode\unskip\strut\fi should do the trick.
    – Don Hosek
    Apr 13 '21 at 4:48
  • I see. This makes sense now, thank you very much!
    – Jim
    Apr 13 '21 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.