I am writing a document class, which has a few custom text elements. The text elements have concrete requirements regarding color, font family, size, leading etc. I have created a few custom commands and I would like them to behave like \small
, \large
etc. My current approach is
\NewDocumentCommand { \MarginFont } { }
{ \color{gray}\normalfont\fontsize{8pt}{10.4pt}\selectfont }
However, this does not always behave as expected, e.q. sometimes an extra linebreak is inserted as in the following MWE
\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage{xcolor}
\usepackage{xparse}
\usepackage{blindtext}
\NewDocumentCommand { \MarginFont } { }
{ \color{gray}\normalfont\fontsize{8pt}{10.4pt}\selectfont }
\setlength{\parindent}{0pt}
\begin{document}
\begin{minipage}[t]{0.5\linewidth}
\blindtext
\end{minipage}\hfill%
\begin{minipage}[t]{0.45\linewidth}
{\MarginFont \blindtext\par}
\end{minipage}
\vspace*{2cm}
\begin{minipage}[t]{0.5\linewidth}
\blindtext
\end{minipage}\hfill%
\begin{minipage}[t]{0.45\linewidth}
{\small \blindtext\par}
\end{minipage}
\end{document}
The minipage
with the \MarginFont
is for some reason not correcty aligned. This does not happen when I use any LaTeX size command such as \small
.
In the Document Classes Documentation, I found the much more sophisticated code for the definition of \small
.
\DeclareRobustCommand\small{%
⟨*10pt⟩
\@setfontsize\small\@ixpt{11}%
\abovedisplayskip 8.5\p@ \@plus3\p@ \@minus4\p@
\abovedisplayshortskip \z@ \@plus2\p@
\belowdisplayshortskip 4\p@ \@plus2\p@ \@minus2\p@
\def\@listi{\leftmargin\leftmargini
\topsep 4\p@ \@plus2\p@ \@minus2\p@
\parsep 2\p@ \@plus\p@ \@minus\p@
\itemsep \parsep}%
⟨/10pt⟩
How can I change my definition to behave the same? Also, will TeX loose is ability to produce well formatted paragraphs, if I set a fixed baselineskip
instead of the various definitions with plus
and minus
. If so, how can I add this behaviour to my custom font commands?
Bonus question: Currently, the user has to add a \par
before closing the group in order for the baselineskip
to take effect. Is there a smarter way to define the commands such that this is no longer required? I know, that with the minipage the group braces are not needed, but these commands should also be used inside normal text.
Edit: I know that adding \vspace{0pt}
can fix the alignment, but I am interested what caused it in the first place.
texdoc grfguide
footnote page 6\vspace{0pt}
wouldn't really fix the alignment, it just makes it wrong on both sides so the error is less apparent.\color
\vspace{0pt}
inserts to much vertical space if the minipages are enclosed in other text.\color
) it moves the reference point of the minipage to the top edge (above the capital L) rather than the first baseline (the base of the capital L) see the image you posted for the\small
example if you added vspace0pt to both sides the small text would all move up so that the top of the\small L
aligned with the top of the normalsizeL