我正在学习如何使用框来布置文本块。
我正在把一个\makebox
和\minipage
放在一起。在示例一中看起来很棒。但是当我在示例\Large
二中使用 makebox 增加字体大小时,文本会移动向上进入\vspace
。有人能帮我了解发生了什么以及如何解决它吗?
\documentclass[12pt]{article}
\usepackage{xcolor}
\begin{document}
\vspace{5mm}
\hrule
\vspace{2mm}
\noindent\makebox[1.7cm][l]{\textbf{50.12}}
\minipage[t]{\dimexpr\textwidth-1.7cm\relax}
Here is just some more text. It is for testing stuff. I wonder if this will work. Here is some more textm it is about enough now.
\endminipage
\vspace{5mm}
\hrule
\vspace{2mm}
\noindent\makebox[1.7cm][l]{\textbf{\Large 50.12}}
\minipage[t]{\dimexpr\textwidth-1.7cm\relax}
Here is just some more text. It is for testing stuff. I wonder if this will work. Here is some more textm it is about enough now.
\endminipage
\end{document}
答案1
即使这不是问题的原因,绝不在环境中使用\minipage
and 。始终对环境使用and语法。定义新环境时可以使用and语法。\endminipage
document
\begin
\end
\foo
\endfoo
TeX 对齐了框的参考点;包含数字的框的参考点是其基线,而 的参考点minipage
是顶线的基线(因为[t]
)。您需要降低数字,但也要使其深度为零。
您可能希望将数字的顶部与文本的顶部对齐,但您必须确保文本至少超过两行。如果需要,可以通过进一步的工作来提高此限制。找到一个比 更好的名称foo
。
\documentclass[12pt]{article}
\newenvironment{foo}[1]
{%
\par\addvspace{5mm}%
\hrule
\nopagebreak\vspace{2mm}%
\noindent\vphantom{T}%
\raisebox{\dimexpr\fontcharht\font`T-\height}[0pt][0pt]{\makebox[1.7cm][l]{\Large#1}}%
\begin{minipage}[t]{\dimexpr\textwidth-1.7cm\relax}%
}{%
\end{minipage}\par\addvspace{5mm}%
}
\begin{document}
\begin{foo}{50.12}
Here is just some more text. It is for testing stuff. I wonder if this
will work. Here is some more textm it is about enough now.
\end{foo}
\end{document}
答案2
正如 Ulrike 所说,Tex 希望根据基线而不是上限来对齐事物。
获得两个不同字体大小的框的文字顶部对齐的一种方法是使用包\belowbaseline
的宏stackengine
来设置两者的顶部\makebox
以及\minipage
低于基线的固定距离,在本例中距离为-\ht\strutbox
。
\documentclass[12pt]{article}
\usepackage{xcolor,stackengine}
\begin{document}
\vspace{5mm}
\hrule
\vspace{2mm}
\noindent\makebox[1.7cm][l]{\textbf{50.12}}
\minipage[t]{\dimexpr\textwidth-1.7cm\relax}
Here is just some more text. It is for testing stuff. I wonder if this will work. Here is some more textm it is about enough now.
\endminipage
\vspace{5mm}
\hrule
\vspace{2mm}
\noindent\belowbaseline[-\ht\strutbox]{\makebox[1.7cm][l]{\textbf{\Large 50.12}}}
\belowbaseline[-\ht\strutbox]{\minipage[t]{\dimexpr\textwidth-1.7cm\relax}
Here is just some more text. It is for testing stuff. I wonder if this will work. Here is some more textm it is about enough now.
\endminipage}
\end{document}