將文字調整為精確的特定尺寸

將文字調整為精確的特定尺寸

我想讓我的文字適合特定位置的特定大小的“框”。我遇到的兩個問題如下:

當這個長字串達到 4.5 英吋限制時,它應該換行,但事實並非如此:

\documentclass[landscape]{article}
\usepackage[top=1.5in, bottom=1.125in, left=.25in, right=6.25in,textwidth=4.5in, textheight=5.875in]{geometry}

\begin{document}
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd
\end{document}

這個保持不變,但我想強制它適合整個 4.5 英寸 x 5.875 英寸的盒子,就像放大文字以使其適合盒子一樣。

\documentclass[landscape]{article}
\usepackage[top=1.5in, bottom=1.125in, left=.25in, right=6.25in,textwidth=4.5in, textheight=5.875in]{geometry}

\begin{document}
{\Huge This should fit in a 4.5in x 5.875in box but that is close to the left edge of paper, but it is not conforming to the box size desired....
\end{document}

謝謝您的幫忙。

答案1

這可能是一份工作適合框包的選項tcolorbox。正如所評論的,您的第一個文字需要連字符。但是您的第二個文字可以使用以下程式碼調整大小。我添加了黃色背景來顯示 4.5 英寸 x 5.875 英寸的盒子。

請注意,我包含了一個可縮放字體包 ( lmodern) 來啟用字體縮放機制。

\documentclass[landscape]{article}
\usepackage[top=1.5in, bottom=1.125in, left=.25in, right=6.25in,textwidth=4.5in, textheight=5.875in]{geometry}
\usepackage{lmodern}% for scalable fonts!
\usepackage[many]{tcolorbox}

\begin{document}
\tcboxfit[blank,width=4.5in,height=5.875in,
  fit basedim=20pt,fit fontsize macros,valign=center,
  frame style={fill=yellow!50!white}% remove this line to remove the yellow background
]%
{\Huge This should fit in a 4.5in x 5.875in box but that is close to the left edge of paper, but it is not conforming to the box size desired....}
\end{document}

在此輸入影像描述

第一個程式碼調整字體以適合給定框中的文字。儘管如此,盒子的頂部和底部仍然有兩個非常小的空白區域。如果刪除它們很重要,可以使用以下程式碼添加最終拉伸。請注意,外框僅用於為範例著色。

\documentclass[landscape]{article}
\usepackage[top=1.5in, bottom=1.125in, left=.25in, right=6.25in,textwidth=4.5in, textheight=5.875in]{geometry}
\usepackage{lmodern}% for scalable fonts!
\usepackage[many]{tcolorbox}

\begin{document}
\tcbox[blank,width=4.5in,height=5.875in,frame style={fill=yellow!50!white}]{% just for the background
%
\resizebox{4.5in}{5.875in}{\tcboxfit[blank,width=4.5in,fit height from=5in to 5.875in,fit basedim=20pt,fit fontsize macros]%
{\Huge This should fit in a 4.5in x 5.875in box but that is close to the left edge of paper, but it is not conforming to the box size desired....}}
%
}% just for the background
\end{document}

在此輸入影像描述

相關內容