表格中的文本超出了文档范围。需要自动换行

表格中的文本超出了文档范围。需要自动换行

我的两列表格出现了一些问题。包含说明的第二列出现了问题。我希望第二列在超出文档文本宽度时自动开始新行。

另外,我在表格中标题的放置方面遇到了问题。目前,如您所见,第二列中的文本被第一列中的“案例 1”标题移位。理想情况下,第一列不应以这种方式影响第二列。

这是我的代码:

  \documentclass[12pt,twoside]{book}
\usepackage[a4paper, hmargin={2.5cm, 2.5cm}, vmargin={2.5cm, 2.5cm},bindingoffset=6mm]{geometry}      

\usepackage{amsmath}                      
\usepackage{mathtools} 
\usepackage{tabularx}                     
\usepackage{subcaption}
\usepackage{booktabs}   

\begin{document}
        \begin{table}[H] 
    \centering
    \begin{tabular}{llp{4cm}}
    \toprule
    \textbf{Variable} & \textbf{Definition}   \\
    \midrule
    \textbf{General variables} \\
    $K$ & Fixed amount of money need to start production \\
    $s$ & Baseline quality of the good (normalized to 1) \\
    $n$ & Number of people \\
    $\pi_1, \pi_2, \Pi$ & Profits of the entrepreneur in the first period ($\pi_1$), in the second period ($\pi_2$) and total profits $\Pi = \pi_1 + \pi_1$) \\
    $P_r$ & $P_r$ is the regular price \\
    \textbf{Case 1: This is a very long title2} \\
    $\alpha$ & $\alpha$ is specific for Case 1 \\
    \bottomrule
    \end{tabular}
    \floatfoot{ \textit{Note}: This table....
                \textit{Source}: Source to be inserted}
    \caption{Definition of variables}
    \label{table_alm}
    \end{table}

\end{document}

这是当前输出:

在此处输入图片描述

答案1

尝试这个:

     \documentclass[12pt,twoside]{book}
  \usepackage[a4paper, hmargin={2.5cm, 2.5cm}, vmargin={2.5cm, 2.5cm},bindingoffset=6mm]{geometry}      

  \usepackage{amsmath}                      
  \usepackage{mathtools} 
  \usepackage{tabularx}                     
  \usepackage{subcaption}
    \usepackage{booktabs}   

    \begin{document}
    \begin{table}[H] 
    \centering
    \begin{tabular}{lp{6cm}}
        \toprule
        \textbf{Variable} & \textbf{\hskip-1.2in Definition}   \\
        \midrule
        \textbf{General variables} \\
        $K$ & \hskip-1.2in Fixed amount of money need to start production \\
        $s$ & \hskip-1.2in Baseline quality of the good (normalized to 1) \\
        $n$ & \hskip-1.2in Number of people \\
        $\pi_1, \pi_2, \Pi$ & \hskip-1.2in%
 \vtop{\hsize=3.5in Profits of the entrepreneur in the first period ($\pi_1$),%
 in the second period ($\pi_2$) and total profits $\Pi = \pi_1 + \pi_1$)} \\
        $P_r$ & \hskip-1.2in $P_r$ is the regular price%
   \vspace{.05in}\\
         \textbf{Case 1: This is a very long title2} \\
        $\alpha$ & \hskip-1.2in $\alpha$ is specific for Case 1 \\
        \bottomrule
    \end{tabular}
     \vskip.1in\par
     {\textit{Note}: This table....
        \textit{Source}: Source to be inserted}
    \caption{Definition of variables}
    \label{table_alm}
\end{table}

  \end{document}

其结果为:在此处输入图片描述

相关内容