我按照所述方式在 varwidth 环境中使用 microtype这里。它对对齐文本很有效,但现在我有像诗句一样的非常短的文本。有时微打字可以工作,有时不工作...为什么?有解决办法吗?
\documentclass{article}
\usepackage[paperwidth=140mm,paperheight=210mm,nomarginpar, noheadfoot,left=20mm,right=20mm,top=20mm,bottom=40mm,showframe]{geometry}
\usepackage{microtype}
\usepackage{varwidth}
%make microtype work inside varwidth
\makeatletter
\newdimen\@vwid@leftmargin
\newdimen\@vwid@rightmargin
\def\@vwid@sift{%
\skip@\lastskip\unskip
\dimen@\lastkern\unkern
\count@\lastpenalty\unpenalty
\setbox\z@\lastbox
%{\showoutput\showbox\z@}%
\ifvoid\z@ \advance\sift@deathcycles\@ne \else
% --- record left/right margin kerning ---
\@vwid@leftmargin \leftmarginkern \z@ % <--
\@vwid@rightmargin\rightmarginkern\z@ % <--
\sift@deathcycles\z@ \fi
\ifnum\sift@deathcycles>33
\let\@vwid@sift\relax
\PackageWarning{varwidth}{Failed to reprocess entire contents}%
\fi
%\message{\the\sift@deathcycles: skip \the\skip@; kern \the\dimen@; penalty \the\count@. }%
%\ifhbox\z@\setbox99\hbox to0pt{\unhcopy\z@}\fi % = message
\ifnum\count@=\@vwid@preeqp \@vwid@eqmodefalse\fi
%\ifnum\count@=\@vwid@preeqp \message{End equation mode. }\fi
\ifnum\count@=\@vwid@posteqp \@vwid@eqmodetrue\fi
%\ifnum\count@=\@vwid@posteqp\message{Begin equation mode. }\fi
%\if@vwid@eqmode {\showoutput\showbox\z@}\fi
\ifnum\count@=\@vwid@toppen % finished
\let\@vwid@sift\relax
\else\ifnum\count@=\@vwid@offsets
\@vwid@setoffsets
\else
\ifnum\count@=\@vwid@postw
\else
\@vwid@resetb % reset box \z@ or measure it
\fi
\@vwid@append
\fi\fi
\@vwid@sift}
\def\@vwid@resetb{%
\setbox\z@\vbox\bgroup
\ifvoid\z@
\else
\ifvbox\z@
\box\z@
\else % \hbox
\@tempdima\hsize
\advance\@tempdima-\@vwid@roff
\advance\@tempdima-\@vwid@loff
\advance\@tempdima-\p@
%\message{Test if \the\wd\z@ > \the\@tempdima, }%
\ifdim\wd\z@>\@tempdima % full-width line; rebox it
%\message{An ordinary line or alignment. (\the\wd\z@ > \the\@tempdima) }%
\hbox to\hsize
{\kern\@vwid@loff
% --- reinsert margin kerning ---
\ifdim\@vwid@leftmargin=\z@\else\kern\@vwid@leftmargin\fi % <--
\unhbox\z@
\ifdim\@vwid@rightmargin=\z@\else\kern\@vwid@rightmargin\fi % <--
\kern\@vwid@roff}%
\else % an equation or direct \hbox
\if@vwid@eqmode % re-center unnumbered equations
%\message{A centered equation hsize=\the\hsize. }%
\hbox to\hsize
{\hskip\@vwid@loff\@plus1fil
\unhbox\z@ \hskip\@vwid@roff\@plus1fil}%
\else % plain narrow \hbox; leave it as-is
%\message{Plain narrow box}%
\box\z@
\fi\fi\fi\fi
\egroup}
\makeatother
\begin{document}
\hfill\begin{varwidth}{.5\textwidth}
\raggedright
Lorem ipsum, dolor sit amet
Consectetur adipiscing elit, sed, do
Eiusmod tempor, incididunt ut
Labore et dolore.
Ut enim, ad minim veniam, quis, nostrud
Exercitation ullamco
\end{varwidth}\strut
\hfill\begin{varwidth}{.5\textwidth}
\raggedright
Lorem ipsum, dolor sit
Consectetur adipiscing elit, сonsectetur
Eiusmod tempor,
Labore et dolore.
Ut enim, ad minim
Exercitation ullamco
\end{varwidth}
\end{document}
答案1
尽管有人质疑,对于粗糙的文本来说,突出是否毫无意义,我的补丁你提到的内容根本不完整。你还需要添加以下内容:
\def\@vwid@measure{%
\ifvoid\z@
\else
% numbered equations not part of alignments can't be reset,
% so force retention of full width.
\ifnum\count@=\@vwid@postnump \ifdim\wd\z@<\linewidth
\ifdim\@tempdima<\linewidth \@tempdima\linewidth \fi
\fi\fi
\ifhbox\z@
\setbox\z@=\hbox
{\kern\@vwid@loff
\ifdim\@vwid@leftmargin=\z@\else\kern\@vwid@leftmargin\fi % <--
\unhbox\z@
\ifdim\@vwid@rightmargin=\z@\else\kern\@vwid@rightmargin\fi % <--
\kern\@vwid@roff}%
\fi
\ifdim\wd\z@>\@tempdima \@tempdima\wd\z@ \fi
\fi}
[我现在也将其添加到了另一个答案中。]