GeneralUnexplained Vertical spacing outside of minipage

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
robertjlee
Posts: 17
Joined: Thu Aug 07, 2008 7:51 pm

Unexplained Vertical spacing outside of minipage

Post by robertjlee »

Please help me understand what causes this extra space, or how to kill it.

To align multiple boxes vertically, without any additional space between them, I'm generating each box with a minipage environment, to exactly control the size (and eventually to use multi-paragraph text).

There is 1pt of vertical space appearing between the boxes, and it doesn't seem to be controlled by \baselineskip, \parsep, \parskip, or similar, and I'm lost as to where it's coming from. It seems to be exactly 1pt every time, and it is throwing off the vertical alignment. The same space appears whether I separate the boxes with a line-break or a new paragraph.

Here is my MWE. The first column contains 3 rules, each 1in high, and the second contains a single rule 3in high. I expect both columns to be exactly 3in high, but the first one contains two extra 1pt spaces, seen as white gaps between the rules.

I've tried various combinations of the alignment options for minipage, to no effect.

Code: Select all

\documentclass{minimal}
\usepackage{color}

\begin{document}

\setlength{\parsep}{0pt}
\setlength{\parskip}{0pt}
\setlength{\parindent}{0pt}
\setlength{\abovedisplayskip}{0pt}
\setlength{\belowdisplayskip}{0pt}
\renewcommand{\baselinestretch}{1}

\begin{minipage}[b][3in][s]{0.25in}%
  \begin{minipage}[b][1in][s]{0.250in}%
    \textcolor{red}{\rule{0.25in}{1in}}%
  \end{minipage}\par% 1pt extra space; why?
  \begin{minipage}[b][1in][s]{0.250in}%
    \textcolor{green}{\rule{0.25in}{1in}}%
  \end{minipage}\\% 1pt extra space; why?
  \begin{minipage}[b][1in][s]{0.250in}%
    \textcolor{blue}{\rule{0.25in}{1in}}%
  \end{minipage}
\end{minipage}% minipage gives no overfull warnings.
\begin{minipage}[b][3in][s]{0.25in}%
  \rule{0.25in}{3in}% does not line up.
\end{minipage}

\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

rais
Posts: 419
Joined: Sun Nov 16, 2014 8:51 pm

Unexplained Vertical spacing outside of minipage

Post by rais »

Well, \parsep has no effect, because it's used as vertical skip between paragraphs within an item of a list environment, such as enumerate or itemize.
\parindent would be a horizontal, not vertical skip at the beginning of a new paragraph.
\abovedisplayskip/\belowdisplayskip are only inserted for displayed math environments, such as equation or \[..\] to name a few.
\baselinestretch is 1 by default.
Interestingly enough, \parskip's default is 0pt plus 1pt, but as you already found out, this is not where your 1pt skip is coming from---that should be \lineskip in this case.
You could add \nointerlineskip after \par before the next minipage to get rid of that skip. This is limited to a single instance, though.
OTOH, you could put your colored boxes all on one line:

Code: Select all

\documentclass{minimal}
\usepackage{color}

\begin{document}

  \makebox[0pt][l]{%
    \color{red}\rule[2in]{0.25in}{1in}}%
  \makebox[0pt][l]{%
    \color{green}\rule[1in]{0.25in}{1in}}%
  {\color{blue}\rule{0.25in}{1in}}%
  \rule{0.25in}{3in}% should line up.

\end{document}
then you won't have to worry about what TeX puts between lines ;)
You may need to put a minipage around the whole thing to prevent (La)TeX from inserting something like a page break, though.

However, if you wish to pursue this matter further, have a look at TeXbyTopic, chapter `Baseline Distances'.

KR
Rainer
robertjlee
Posts: 17
Joined: Thu Aug 07, 2008 7:51 pm

Unexplained Vertical spacing outside of minipage

Post by robertjlee »

Thank you so much. I was looking everywhere online for information on TeX's vertical spacing, and had little luck in tracking this down. I read Tex by Topic years ago and should have tried there!

\nointerlineskip works beautifully. I will look into the \makebox approach as well; it looks a lot tidier.

—Robert.
Post Reply