6

If I uncomment the first line of the minipage, the minipage is then too big to fit on the page. What's happening here?

\documentclass{article}
\usepackage{xcolor}
\usepackage{lipsum}
\pagestyle{empty}
\begin{document}

\noindent%
\fbox{%
\begin{minipage}
      [t][\dimexpr\textheight-2\fboxrule-2\fboxsep\relax]
         {\dimexpr\linewidth-2\fboxrule-2\fboxsep\relax}
%    \color{blue}

    \lipsum[1-2]

\end{minipage}}

\lipsum[1-2]

\end{document}
egreg
  • 1,121,712
A.Ellett
  • 50,533
  • 2
    Why don't you set \color{blue} before the minipage, just at the start of \fbox? The problem is \color{blue} before starting a paragraph, which creates every kind of evil. – egreg Jun 25 '13 at 16:06
  • Replacing \color{blue} with \leavevmode has the same effect. –  Jun 25 '13 at 16:11
  • @egreg, great! I'd imagined that. But why does it start a paragraph? What is the advantage on it? – Sigur Jun 25 '13 at 16:11
  • @jfbu Yes, but creates a one line paragraph, if the blank line is not removed. – egreg Jun 25 '13 at 16:11
  • @egreg Is there a place where I can learn what these various evils are? Also, what other commands before a paragraph will also create every kind of evil? – A.Ellett Jun 25 '13 at 16:12
  • @egreg sorry I meant has the same effect as the original code not has the same effect as your suggestion !! Indeed I left the blank line. –  Jun 25 '13 at 16:14
  • 1
    @egreg and I was going to add use \leavevmode\color{blue}\lipsum etc... but David's answer came in-between... –  Jun 25 '13 at 16:15
  • @jfbu sorry only saw this comment thread apart from egregs initial comment after I posted:-) – David Carlisle Jun 25 '13 at 16:19
  • @DavidCarlisle ... one has to be quick here, and when I saw one new answer I knew without any need to click that the creator of the thing was probably settling up the matter! ;-) –  Jun 25 '13 at 16:23

1 Answers1

7

It's a feature (documented even) of the color package that it will mess up alignment in this instance. grfguide.tex distributed with LaTeX says

There is a different type of problem that will occur for all drivers. Due to certain technical difficulties\footnote{At least two causes: 1) The presence of a \special whatsit prevents \addvspace 'seeing' space on the current vertical list, so causing it to incorrectly add extra vertical space. 2) A whatsit as the first item in a \vtop moves the reference point of the box.}

and \begin{minipage}[t] is a \vtop.

So you can use \leavevmode\color{blue} If you can place the color immediately before the text of the box (ie no blank line, or \begin{enumerate} etc) or as egreg suggested in comments move the color out of the vertical box and place it at the start of the \fbox.

David Carlisle
  • 757,742
  • What exactly is a whatsit? – A.Ellett Jun 25 '13 at 16:24
  • 1
    @A.Ellett: See http://tex.stackexchange.com/a/43174/2975 – Martin Scharrer Jun 25 '13 at 16:28
  • 3
    That's probably a new question. TEX lists can contain various types of things horizontal and vertical boxes, glue, kerns, penalties, rules, characters, marks, inserts, discretionaries and whatsits which are a hypothetical extension point for implementers to add new node types but two "example" whatsits are defined write nodes and \special (and some pdftex built-in special-like commands like \pdfliteral) so color is marked by soomething like \special{postscript command for blue} but that is a node in the vertical list before text so forms the reference point of minipage[t] – David Carlisle Jun 25 '13 at 16:32