0

I am using minipages to arrange three verbatim blocks horizontally. Here is my code:

\section*{Problem 1 : Solution} 
    \begin{enumerate}[label={(\alph*)}]
        \item Excuting the following code, we can get: \\ \\
        \begin{minipage}[t]{0.3\linewidth}
            \begin{verbatim}
                y=rnorm(10,50,7)
                stem(y)
                qqnorm(y)

                  3 | 7
                  4 | 2368
                  5 | 15
                  6 | 355
            \end{verbatim}
        \end{minipage}
%
        \begin{minipage}[t]{0.3\linewidth}
            \begin{verbatim}
                y=rnorm(10,50,7)
                stem(y)
                qqnorm(y)

                  3 | 07
                  4 | 13567
                  5 | 135
            \end{verbatim}
        \end{minipage}
%
        \begin{minipage}[t]{0.3\linewidth}
            \begin{verbatim}
                y=rnorm(10,50,7)
                stem(y)
                qqnorm(y)

                  3 | 
                  3 | 5
                  4 | 
                  4 | 77
                  5 | 011334
                  5 | 6
            \end{verbatim}
        \end{minipage}

        \item
        \item
    \end{enumerate}

It looks pretty good:

enter image description here

However, if I get rid of the two % signs separating minipages, I would get the following result:

enter image description here

I thought % in latex is only for commenting. My question is why do we add % between minipages? Is that the rule of using minipages?

3
  • 5
    I think this is just the standard % eating the new line, see What is the use of percent signs (%) at the end of lines? You should see the same if you get rid of the blank line between \end{minipage} and \begin{minipage}.
    – Dai Bowen
    Nov 20, 2016 at 22:13
  • 9
    An empty line gives a new paragraph. If you comment the empty line it isn't there any more. You don't need minipages, simple words would show the same effect. Nov 20, 2016 at 22:13
  • 1
    Without the % you have a blank line which is, as usual, the way you insert a paragraph break. With the % you have just spaces between them because the previous line ending is not commented \end{minipage} and a line ending is interpreted as a space.
    – cfr
    Nov 20, 2016 at 23:10

1 Answer 1

1

There is nothing special about minipage here, you are just removing a paragraph break, normally you should also have a % after minipage to remove the word space as well, compare 1 2 and 3 below which are the same as your examples but using words rather than minipage.

enter image description here

(1) has word spaces (2) has no space (3) has paragraph beaks.

\documentclass{article}

\begin{document}

1 one
%
two
%
three

2 one%
%
two%
%
three

3 one

two

three

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .