我怎样才能在环境中有两条线 - 一条在文本(或数字)的上方,一条在下方align
。就像儿童数学题中的和一样。在给定的示例中,我需要在最后一行的 26 上方和下方各有一条线,而不会对行距产生很大影响。我更喜欢不用表格。
\textbf{Amy has 12 red buttons and 14 green buttons. How many buttons does she have in all?} \par
\vspace{5mm}
\begin{align*}
&\text{Number of red buttons} & & 12\\
&\text{Number of green buttons} & &14\\
&\text{Total number of buttons Amy has} & &26\\
\end{align*}
答案1
tabular
您可以在顶部和底部设置答案\hline
。为了确保它不影响行距,\smash
它:
\documentclass{article}
\usepackage{amsmath}
\newcommand{\Answer}[1]{\smash{\begin{tabular}{l} \hline #1 \\ \hline \end{tabular}\hspace*{-\tabcolsep}}}
\begin{document}
\noindent
Amy has 12 red buttons and 14 green buttons. How many buttons does she have in all?
\begin{align*}
& \text{Number of red buttons} & 12 \\
& \text{Number of green buttons} & 14 \\
& \text{Total number of buttons Amy has} & \Answer{26}
\end{align*}
\noindent
Amy has 12 red buttons and 14 green buttons. How many buttons does she have in all?
\begin{center}
\begin{tabular}{ l @{\qquad} r }
Number of red buttons & 12 \\
Number of green buttons & 14 \\
Total number of buttons Amy has & \Answer{26}
\end{tabular}
\end{center}
\end{document}
您也可以在中设置内容tabular
,并调整垂直填充如果需要的话,与 相匹配align
。
答案2
另一个简单的解决方案:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
Amy has 12 red buttons and 14 green buttons. How many buttons does she have in all?
\begin{align*}
& \text{Number of red buttons} & 12 \\
& \text{Number of green buttons} & 14 \\
& \text{Total number of buttons Amy has} & \smash{\overline{\underline{26\mathstrut}}}
\end{align*}
\end{document}