将文本调整至精确的特定尺寸

将文本调整至精确的特定尺寸

我想让我的文本适合特定位置的特定大小的“框”。我遇到的两个问题如下:

这条长字符串在达到 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}

在此处输入图片描述

相关内容