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.

  • 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. – Ulrike Fischer Sep 14 '17 at 12:27
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

  • 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... – Thomas F. Sturm Sep 14 '17 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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.