我编写了以下代码,但它给出了错误。我认为问题出在新命令上。(我是定义新命令的新手,因此请提供一些解释)
\usepackage{array}
\usepackage{booktabs}
\newcommand{\tableequation}[1]{%
\vspace*{-\baselineskip}
{\begin{flalign}#1&&&\end{flalign}}%
\vspace*{-\baselineskip}
}
\begin{document}
\begin{tabular} {
@{}
>{\linespread{1.2}\selectfont}m{6cm}
@{}
m{6cm}
@{}
}
\toprule
\multicolumn{2}{ |l| }{\textbf{Requirements of inner product}}\\
\midrule
\emph{Commutative:} & \tableequation{ \textbf{u} \cdot \textbf{v} = \textbf{v} \cdot \textbf{u}, }\\
\emph{Nonnegative:} &
\tableequation{
\textbf{u} \cdot \textbf{u} &> 0 && \text{for all \textbf{u} \ne 0, }\\
&=0 && \text{for \textbf{u} = 0,}\\
}\\
\emph{Linear:} & \tableequation{ (\alpha \textbf{u} + \beta \textbf{v}) \cdot \textbf{w} = \alpha(\textbf{u} \cdot \textbf{w}) + \beta(\textbf{v} \cdot \textbf{w}), }
\bottomrule
\end{tabular}
\end{document}
答案1
您不需要tabular
环境即可获得此结果:alignat
可以轻松完成。我建议使用第二种变体,代码更简单,在我看来,它看起来更好:
\documentclass{article}
\usepackage{mathtools} %requirement for the flalign environment
\usepackage{array}
\usepackage{booktabs}
\begin{document}
\begin{subequations}
\setlength{\aboverulesep}{1ex}
\setlength{\belowrulesep}{1ex}
\begin{alignat}{3}
\toprule
\shortintertext{\bfseries\MakeUppercase{Requirements of inner product}\smallskip}
\emph{Commutative:} & \qquad & \mathbf{u} · \mathbf{v} & {}={} & & \mathbf{v} · \mathbf{u}, \\
\emph{Nonnegative:} & & \mathbf{u} · \mathbf{u} > 0 & & & \text{for all } \mathbf{u} \ne 0, \notag \\
& & = 0 & & & \text{for } \mathbf{u} = 0 \\
\emph{Linear:} & & (α\mathbf{u} + β\mathbf{v}) · \mathbf{w} & {}={} & & α(\mathbf{u} · \mathbf{w}) + β(\mathbf{v} · \mathbf{w}), \\
\bottomrule\notag
\end{alignat}
\end{subequations}
\begin{subequations}
\setlength{\aboverulesep}{1ex}
\setlength{\belowrulesep}{1ex}
\begin{alignat}{2}
\toprule
\shortintertext{\bfseries\MakeUppercase{Requirements of inner product}\smallskip}
\emph{Commutative:} & \qquad & \mathbf{u} · \mathbf{v} & = \mathbf{v} · \mathbf{u}, \\
\emph{Nonnegative:} & & \mathbf{u} · \mathbf{u} & > 0 \quad\text{for all } \mathbf{u} \ne 0, \notag \\
& & & = 0 \quad \text{for } \mathbf{u} = 0 \\
\emph{Linear:} & & (α\mathbf{u} + β\mathbf{v}) · \mathbf{w} & = α(\mathbf{u} · \mathbf{w}) + β(\mathbf{v} · \mathbf{w}), \\
\bottomrule\notag
\end{alignat}
\end{subequations}
\end{document}
答案2
您需要amsmath
flalign 环境。此外,您的 bottomrule 之前缺少一个\\
,请参阅内联注释:
\documentclass{article}
\usepackage{amsmath} %requirement for the flalign environment
\usepackage{array}
\usepackage{booktabs}
\newcommand{\tableequation}[1]{%
\vspace*{-\baselineskip}
{\begin{flalign}#1&&&\end{flalign}}%
\vspace*{-\baselineskip}
}
\begin{document}
\begin{tabular} {
@{}
>{\linespread{1.2}\selectfont}m{6cm}
@{}
m{6cm}
@{}
}
\toprule
\multicolumn{2}{ |l| }{\textbf{Requirements of inner product}}\\
\midrule
\emph{Commutative:} & \tableequation{ \textbf{u} \cdot \textbf{v} = \textbf{v} \cdot \textbf{u}, }\\
\emph{Nonnegative:} &
\tableequation{
\textbf{u} \cdot \textbf{u} &> 0 && \text{for all \textbf{u} \ne 0, }\\
&=0 && \text{for \textbf{u} = 0,}\\
}\\
\emph{Linear:} & \tableequation{ (\alpha \textbf{u} + \beta \textbf{v}) \cdot \textbf{w} = \alpha(\textbf{u} \cdot \textbf{w}) + \beta(\textbf{v} \cdot \textbf{w}), }\\ %missing \\ in the original code
\bottomrule
\end{tabular}
\end{document}
答案3
一些建议:第一个有点复杂,因为我们需要模拟booktabs
但使用flalign
。第二个更自然。我删除了其中一个条件,因为它遵循最后一个条件。
\documentclass{article}
\usepackage{amsmath}
\usepackage{booktabs,array}
\usepackage{lipsum} % just for the example
\begin{document}
\lipsum[2]
\begin{center}
\begin{minipage}{\textwidth}% don't break
\setlength{\abovedisplayskip}{0pt}
\setlength{\belowdisplayskip}{0pt}
\newcommand{\eqsep}{\mathrel{\hphantom{=}}}
\hrule height \heavyrulewidth
\vspace{\belowrulesep}
\textbf{Requirements of inner product}
\vspace{\aboverulesep}
\hrule height \lightrulewidth
\vspace{\belowrulesep}
\begin{flalign}
&\text{\emph{Commutative}:} &
\mathbf{u} \cdot \mathbf{v} &= \mathbf{v} \cdot \mathbf{u}, &\\
&\text{\emph{Nonnegative}:} &
\mathbf{u} \cdot \mathbf{u} > 0 &\eqsep \text{for all $\mathbf{u} \ne 0$, } &\nonumber\\
&&
{} = 0 &\eqsep \text{for $\mathbf{u} = 0$,} &\\
&\text{\emph{Linear}:} &
(\alpha \mathbf{u} + \beta \mathbf{v}) \cdot \mathbf{w} &=
\alpha(\mathbf{u} \cdot \mathbf{w}) + \beta(\mathbf{v} \cdot \mathbf{w}). &
\end{flalign}
\vspace{\aboverulesep}
\hrule height \heavyrulewidth
\end{minipage}
\end{center}
\lipsum[3]
\[
\newcommand{\eqsep}{\mathrel{\hphantom{=}}}
\newcommand{\addnumber}{\refstepcounter{equation}(\theequation)}
\setlength{\tabcolsep}{0pt}
\begin{tabular*}{\textwidth}{
@{\extracolsep{\fill}}
l
>{$}r<{$}@{\extracolsep{0pt}}
>{${}}c<{{}$}
>{$}l<{$}@{\extracolsep{\fill}}
r
}
\toprule
\multicolumn{5}{c}{\bfseries Requirements of inner product}\\
\midrule
\emph{Commutative} &
\mathbf{u} \cdot \mathbf{v} &= &\mathbf{v} \cdot \mathbf{u}, & \addnumber \\
\addlinespace
\emph{Positive}: &
\mathbf{u} \cdot \mathbf{u} > 0 & &\text{for all $\mathbf{u} \ne 0$, } & \addnumber \\
\addlinespace
\emph{Linear}: &
(\alpha \mathbf{u} + \beta \mathbf{v}) \cdot \mathbf{w} &= &
\alpha(\mathbf{u} \cdot \mathbf{w}) + \beta(\mathbf{v} \cdot \mathbf{w}). & \addnumber \\
\bottomrule
\end{tabular*}
\]
\lipsum[3]
\end{document}
之后您可以根据需要\addnumber
添加。\label