特定单元格的顶部对齐

特定单元格的顶部对齐

我尝试将“教育”单元格顶部对齐,\makecell[t]但没有成功。所以我尝试将整个表格顶部对齐,然后使用,\begin{tabularx}{\linewidth}[t]但仍然没有任何变化。虽然我只需要将“教育”顶部对齐,但我也很高兴知道如何将整个表格顶部对齐。非常感谢![在此处输入图片描述]1

\documentclass{article}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{makecell}

\begin{document}
    \begin{table}[htbp]
        \small
        \caption{Definition of Variables}

        \begin{tabularx}{\linewidth}[t]{ r X }
            \toprule
            Variable & Description \\
            \midrule
            SR1+  & Positive SR1 \\
            SRdummy1 & Dummy variable that equals one if SR1 is positive and zero otherwise \\
            SR2+  & Positive SR2 \\
            SRdummy2 & Dummy variable that equals one if SR2 is positive and zero otherwise \\
            LnInc & The Natural logarithm of the household income  \\
            Age   & The age of the household head \\
            \makecell[t]{Education} & \makecell[l]{The Education level of the household head;\\
                equals 1 with level of non-educational; \\ 
                equals 2 with level of primary school; \\ 
                equals 3 with level of junior high school; \\ 
                equals 4 with level of high school; \\ 
                equals 5 with level of secondary/vocational school; \\ 
                equals 6 with level of college/vocational; \\ 
                equals 7 with level of undergraduate degree; \\ 
                equals 8 with level of Master's degree; \\ 
                equals 9 with level of PhD degree; }  \\
            Kid   & The number of kids (age under 16) in the household \\
            Old   & The number of elders (age over 60) in the household \\
            HHsize & Number of persons living together in the household \\
            Male  & Dummy variable that equals one if the household head is male and zero otherwise \\
            Married & Dummy variable that equals one if the household head is married and zero otherwise \\
            Party & Dummy variable that equals one if the household head is a member of the Communist Party of China and zero otherwise \\
            Job   & Dummy variable that equals one if the household head is employed and zero otherwise \\
            House & Dummy variable that equals one if the household holds real estate asset and zero otherwise \\
            \bottomrule
        \end{tabularx}
        \label{tab:definition}

    \end{table}

\end{document}

答案1

这里不需要makecell。该列有一个X允许换行的说明符\newline

带缩进后续行的示例:

\documentclass{article}
\usepackage{array}
\usepackage{caption}% fix spacing for \caption above the table
\usepackage{tabularx}
\usepackage{booktabs}

\begin{document}
    \begin{table}
        \small
        \caption{Definition of Variables}
        \begin{tabularx}{\linewidth}[t]{ r >{\hangindent1em\hangafter1 }X }
            \toprule
            Variable & Description \\
            \midrule
            SR1+  & Positive SR1 \\
            SRdummy1 & Dummy variable that equals one if SR1 is positive and zero otherwise \\
            SR2+  & Positive SR2 \\
            SRdummy2 & Dummy variable that equals one if SR2 is positive and zero otherwise \\
            LnInc & The Natural logarithm of the household income  \\
            Age   & The age of the household head \\
            Education & The Education level of the household head;\newline
                equals 1 with level of non-educational;\newline
                equals 2 with level of primary school;\newline
                equals 3 with level of junior high school;\newline
                equals 4 with level of high school;\newline
                equals 5 with level of secondary/vocational school;\newline
                equals 6 with level of college/vocational;\newline
                equals 7 with level of undergraduate degree;\newline
                equals 8 with level of Master's degree;\newline
                equals 9 with level of PhD degree;  \\
            Kid   & The number of kids (age under 16) in the household \\
            Old   & The number of elders (age over 60) in the household \\
            HHsize & Number of persons living together in the household \\
            Male  & Dummy variable that equals one if the household head is male and zero otherwise \\
            Married & Dummy variable that equals one if the household head is married and zero otherwise \\
            Party & Dummy variable that equals one if the household head is a member of the Communist Party of China and zero otherwise \\
            Job   & Dummy variable that equals one if the household head is employed and zero otherwise \\
            House & Dummy variable that equals one if the household holds real estate asset and zero otherwise \\
            \bottomrule
        \end{tabularx}
        \label{tab:definition}
    \end{table}
\end{document}

结果

如果垂直空间允许,条目之间稍微分开一下看起来会更好:

\documentclass{article}
\usepackage{caption}% fix spacing for \caption above the table
\usepackage{tabularx}
\usepackage{booktabs}

\begin{document}
    \begin{table}
        \small
        \caption{Definition of Variables}
        \begin{tabularx}{\linewidth}[t]{ r X }
            \toprule
            Variable & Description \\
            \midrule
            SR1+  & Positive SR1 \\
            \addlinespace
            SRdummy1 & Dummy variable that equals one if SR1 is positive and zero otherwise \\
            \addlinespace
            SR2+  & Positive SR2 \\
            \addlinespace
            SRdummy2 & Dummy variable that equals one if SR2 is positive and zero otherwise \\
            \addlinespace
            LnInc & The Natural logarithm of the household income  \\
            \addlinespace
            Age   & The age of the household head \\
            \addlinespace
            Education & The Education level of the household head;\newline
                equals 1 with level of non-educational;\newline
                equals 2 with level of primary school;\newline
                equals 3 with level of junior high school;\newline
                equals 4 with level of high school;\newline
                equals 5 with level of secondary/vocational school;\newline
                equals 6 with level of college/vocational;\newline
                equals 7 with level of undergraduate degree;\newline
                equals 8 with level of Master's degree;\newline
                equals 9 with level of PhD degree;  \\
            \addlinespace
            Kid   & The number of kids (age under 16) in the household \\
            \addlinespace
            Old   & The number of elders (age over 60) in the household \\
            \addlinespace
            HHsize & Number of persons living together in the household \\
            \addlinespace
            Male  & Dummy variable that equals one if the household head is male and zero otherwise \\
            \addlinespace
            Married & Dummy variable that equals one if the household head is married and zero otherwise \\
            \addlinespace
            Party & Dummy variable that equals one if the household head is a member of the Communist Party of China and zero otherwise \\
            \addlinespace
            Job   & Dummy variable that equals one if the household head is employed and zero otherwise \\
            \addlinespace
            House & Dummy variable that equals one if the household holds real estate asset and zero otherwise \\
            \bottomrule
        \end{tabularx}
        \label{tab:definition}
    \end{table}
\end{document}

结果 \addlinespace

答案2

像这样:

在此处输入图片描述

您应该输入第二个\makecell\makecell[tl]{...

    \makecell[t]{Education} & \makecell[tl]{The Education level of the household head;\\
        equals 1 with level of non-educational; \\
        equals 2 with level of primary school; \\
        equals 3 with level of junior high school; \\
        equals 4 with level of high school; \\
        equals 5 with level of secondary/vocational school; \\
        equals 6 with level of college/vocational; \\
        equals 7 with level of undergraduate degree; \\
        equals 8 with level of Master's degree; \\
        equals 9 with level of PhD degree; }  \\

相关内容