带字母的循环小数(顶部对齐)

带字母的循环小数(顶部对齐)

在此处输入图片描述

一张图片胜过 100 个字。如何(自动)正确地将点对齐到顶部?

当前使用的代码来自这里

\documentclass[12pt]{article}
%% packages
\usepackage{amsmath,multicol,graphics,enumerate}
\usepackage{graphicx}
\usepackage[margin=1cm]{geometry}

\makeatletter
\DeclareRobustCommand{\periodfl}[1]{\@periodflold#1\@nil\relax}
\def\@periodflold#1#2{%
  \ifx#2\relax
    \expandafter\@gobble
  \else
    \expandafter\@firstofone
  \fi
  {\@periodflold@i#1#2}%
}
\def\@periodflold@i#1#2{%
  \dot{#1}%
  \ifx#2\@nil
    \expandafter\@gobble
  \else
    \expandafter\@firstofone
  \fi
  {\@periodflold@ii#2}%
}
\def\@periodflold@ii#1#2{%
  \ifx#2\@nil
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi
  {\dot{#1}}{#1\@periodflold@ii#2}%
}
\makeatother

\begin{document}
\pagestyle{empty}
\setlength{\parindent}{0pt}

Prove that $0.\periodfl{0x}=\frac{x}{99}$.

\end{document}

谢谢!

答案1

只需\vphantom{0}在两个实例中添加参数\dot

\documentclass{article}

\makeatletter
\DeclareRobustCommand{\periodfl}[1]{\@periodflold#1\@nil\relax}
\def\@periodflold#1#2{%
  \ifx#2\relax
    \expandafter\@gobble
  \else
    \expandafter\@firstofone
  \fi
  {\@periodflold@i#1#2}%
}
\def\@periodflold@i#1#2{%
  \dot{\vphantom{0}#1}%
  \ifx#2\@nil
    \expandafter\@gobble
  \else
    \expandafter\@firstofone
  \fi
  {\@periodflold@ii#2}%
}
\def\@periodflold@ii#1#2{%
  \ifx#2\@nil
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi
  {\dot{\vphantom{0}#1}}{#1\@periodflold@ii#2}%
}
\makeatother

\begin{document}

Prove that $0.\periodfl{0x}=\frac{x}{99}$.

Prove that $0.\periodfl{00x}=\frac{x}{999}$.

\end{document}

在此处输入图片描述

为了完整起见,这里是该版本的修复expl3

\documentclass{article}
\usepackage{xparse}

\ExplSyntaxOn
%% Dots on the first and last digit
\NewDocumentCommand{\periodfl}{m}
 {
  \repdec_initial_final_dots:n { #1 }
 }

\seq_new:N \l__repdec_digits_seq
\tl_new:N \l__repdec_first_tl
\tl_new:N \l__repdec_last_tl

\cs_new_protected:Npn \repdec_initial_final_dots:n #1
 {
  \seq_set_split:Nnn \l__repdec_digits_seq {} { #1 }
  \seq_pop_left:NN \l__repdec_digits_seq \l__repdec_first_tl
  \seq_pop_right:NN \l__repdec_digits_seq \l__repdec_last_tl
  \quark_if_no_value:VF \l__repdec_first_tl { \dot{\vphantom{0}\l__repdec_first_tl} }
  \seq_use:Nn \l__repdec_digits_seq {}
  \quark_if_no_value:VF \l__repdec_last_tl { \dot{\vphantom{0}\l__repdec_last_tl} }
 }
\cs_generate_variant:Nn \quark_if_no_value:nF { V }
\ExplSyntaxOff

\begin{document}

Prove that $0.\periodfl{0x}=\frac{x}{99}$.

Prove that $0.\periodfl{00x}=\frac{x}{999}$.

\end{document}

相关内容