帶字母的循環小數(頂部對齊)

帶字母的循環小數(頂部對齊)

在此輸入影像描述

一張圖片超過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}

相關內容