对于下面的例子,有没有办法自动将公式编号 (1) 与公式编号 (2) 和 (3) 对齐?\parbox
每次手动调整参数很烦人。
\documentclass{article}
% packages used in my real .tex script
\usepackage[fontset=adobe]{ctex}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{graphicx}
\graphicspath{ {./chapter-01-img/} }
\begin{document}
\begin{equation}
p(x\in(a, b)) = \int^b_ap(x)\mathrm{d}x
\end{equation}
%
%some text...
%
\begin{tabular}{rl}
\textbf{discrete random variable} & \parbox{6.1cm}{\begin{equation}\mathbb{E}[f]=\sum_xf(x)p(x)\end{equation}} \\
\textbf{continuous random variable} & \parbox{6.1cm}{\begin{equation}\mathbb{E}[f]=\int f(x)p(x)\mathrm{d}x\end{equation}}
\end{tabular}
\end{document}
这是我的ctex-fontset-adobe.def
:
%%
%% This is file `ctex-fontset-adobe.def',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% ctex.dtx (with options: `fontset,adobe')
%%
%% Copyright (C) 2003--2017
%% CTEX.ORG and any individual authors listed in the documentation.
%% ------------------------------------------------------------------------------
%%
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either
%% version 1.3c of this license or (at your option) any later
%% version. This version of this license is in
%% http://www.latex-project.org/lppl/lppl-1-3c.txt
%% and the latest version of this license is in
%% http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of
%% LaTeX version 2005/12/01 or later.
%%
%% This work has the LPPL maintenance status `maintained'.
%%
%% The Current Maintainers of this work are Leo Liu, Qing Lee and Liam Huang.
%%
%% ------------------------------------------------------------------------------
%%
\GetIdInfo$Id: ctex.dtx c498d8c 2017-04-01 21:33:50 +0800 Qing Lee <[email protected]> $
{Adobe fonts definition (CTEX)}
\ProvidesExplFile{ctex-fontset-adobe.def}
{\ExplFileDate}{2.4.9}{\ExplFileDescription}
\sys_if_engine_pdftex:TF
{
\sys_if_output_pdf:TF
{ \ctex_fontset_error:n { adobe } }
{
\ctex_zhmap_case:nnn
{
\setCJKmainfont
[
cmap = UniGB-UTF16-H ,
BoldFont = Source Han Sans SC Bold,
ItalicFont = AdobeKaitiStd-Regular.otf
] { Source Han Sans SC Regular }
\setCJKsansfont [cmap = UniGB-UTF16-H] { Source Han Sans SC Regular }
\setCJKmonofont [ cmap = UniGB-UTF16-H ] { Source Han Sans HW SC Regular }
\setCJKfamilyfont { zhsong }
[ cmap = UniGB-UTF16-H ] { Source Han Serif CN Regular }
\setCJKfamilyfont { zhhei }
[ cmap = UniGB-UTF16-H ] { Source Han Sans SC Regular }
\setCJKfamilyfont { zhkai }
[ cmap = UniGB-UTF16-H ] { AdobeKaitiStd-Regular.otf }
\setCJKfamilyfont { zhfs }
[ cmap = UniGB-UTF16-H ] { AdobeFangsongStd-Regular.otf }
\ctex_punct_set:n { adobe }
\ctex_punct_map_family:nn { \CJKrmdefault } { zhsong }
\ctex_punct_map_family:nn { \CJKsfdefault } { zhhei }
\ctex_punct_map_family:nn { \CJKttdefault } { zhfs }
\ctex_punct_map_itshape:nn { \CJKrmdefault } { zhkai }
\ctex_punct_map_bfseries:nn { \CJKrmdefault } { zhhei }
}
{
\ctex_load_zhmap:nnnn { rm } { zhhei } { zhfs } { zhadobefonts }
\ctex_punct_set:n { adobe }
\ctex_punct_map_family:nn { \CJKrmdefault } { zhsong }
\ctex_punct_map_bfseries:nn { \CJKrmdefault } { zhhei }
\ctex_punct_map_itshape:nn { \CJKrmdefault } { zhkai }
}
{ \ctex_fontset_error:n { adobe } }
}
}
{
\setCJKmainfont
[
BoldFont = SourceHanSerifCN-Bold,
% ItalicFont = AdobeKaitiStd-Regular.otf
] { Source~Han~Serif~CN }
\setCJKsansfont { Source~Han~Sans~SC~Regular }
\setCJKmonofont { Source~Han~Sans~HW~SC~Regular }
\setCJKfamilyfont { zhsong } { Source~Han~Serif~CN }
\setCJKfamilyfont { zhhei } { Source~Han~Sans~SC~Regular }
\setCJKfamilyfont { zhfs } { AdobeFangsongStd-Regular }
\setCJKfamilyfont { zhkai } { AdobeKaitiStd-Regular }
}
\NewDocumentCommand \songti { } { \CJKfamily { zhsong } }
\NewDocumentCommand \heiti { } { \CJKfamily { zhhei } }
\NewDocumentCommand \fangsong { } { \CJKfamily { zhfs } }
\NewDocumentCommand \kaishu { } { \CJKfamily { zhkai } }
%%
%%
%% End of file `ctex-fontset-adobe.def'.
答案1
您实际上并不需要表格,只需使用数学包提供的内容即可。fromalignat
包amsmath
正好用于这些情况。
\documentclass{article}
\usepackage{amsmath,amssymb}
\begin{document}
\begin{equation}
p(x\in(a, b)) = \int^b_ap(x)\mathrm{d}x
\end{equation}
%
some text...
%
\begin{alignat}{2}
\textbf{discrete random variable} & &&\mathbb{E}[f]=\sum_xf(x)p(x) \\
\textbf{continuous random variable} & \quad\quad &&\mathbb{E}[f]=\int f(x)p(x)\mathrm{d}x
\end{alignat}
\end{document}
答案2
尝试将显示的方程模式破解到表格环境中对我来说似乎是一个明显不能令人满意的解决方案。为什么不使用包align
中的环境amsmath
呢?
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation}
p(x\in(a, b)) = \int^b_ap(x)\mathrm{d}x
\end{equation}
some text...
\begin{align}
\textbf{discrete random variable} \qquad & \mathbb{E}[f]=\sum_xf(x)p(x) \\
\textbf{continuous random variable} \qquad & \mathbb{E}[f]=\int f(x)p(x)\mathrm{d}x
\end{align}
\end{document}
答案3
使用flalign
是另一种解决方案。我通过专用命令来改善积分中微分符号的间距:
\documentclass{article}
\usepackage{amsmath,amssymb}
\newcommand*{\dd}{\mathop{}\!\mathrm{d}}
\begin{document}
\begin{equation}
p(x\in(a, b)) = \int^b_ap(x)\mathrm{d}x
\end{equation}
%
some text...
%
\begin{flalign}
\textbf{discrete random variable} & &&\mathbb{E}[f]=\sum_xf(x)p(x)\\
\textbf{continuous random variable} & &&\mathbb{E}[f]=\int f(x)p(x)\dd x & &
\end{flalign}
\end{document}