将文本居中、缩放和换行到图像顶部

将文本居中、缩放和换行到图像顶部

我可以使用哪些 LaTeX 包来使文本居中、缩放和换行,以满足以下条件:

  • 如果文本的宽度不如容器的宽度,则缩放文本以适应容器。
  • 如果文本比容器宽,则缩小文本以适应容器。
  • 如果文本缩小,请将文本换行,以免最终只剩下一个难以阅读的小段落。

我已经尝试过parbox、、和,pbox但没有一个能完全满足所有三个条件。tabularadjustbox

以下是要点:

\documentclass{article}

\usepackage[percent]{overpic}
\usepackage[outline]{contour}
\usepackage{fontspec}
\newfontfamily\headingText[Color=FFFFFF]{KnowYourProduct}

\newcommand{\myFrame}[1]  {
    \begin{overpic}[width=6cm,height=3cm,grid,tics=10]{Template}
        \put (8,25) {
            {\contourlength{0.025em}\contour{black}{\headingText #1}}
        }
    \end{overpic}
}   

\begin{document}

\myFrame{Title}
\myFrame{This Is A Long Title}
\myFrame{This title is so long that if you're still reading it you may want to reevaluate how you are presently squandering your personal time.}

\end{document}

答案1

抱歉,但我已经有足够多的问题了,无需再处理您的字体等问题。

\documentclass{article}
\usepackage{graphicx}

\newlength{\tempwidth}
\newlength{\temptest}
\newcount{\templines}

\newcommand{\myFrame}[1]% #1 = text
{\settowidth{\tempwidth}{#1}%
\ifdim\tempwidth>6cm \templines=0
  \loop\advance\templines by 1
    \temptest = 2\baselineskip% 6cm (width) / 3cm (height) = 2
    \multiply\temptest by \templines
    \multiply\temptest by \templines
    \ifdim\tempwidth>\temptest\repeat
  \divide\temptest by \templines
  \fbox{\resizebox*{6cm}{3cm}{\parbox{\temptest}{#1}}}%
\else \fbox{\resizebox*{6cm}{3cm}{#1}}%
\fi}

\begin{document}

\myFrame{Title}

\myFrame{This Is A Long Title}

\myFrame{This title is so long that if you're still reading it you may want to reevaluate how you are presently squandering your personal time.}

\end{document}

盒子

相关内容