我正在使用的代码egreg(新命令,xabove
) 从我之前的问题排版不带分数线的“分数”。
在以下 MWE 中,是否有一种简单的方法可以水平对齐“A:3.14”和“B:6.28”中的冒号 (:)?还是我需要使用不同的定义xabove
?
\documentclass[oneside,11pt]{book}
\usepackage[semibold,tt=false]{libertine}
\usepackage{libertinust1math}
\usepackage[T1]{fontenc}
\usepackage[
expansion = false ,
tracking = smallcaps ,
letterspace = 40 ,
final
]{microtype}
\usepackage{booktabs}
% egreg's answer (https://tex.stackexchange.com/a/590218/15622)
\makeatletter
\DeclareRobustCommand{\xabove}[2]{{%
\mathpalette\fix@genfrac{{#1}{#2}}%
}}
\newcommand{\fix@genfrac}[2]{\fix@@genfrac#1#2}
\newcommand{\fix@@genfrac}[3]{%
\genfrac{}{}{\fix@@@genfrac{#1}}{}{#2}{#3}%
}
\newcommand{\fix@@@genfrac}[1]{%
\ifx#1\displaystyle 0pt\else
\ifx#1\textstyle -\fontdimen8\textfont2 \else
\ifx#1\scriptstyle -\fontdimen8\scriptfont2 \else
0pt % but doesn't really work :-(
\fi\fi\fi
}
\makeatother
\begin{document}
$\xabove{\textit{A}:\;3.14}{\textit{B}:\;6.28}$
\end{document}
答案1
这是一种直接的方法\phantom
:
\documentclass{article}
\usepackage[semibold,tt=false]{libertine}
\usepackage{libertinust1math}
\usepackage[T1]{fontenc}
\usepackage{mathtools}
% egreg's answer (https://tex.stackexchange.com/a/590218/5764)
\makeatletter
\DeclareRobustCommand{\xabove}[2]{{%
\mathpalette\fix@genfrac{{#1}{#2}}%
}}
\newcommand{\fix@genfrac}[2]{\fix@@genfrac#1#2}
\newcommand{\fix@@genfrac}[3]{%
\genfrac{}{}{\fix@@@genfrac{#1}}{}{#2}{#3}%
}
\newcommand{\fix@@@genfrac}[1]{%
\ifx#1\displaystyle 0pt\else
\ifx#1\textstyle -\fontdimen8\textfont2 \else
\ifx#1\scriptstyle -\fontdimen8\scriptfont2 \else
0pt % but doesn't really work :-(
\fi\fi\fi
}
\makeatother
\begin{document}
$\xabove{\textit{A}:\;3.14}{\phantom{\textit{A}}\mathllap{\textit{B}}:\;6.28}$
\end{document}
这是可行的,因为A
和B
是仅有的两个顶部/底部宽度不同的元件。因此,我们将较宽/较大的元件放在内部\phantom
以实现所需的位置/位置,然后将另一个(较窄/较小的)元件插入通孔\mathllap
(从mathtools
)。
答案2
2.5pt
对齐的 TABstack 可以完成这项工作。在这里,我选择堆栈行之间的间隙(用户可选择) ,我认为这个间隙合适,并且不会在文本中造成更大的行间间隙。
\documentclass[oneside,11pt]{book}
\usepackage[semibold,tt=false]{libertine}
\usepackage{libertinust1math}
\usepackage[T1]{fontenc}
\usepackage[
expansion = false ,
tracking = smallcaps ,
letterspace = 40 ,
final
]{microtype}
\usepackage{booktabs}
\usepackage{tabstackengine,lipsum}
\TABstackMath
\TABstackMathstyle{\scriptstyle}
\begin{document}
\lipsum[1]
\alignstackanchor[2.5pt]{A:&\;3.14}{B:&\;6.28} % FOR S \stacktype
\lipsum[2]
\end{document}
答案3
你可以做到,但是你应该想想这是否真的是你想要的。
\documentclass[oneside,10pt]{book}
\usepackage{amsmath,mathtools}
\usepackage[semibold,tt=false]{libertine}
\usepackage{libertinust1math}
\usepackage[T1]{fontenc}
\makeatletter
\DeclareRobustCommand{\xabove}[2]{{%
\mathpalette\fix@genfrac{{#1}{#2}}%
}}
\newcommand{\fix@genfrac}[2]{\fix@@genfrac#1#2}
\newcommand{\fix@@genfrac}[3]{%
\genfrac{}{}{\fix@@@genfrac{#1}}{}{#2}{#3}%
}
\newcommand{\fix@@@genfrac}[1]{%
\ifx#1\displaystyle 0pt\else
\ifx#1\textstyle -\fontdimen8\textfont2 \else
\ifx#1\scriptstyle -\fontdimen8\scriptfont2 \else
0pt % but doesn't really work :-(
\fi\fi\fi
}
\newcommand{\labeledabove}[4]{%
\xabove{\above@label{#1}{#3}{:}\;\hfill#2}{\above@label{#3}{#1}{:}\;\hfill#4}%
}
\newcommand{\above@label}[2]{\mathpalette\above@@label{{#1}{#2}}}
\newcommand{\above@@label}[2]{\above@@@label#1#2}
\newcommand{\above@@@label}[3]{%
{\sbox\z@{\vbox{\ialign{$\m@th#1##\mkern-2mu$\hfil\cr#2\cr#3\cr}}}\makebox[\wd\z@][l]{$\m@th#1#2$}}
}
\makeatother
\begin{document}
$\displaystyle\frac{1}{2}\xabove{1}{2}$
$\textstyle\frac{1}{2}\xabove{1}{2}$
$\scriptstyle\frac{1}{2}\xabove{1}{2}$
%$\scriptscriptstyle\frac{1}{2}\xabove{1}{2}$
\bigskip
$\displaystyle\labeledabove{A}{3.14}{B}{6.28}\quad\xabove{1}{2}$
\medskip
$\labeledabove{A}{3.14}{B}{6.28}\quad\xabove{1}{2}$
\end{document}