表中的对齐取决于表头的长度

表中的对齐取决于表头的长度

当我删除代码(或任何长文本)中的标题“标题中使用的常规变量”时,两列会像这样重叠:

电流输出:

在此处输入图片描述

当前代码:

\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 used in the model} \\
        $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 \\
        $\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}

但是当我保留标题时,表格看起来还不错。理想情况下,我想删除标题并保留如下输出:

期望输出:

在此处输入图片描述

我究竟做错了什么?

答案1

\begin{table}[!htb] 
    \centering
    \begin{tabular}{lp{6cm}}\toprule
        \textbf{Variable} & \textbf{ Definition}   \\
        \midrule
        \multicolumn{2}{c}{\textbf{General variables used in the model}} \\
        $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 \\
        $\alpha$ & $\alpha$ is specific for Case 1 \\
        \bottomrule
    \end{tabular}

    \bigskip
    \textit{Note}: This table....
    \textit{Source}: Source to be inserted
    \caption{Definition of variables}\label{table_alm}
\end{table}

在此处输入图片描述

使用tabularxwith \begin{tabularx}{\linewidth}{lX}\toprule 更有意义:

在此处输入图片描述

并且没有第二行:

    \begin{tabular}{lp{6cm}}\toprule
        \textbf{Variable} & \textbf{Definition}\\\midrule
        $K$ & Fixed amount of money need to start production \\
        ...

在此处输入图片描述

答案2

我会删除所有\vskip说明\hskip,只使用两列tabularx环境。顺便说一句,大胆的如果谨慎使用则会更加有效。

在此处输入图片描述

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

\begin{document}    
\begin{table}
    \begin{tabularx}{\textwidth}{@{} l X @{}}
        \toprule
        \textbf{Variable} & \textbf{Definition}   \\
        \midrule
        \multicolumn{2}{@{}l}{General variables used in the model} \\[1ex]
        $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$), 
            profits in the second period~($\pi_2$), and total profits 
            ($\Pi = \pi_1 + \pi_1$) \\
        $P_r$ & $P_r$ is the regular price \\
        $\alpha$ & $\alpha$ is specific for Case 1 \\
        \bottomrule
    \end{tabularx}

    \bigskip
    \textit{Note}: This table \dots 

    \textit{Source}: Source to be inserted
    \caption{Definition of variables}
    \label{table_alm}
\end{table}
\end{document}

相关内容