我是 Latex 的新手,我有以下代码。
\documentclass[12]{article}
\usepackage{amsthm,amssymb,amsmath,amsfonts,amscd}
\usepackage{caption,subcaption}
\newcommand{\hmi}{\hat{\mu}_i}
\newcommand{\hapi}{\hat{p}_i}
\newcommand{\hli}{\hat{\lambda_i}}
\begin{document}
\begin{table}[h]
\begin{tabular}{|c|c|}
\hline
blah & blah blah \\
\hline
blah & $d_i = sign(y_i-\hmi) \sqrt{ 2\left\{ y_i \log \frac{ y_i}{\hmi} - (y_i - \hmi) \right\}} $ \\
\hline
blah & $ d_i = sign(y_i-\hmi) \left( 2\left\{ -y_i +y_i \log y_i -\log y_i ! - I(y_i=0)\log \left[ \hapi +(1-\hapi) e^{-\hli} \right] - I(y_i > 0)\log \left[ (1-\hapi) - \hli +y_i \log \hli -\log y_i ! \right] \right\} \right)^{1/2}$ \\
\hline
\end{tabular} \caption{blah blah blah \label{tab:deviance}}
\end{table}
\end{document}
我如何才能将这个大公式拆分成一个单元格中的多行?
答案1
尝试:
\documentclass[12]{article}
\usepackage{mathtools} % <-- added
\usepackage{makecell} % <-- added
\usepackage{amsthm,amssymb,amsfonts,amscd}
\usepackage{caption,subcaption}
\newcommand{\hmi}{\hat{\mu}_i}
\newcommand{\hapi}{\hat{p}_i}
\newcommand{\hli}{\hat{\lambda_i}}
\begin{document}
\begin{table}[h]
\setcellgapes{5pt}
\makegapedcells
\begin{tabular}{|c|c|}
\hline
blah & blah blah \\
\hline
blah & $d_i = sign(y_i-\hmi) \sqrt{ 2\left\{ y_i \log \frac{ y_i}{\hmi} - (y_i - \hmi) \right\}} $ \\
\hline
blah & $\begin{multlined}[t][0.8\linewidth]
d_i = sign(y_i-\hmi) \Bigl(2\Bigl\{ -y_i +y_i \log y_i -\log y_i !
- I(y_i=0)\log \Bigl[ \hapi +(1-\hapi) e^{-\hli} \Bigr] \\[-1ex]
- I(y_i > 0)\log \Bigl[ (1-\hapi)
- \hli +y_i \log \hli -\log y_i ! \Bigr] \Bigr\}\Bigr)^{1/2}
\end{multlined}$ \\
\hline
\end{tabular}
\caption{blah blah blah
\label{tab:deviance}}
\end{table}
\end{document}
对于上面的代码,需要添加mathtools
包。我还定义了数学运算符sign
。为了更好的间距,我还添加了包makecell
,并为表声明 clls 以具有\makegapedcells
间距\setcellgapes{5pt}