我想显示分数
但有一个过度支撑的说法number 7 appears n times
和一个支撑不足的说法number 8 appears n times
。
我希望自动确定最小点数,以便
上方标签最右边的字符7、5以及水平线的右端均与同一垂直线对齐。
下方标签最左边的字符8、1以及水平线的左端均与同一垂直线对齐。
平均能量损失
\documentclass[border=12pt,12pt]{standalone}
\usepackage{amsmath}
\begin{document}
$\displaystyle\frac{1\overbrace{7\dots 7}^{\text{number 7 appears $n$ times}}}{\underbrace{8\dots 8}_{\text{number 8 appears $n$ times}}5}$
\end{document}
如何根据上面给出的约束自动确定最少填充点数?
编辑
通过反复试验,我得到了以下内容,但我想要一种更聪明的方法。
\documentclass[border=12pt,12pt]{standalone}
\usepackage{amsmath}
\begin{document}
$\displaystyle\frac{1\overbrace{7..........................7}^{\text{number 7 appears $n$ times}}}{\underbrace{8..........................8}_{\text{number 8 appears $n$ times}}5}$
\end{document}
答案1
我不确定我是否理解了这些限制,但也许
\documentclass[border=12pt,12pt]{standalone}
\usepackage{amsmath}
\def\zz#1#2#3#4{%
\setbox0\hbox{$\scriptstyle#4$}%
#1{\hbox to \wd0{$#2$}}#3{#4}%
}
\begin{document}
$\displaystyle
\frac
{1\zz\overbrace{7\dotfill7}^{\text{number 7 appears $n$ times}}}
{\zz\underbrace{8\dotfill 8}_{\text{number 8 appears $n$ times}}5}
$
\end{document}
或按照 jfbu 的要求使用对齐点(需要 luatex)
\RequirePackage{luatex85}
\documentclass[border=12pt,12pt]{standalone}
\usepackage{amsmath}
\def\zz#1#2#3#4{%
\setbox0\hbox{$\scriptstyle#4$}%
#1{\hbox to \wd0{$\let\cleaders\gleaders#2$}}#3{#4}%
}
\begin{document}
$\displaystyle
\frac
{1\zz\overbrace{7\dotfill7}^{\text{number 7 appears $n$ times}}}
{\zz\underbrace{8\dotfill 8}_{\text{number 8 appears $n$ times}}5}
$
\end{document}
不确定看起来更好
答案2
以下是一些可供使用的选项:
\documentclass{article}
\usepackage{mathtools}
\begin{document}
\[
\frac
{1\overbrace{\makebox[5em]{7\dotfill 7}}^{\clap{\scriptsize\begin{tabular}{c} number 7 appears \\ $n$ times \end{tabular}}}}
{\underbrace{\makebox[5em]{8\dotfill 8}}_{\clap{\scriptsize\begin{tabular}{c} number 8 appears \\ $n$ times \end{tabular}}}5}
\]
\[
\frac
{1\overbrace{\makebox[5em]{7\dotfill 7}}^{\mathclap{\text{number 7 appears $n$ times}}}}
{\underbrace{\makebox[5em]{8\dotfill 8}}_{\mathclap{\text{number 8 appears $n$ times}}}5}
\]
\[
\frac
{1\makebox[5em]{7\dotfill 7}\mathllap{\overbrace{\rule{5em}{0pt}\vphantom{7}}^{\mathclap{\text{number 7 appears $n$ times}}}}}
{\mathrlap{\underbrace{\rule{5em}{0pt}\vphantom{8}}_{\mathclap{\text{number 8 appears $n$ times}}}}\makebox[5em]{8\dotfill 8}5}
\]
\end{document}
您可以调整我选择的宽度5em
,使内容间隔更大。选项 2 和 3 之间的区别在于非括号数字旁边的间距。
答案3
我相信。
\documentclass{article}
\usepackage{amsmath}
\newlength{\ntimeslen}
\newcommand{\ntimes}[2]{%
\settowidth{\ntimeslen}{$\scriptstyle\text{number $#2$ appears $n$ times}$}%
#1{\makebox[\ntimeslen][s]{$#2\dotfill#2$}}%
\ifx#1\overbrace^\else_\fi
{\text{number $#2$ appears $n$ times}}%
}
\begin{document}
\begin{equation*}
\frac{1\!\ntimes{\overbrace}{7}}{\ntimes{\underbrace}{8}\!5}=
\frac{10^n+7\dfrac{10^n-1}{9\mathstrut}}{80\dfrac{10^n-1\mathstrut}{9}+5}=
\frac{16\cdot 10^n-7}{80\cdot 10^n-35}=\frac{1}{5}
\end{equation*}
\end{document}