表格中过长公式的手动换行

表格中过长公式的手动换行

如何让 LaTeX 在显示数学模式下为长方程式应用换行符?

我创建了一个表格:

% \usepackage{booktabs}
\begin{table}[]
\centering
\caption{My caption}
\label{my-label}
\begin{tabular}{@{}|l|l|l|@{}}
\toprule
                           & Actual Positive $(y_i=1)$                                                & Actual Negative $(y_i=0)$ \\ \midrule
Predicted Positive $c_i=1$ & $C_{TP_i}=0$                                                             & $C_{FP_i}=r_i+C^m_{FP_i}$ \\ \midrule
Predicted Negative $c_i=0$ & $C_{FN_i}=C_{device_i} + C_{marketInvest_i} + C_{usage_i}-Downpayment_i$ & $C_{TN_i}=0$              \\ \bottomrule
\end{tabular}
\end{table}

在哪里

$C_{FN_i}=C_{device_i} + C_{marketInvest_i} + C_{usage_i}-Downpayment_i$

表示方程太长。

我怎样才能分割它,例如

$C_{FN_i}=C_{device_i} +
    C_{marketInvest_i} + 
    C_{usage_i}-Downpayment_i$

align在表中使用时

\begin{align*}
    C_{FN_i}=C_{device_i} &+\\
    C_{marketInvest_i} &+\\
    C_{usage_i} &-\\
    Downpayment_i
\end{align}

结果是编译错误在乳胶中。

\begin{table}[]
\centering
\caption{Cost matrix proposed for telecommunication industry.}
\label{tbl:tma-costmat}
\begin{tabular}{@{}l|l|l@{}}
                           & Actual Positive $(y_i=1)$                                                & Actual Negative $(y_i=0)$ \\ \midrule
Predicted Positive $c_i=1$ & $C_{TP_i}=0$                                                             & $C_{FP_i}=r_i+C^m_{FP_i}$ \\ \midrule
Predicted Negative $c_i=0$ & \begin{align*}
    C_{FN_i}=C_{device_i} &+\\
    C_{marketInvest_i} &+\\
    C_{usage_i} &-\\
    Downpayment_i
\end{align} & $C_{TN_i}=0$              \\
\end{tabular}
\end{table}

答案1

您不能按照您提议的方式使用align环境(或环境)。但是,您可以使用环境。align*aligned

在此处输入图片描述

\documentclass{article}
\usepackage{amsmath,booktabs,array}
\usepackage[skip=0.333\baselineskip]{caption}
\newcolumntype{L}{>{$}l<{$}}   % automatic math mode
\newcommand\vn[1]{\mathit{#1}} % "variable name" 

\begin{document}
\begin{table}
\centering
\caption{Cost matrix proposed for telecommunication industry.}
\label{tbl:tma-costmat}
\begin{tabular}{@{}lLL@{}}
\toprule
  & \text{Actual Pos.\ }(y_i=1)                                                  
  & \text{Actual Neg.\ }(y_i=0) \\ 
\midrule
Predicted Positive $c_i=1 $
  & C_{\vn{TP}_i}=0
  & C^{}_{\vn{FP}_i}=r^{}_i+C^m_{\vn{FP}_i} \\ 
\addlinespace[3mm]
Predicted Negative $c_i=0$ 
  & \begin{aligned}[t]
    C_{\vn{FN}_i}&=C_{\vn{device}_i}  \\
       &\quad+C_{\vn{marketInvest}_i} \\
       &\quad+C_{\vn{usage}_i}        \\
       &\quad-\vn{Downpayment}_i &
    \end{aligned} 
  & C_{\vn{TN}_i}=0  \\
\bottomrule
\end{tabular}
\end{table}
\end{document}

相关内容