宽度适合(缩小!)逐字逐句,可能会破坏页面

宽度适合(缩小!)逐字逐句,可能会破坏页面

是否有一个逐字变体可以检查内容是否超出 \textwidth,并且 [如果是] 缩小逐字内的内容 (字体大小) 以适合文本宽度?(pdflatex 是一个可以满足的要求。)

理想情况下,这也可以跨页面起作用。

答案1

您可以在框中逐字逐句地进行操作,然后查看并找到最长的行,然后再次循环并缩放所有行,以便最长的行\textwidth

在此处输入图片描述

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\makeatletter
\global\setbox1\vbox{}
\setbox0\vbox{%
\hsize0pt
\hfuzz\maxdimen
\begin{verbatim}
ab
abc
1234567890
123456789012345678901234567890
12345678901234567890123456789012345678901234567890
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
555
abcdefg
\cos\sin\tan
abcde abcde abcde abcde abcde abcde abcde 
*
 *
  *
   *
    *
     *
      *
       *
        *
         *
          *
 PPPPPPPPPPP
ab
abc
1234567890
123456789012345678901234567890
12345678901234567890123456789012345678901234567890
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
555
abcdefg
\cos\sin\tan
abcde abcde abcde abcde abcde abcde abcde 
*
 *
  *
   *
    *
     *
      *
       *
        *
         *
          *
 PPPPPPPPPPP
ab
abc
1234567890
123456789012345678901234567890
12345678901234567890123456789012345678901234567890
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
555
abcdefg
\cos\sin\tan
abcde abcde abcde abcde abcde abcde abcde 
*
 *
  *
   *
    *
     *
      *
       *
        *
         *
          *
 PPPPPPPPPPP
ab
abc
1234567890
123456789012345678901234567890
12345678901234567890123456789012345678901234567890
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
555
abcdefg
\cos\sin\tan
abcde abcde abcde abcde abcde abcde abcde 
*
 *
  *
   *
    *
     *
      *
       *
        *
         *
          *
 PPPPPPPPPPP

\end{verbatim}
\dimen1=0pt
\loop
\ifnum\lastnodetype=-1
\else
\ifnum\lastnodetype=11 \skip0\lastskip\unskip\global\setbox2\vbox{\vskip\skip0\unvbox2}\fi
\ifnum\lastnodetype=13 \count0\lastpenalty\unpenalty\global\setbox2\vbox{\penalty\count0\unvbox2}\fi
\ifnum\lastnodetype=1 \setbox4\lastbox\global
  \setbox2\vbox{\hbox{\unhbox4}\unvbox2}%
  \ifdim\wd2>\dimen0 \dimen0=\wd2 \fi
\fi
\repeat
\unvbox2
\Gscale@div\@tempa\textwidth{\dimen0}%
\loop
\ifnum\lastnodetype=-1
\else
\ifnum\lastnodetype=11 \skip0\lastskip\unskip\global\setbox2\vbox{\vskip\skip0\unvbox2}\fi
\ifnum\lastnodetype=13 \count0\lastpenalty\unpenalty\global\setbox2\vbox{\penalty\count0\unvbox2}\fi
\ifnum\lastnodetype=1 \setbox4\lastbox\global\setbox2\vbox{\hbox{\scalebox\@tempa{\unhbox4}}\unvbox2}\fi
\repeat
}


\unvbox2

\end{document}

相关内容