[Tex/LaTex] How to give vertical margins inside a minipage

minipage

I want to give top and bottom margins inside minipages and tried using \vspace as shown below.

But this approach causes a pseudo line below the in-minipage text when the text width is almost fit to the minipage width. (Please compare the two minipages below)

Is there a better approach that prevents this issue?

\documentclass{article}

\begin{document}

When "vspace" is not inserted:

\fbox{
    \begin{minipage}{2.5cm}
        \raggedright
        AAA CD/ BB-2
    \end{minipage}
}

\vspace{30pt}

When "vspace" is inserted to give vertical margin in the minipage:

\fbox{
    \begin{minipage}{2.5cm}
    \vspace{2pt}
        \raggedright
        AAA CD/ BB-2
    \vspace{2pt}
    \end{minipage}
}

\end{document}

enter image description here

Best Answer

The posted code does not show the effect that you ask about, I changed the minipage width in the example below so the second example shows the problem.

enter image description here

The spurious white line is not caused by the \vspace but by the extra inter-word space that you added. You can avoid adding the space by commenting out the end of line or (better) always add a blank line before a \vspace so that it is added in vertical mode.

\documentclass{article}

\begin{document}

When "vspace" is not inserted:

\fbox{
    \begin{minipage}{2.5cm}
        \raggedright
        AAA CD/ BB-2
    \end{minipage}
}

\vspace{30pt}

When "vspace" is inserted to give vertical margin in the minipage:

\fbox{
    \begin{minipage}{2.55cm}
    \vspace{2pt}
        \raggedright
        AAA CD/ BB-2
    \vspace{2pt}
    \end{minipage}
}

\fbox{
    \begin{minipage}{2.55cm}
    \vspace{2pt}
        \raggedright
        AAA CD/ BB-2%
    \vspace{2pt}
    \end{minipage}
}

\fbox{
    \begin{minipage}{2.55cm}
    \vspace{2pt}
        \raggedright
        AAA CD/ BB-2

    \vspace{2pt}
    \end{minipage}
}

\end{document}