我有以下命令用于某个函数:
\documentclass{article}
\usepackage{xparse}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{xfrac}
\NewDocumentCommand{\Inxy}{mmmm}{
\mathbb{I}_{#1}%
\left(#2\middle|\begin{matrix}#4 \\ #3 \end{matrix}\right)
}
\begin{document}
ugly:
\begin{equation}
\Inxy{N}{\begin{bmatrix}
p_1 & \cdots & p_N \\
a_1 & \cdots & a_n \\
b_1 & \cdots & b_n \\
\end{bmatrix}}{x}{y}=\int_x^y \prod_{i=1}^N(a_i+b_it)^{\sfrac{p_i}{2}}
\end{equation}
better but manual and suppose that $p_1$ height is equal to x:
\RenewDocumentCommand{\Inxy}{mmmm}{
\mathbb{I}_{#1}%
\left(#2\middle|\begin{matrix}#4 \\ \; \\ #3 \end{matrix}\right)
}
\begin{equation}
\Inxy{N}{\begin{bmatrix}
p_1 & \cdots & p_N \\
a_1 & \cdots & a_n \\
b_1 & \cdots & b_n \\
\end{bmatrix}}{x}{y}=\int_x^y \prod_{i=1}^N(a_i+b_it)^{\sfrac{p_i}{2}}
\end{equation}
\end{document}
我想让 #4 与垂直条的外侧顶部对齐,而 #3 与底部对齐。我该怎么做?
答案1
这似乎可以实现你想要的效果:
\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\newcommand{\Inxy}[4]{%
\mathbb{I}_{#1}%
\sbox0{$\displaystyle\left({#2}\bigg|\right)$}% at least \bigg
\left(
#2\vphantom{\usebox0}%
\;\middle|\;
\smash{\vcenter to \dimexpr\ht0+\dp0{
\hbox{\strut$\displaystyle#3$}
\vfill
\hbox{\strut$\displaystyle#4$}
}}%
\right)
}
\begin{document}
\begin{equation}
\Inxy{N}{\begin{bmatrix}
p_1 & \dots & p_N \\
a_1 & \dots & a_n \\
b_1 & \dots & b_n \\
\end{bmatrix}\!}{x}{y}
\end{equation}
\begin{equation}
\Inxy{N}{\begin{bmatrix}a\\b\end{bmatrix}\!}{x}{y}
\end{equation}
\begin{equation}
\Inxy{N}{A}{B}{C}
\end{equation}
\end{document}
更完整的解决方案是,如果宏以文本样式出现(如分数),则两个索引(第三和第四个参数)以脚本样式排版。
在示例中,我center
仅使用将最后的示例与其他示例对齐。
\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\makeatletter
\newcommand{\Inxy}[4]{{%
\mathpalette\Inxy@aux@i{{#1}{#2}{#3}{#4}}%
}}
\newcommand{\Inxy@aux@i}[2]{\Inxy@aux@ii{#1}#2}
\newcommand{\Inxy@aux@ii}[5]{%
\mathbb{I}_{#2}%
\sbox\z@{$\m@th#1\left({#3}\right)$}%
\sbox\tw@{\vbox{\hbox{$\Inxy@demote#1\mathstrut#4$}\hbox{$#1\mathstrut#5$}}}%
\left(
#3\vphantom{\usebox\z@\vcenter{\copy\tw@}}%
\;\middle|\;
\dimen@=\ht\z@ \advance\dimen@\dp\z@
\ifdim\ht\tw@>\dimen@ \dimen@=\ht\tw@ \fi
\smash{\vcenter to \dimen@{
\hbox{$\m@th\Inxy@demote#1\mathstrut#4$}
\vfill
\hbox{$\m@th\Inxy@demote#1\mathstrut#5$}
}}%
\right)
}
\newcommand\Inxy@demote[1]{%
\ifx\displaystyle#1\displaystyle\else
\ifx\textstyle#1\scriptstyle\else
\scriptscriptstyle
\fi\fi
}
\makeatother
\begin{document}
\begin{equation}
\Inxy{N}{\begin{bmatrix}
p_1 & \dots & p_N \\
a_1 & \dots & a_n \\
b_1 & \dots & b_n \\
\end{bmatrix}\!}{x}{y}
\end{equation}
\begin{equation}
\Inxy{N}{\begin{bmatrix}a\\b\end{bmatrix}\!}{x}{y}
\end{equation}
\begin{equation}
\Inxy{N}{A}{B}{C}
\end{equation}
\begin{center}
$\Inxy{N}{\begin{smallmatrix} 1 & 2 \\ 1 & 2 \\ 1 & 2 \end{smallmatrix}}{x}{y}$
\end{center}
\end{document}
答案2
答案3
我不确定我是否理解您想要实现的目标,但上述等式使用的\Inxy
定义与您的定义略有不同:
\NewDocumentCommand{\Inxy}{mmmm}{
\mathbb{I}_{#1}%
\left(#2\middle|\begin{matrix}#4 \\ \\#3 \end{matrix}\right)
}
(再观察一个\\
)。完整的 MWE 是:
\documentclass{article}
\usepackage{xparse}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{xfrac}
\NewDocumentCommand{\Inxy}{mmmm}{
\mathbb{I}_{#1}%
\left(#2\middle|\begin{matrix}#4 \\ \\#3 \end{matrix}\right)
}
\begin{document}
ugly ???
\begin{equation}
\Inxy{N}{\begin{bmatrix}
p_1 & \cdots & p_N \\
a_1 & \cdots & a_n \\
b_1 & \cdots & b_n \\
\end{bmatrix}}{x}{y}=\int_x^y \prod_{i=1}^N(a_i+b_it)^{\sfrac{p_i}{2}}
\end{equation}
\end{document}
答案4
感谢@egreg,我更喜欢这个解决方案:
\documentclass{article}
\usepackage{mleftright}
\usepackage{scalerel}
\usepackage{amsmath}
\usepackage{amssymb}
\newcommand{\Inxy}[4]{
\mathbb{I}_{#1}
\ThisStyle{%
\sbox2{$\vcenter{\hbox{\oalign{\hbox{\strut\ensuremath{\SavedStyle#3}}\cr\hbox{\strut\ensuremath{\SavedStyle#4}}}}}$}%
\sbox0{$\SavedStyle\left(#2\middle|\usebox2\right)$}
\mleft(
#2\vphantom{\usebox0}%
\;\middle|\;
\vcenter to \dimexpr\ht0+\dp0{
\hbox{\strut\ensuremath{\SavedStyle#3}}
\vfill
\hbox{\strut\ensuremath{\SavedStyle#4}}
}
\mright)
}
}
\begin{document}
\begin{equation}
\Inxy{N}{\begin{matrix} 1 & 2 \\ 1 & 2 \\ 1 & 2 \end{matrix}}{A}{B} \\
\end{equation}
\begin{equation}
\Inxy{N}{M}{A}{B} \\
\end{equation}
\begin{equation}
\Inxy{N}{M}{x}{y} \\
\end{equation}
This is Text
$\Inxy{N}{\begin{smallmatrix} 1 & 2 \\ 1 & 2 \\ 1 & 2 \end{smallmatrix}}{A}{B}$
and $
\Inxy{N}{M}{A}{B}$ and $\Inxy{N}{M}{x}{y}$
\end{document}