10

I want to scale a boxed text with very tiny font sizes.

The problem is, that on a certain scale the box gets some final vertical glue. If the text is put into a savebox, the problem starts when the savebox has a depth value of 0pt. I guess that TeX puts in some skip value when my lines are getting too small, but I could not figure out how to prevent that effect.

The following MWE displays the problem:

\documentclass{article}

\usepackage{lmodern}

\newlength\myfontdim

\newcommand{\mytest}[1]{%
  \myfontdim=#1%
  \noindent\fboxsep0pt%
  \fbox{\begin{minipage}{1cm}
    \fontsize{\myfontdim}{\dimexpr 1.05\myfontdim}\selectfont
    \parskip 0.15\myfontdim plus 0pt minus 0pt\par
    A\par
    in\par
    Test
  \end{minipage}}
}%


\begin{document}

\mytest{10pt}

\mytest{5pt}

\mytest{1pt}

\mytest{0.5pt}

\end{document}

The output is

enter image description here

Here, box 1 and 2 are nearly as expected and the top and bottom rule are close to the glyphs.

But, box 3 and 4 have some final glue and the bottom line does not touch the word 'Test'.

The main question is, what has to be changed such that this final glue disappears? The problem seems connected with the 0pt depth value of boxes 3 and 4.

An additional question is, why the three text lines in the boxes have a different relative distance to each other. With the used font size and parskip value, I would have expected roughly the same (relative) distance between the text lines.

1
  • It is not a final glue. When the minipage is centered, internally \vcenter is used, and if you set the fontsize inside the \vcenter it doesn't affect the math values. Sep 14, 2017 at 12:27

2 Answers 2

10

There is no final glue. The problem is that centered minipages (and \parbox) uses internally \vcenter, and it centers along the math axis -- which in turn depends on the current font size. So it matters if you change the font inside or before the minipage:

\documentclass{article}

\usepackage{lmodern}

\newlength\myfontdim

\newcommand{\mytest}[1]{%
  \myfontdim=#1%
  \noindent\fboxsep0pt%
  $\frac{a}{a}$ x
  \fbox{%
   $\vcenter {\hbox to 1cm {\fontsize{\myfontdim}{\dimexpr 1.05\myfontdim}\selectfont x\hfil}}$}
  \fbox{%
   \fontsize{\myfontdim}{\dimexpr 1.05\myfontdim}\selectfont
   $\vcenter {\hbox to 1cm {x\hfil}}$}
}%


\begin{document}

\mytest{10pt}

\mytest{5pt}

\mytest{1pt}

\mytest{0.5pt}

\end{document}

enter image description here

1
  • Thank you: I was on the false track when looking for a phantom glue. Now, I see that I should have not used the standard minipage option for my real world problem... I will try to change that under the hood without breaking other things... Sep 14, 2017 at 14:49
9

Add [b] to the minipage.

\documentclass{article}

\usepackage{lmodern}

\newlength\myfontdim

\newcommand{\mytest}[1]{%
  \myfontdim=#1%
  \noindent\fboxsep0pt%
  \fbox{\begin{minipage}[b]{1cm}
    \fontsize{\myfontdim}{\dimexpr 1.05\myfontdim}\selectfont
    \parskip 0.15\myfontdim plus 0pt minus 0pt\par
    A\par
    in\par
    Test
  \end{minipage}}
}%


\begin{document}

\mytest{10pt}

\mytest{5pt}

\mytest{1pt}

\mytest{0.5pt}

\end{document}

enter image description here

Alternately, depending on how you want the line spacing external to your \fbox, put the \fontsize before the minipage (within a group):

\documentclass{article}

\usepackage{lmodern}

\newlength\myfontdim

\newcommand{\mytest}[1]{%
  \myfontdim=#1%
  \noindent\fboxsep0pt%
  \bgroup%
  \fontsize{\myfontdim}{\dimexpr 1.05\myfontdim}\selectfont
  \fbox{\begin{minipage}{1cm}
    \parskip 0.15\myfontdim plus 0pt minus 0pt\par
    A\par
    in\par
    Test
  \end{minipage}}%
  \egroup%
}%


\begin{document}

\mytest{10pt}

\mytest{5pt}

\mytest{1pt}

\mytest{0.5pt}

\end{document}

enter image description here


Without the grouping, the line-spacing shrinks, but of course, the smaller font size persists outside of your macro.

\documentclass{article}

\usepackage{lmodern}

\newlength\myfontdim

\newcommand{\mytest}[1]{%
  \myfontdim=#1%
  \noindent\fboxsep0pt%
  \fontsize{\myfontdim}{\dimexpr 1.05\myfontdim}\selectfont
  \fbox{\begin{minipage}{1cm}
    \parskip 0.15\myfontdim plus 0pt minus 0pt\par
    A\par
    in\par
    Test
  \end{minipage}}
}%


\begin{document}

\mytest{10pt}

\mytest{5pt}

\mytest{1pt}

\mytest{0.5pt}

\end{document}

enter image description here

2
  • In this case, I would have liked to be able to accept two answers, because your answer is also very helpful to me! Sep 14, 2017 at 14:40
  • @ThomasF.Sturm Thanks. But \rules are \rules. Sep 14, 2017 at 17:31

You must log in to answer this question.

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