在表格中使用 \makecell 进行顶部和左侧对齐

在表格中使用 \makecell 进行顶部和左侧对齐

我正在努力使特定单元格(第 4 列)顶部和左侧对齐。不太清楚为什么 \makecell 不配合,但这是我的乳胶代码:

\documentclass[10pt,a4paper]{article}
\usepackage[left=1cm, right=1cm, top=2cm]{geometry}
\usepackage{booktabs}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{array}
\usepackage{makecell}
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\parindent=0em \parskip=20pt
\newcommand\A{\rule{0pt}{2.5ex}}
\newcommand{\tabitem}{~~\llap{\textbullet}~~}
\begin{document}
\begin{center}

\begin{tabular}{llL{5.5cm}L{4.5cm}}
\toprule
\textbf{Variable} & \textbf{Census Code} & \textbf{Description} & \textbf{Study Variables} \\

\midrule
Education & cen\_ind\_std\_highest\_qual\_code & This variable records the highest qualification achieved by an individual. A qualification is a formally recognised award for educational or training attainment by one of the following authorities: 
    \begin{itemize}
        \item New Zealand Qualifications Authority and their recognised approval bodies 
        \item Universities New Zealand 
        \item Associations of Polytechnics of New Zealand 
        \item Association of Colleges of Education in New Zealand 
        \item Recognised overseas authorities
    \end{itemize}
 & \makecell[tl]{\textbf{highest\_qual}: \\ \hspace{\parindent} 0. No formal qualifications \\ \hspace{\parindent} 1. Level 1, 2, or 3 certificate \\ \hspace{\parindent} 2. Level 4, 5, or 6 certificate \\ \hspace{\parindent} 3. Undergraduate degree \\ \hspace{\parindent} 4, Postgraduate degree \\
 \hspace{\parindent} 9. Missing or unidentifiable} \\

\bottomrule 
\end{tabular}   

\end{center}
\end{document} 

在此处输入图片描述

答案1

我不确定您想获得什么。但是,最后一列是类型,因此无论内容是否封装在任何环境中(在您的示例中),m此列中所有单元格的内容都垂直居中。makecell

尝试mp列类型替换。然后您将(考虑到代码中建议的更改)获得:

在此处输入图片描述

(红线表示文本边框)

我建议使用enumitem表中的列表包并省略\makecell环境:

\documentclass[10pt,a4paper]{article}
\usepackage[hmargin=1cm, top=2cm]{geometry}
%\usepackage[latin1]{inputenc}
\usepackage{amsmath, amssymb}
\usepackage{graphicx}
\usepackage{booktabs, makecell}
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}
\parindent=0em
\parskip=20pt

\usepackage{enumitem}

%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
    \begin{center}
    \setlist[itemize]{topsep = 1ex, parsep =0pt, leftmargin=*,after=\vspace{-\baselineskip}}
\begin{tabular}{ll L{5.5cm} L{4.5cm}}
\toprule
\textbf{Variable} & \textbf{Census Code} & \textbf{Description} & \textbf{Study Variables} \\
    \midrule
Education
    & cen\_ind\_std\_highest\_qual\_code
        & This variable records the highest qualification achieved by an individual. A qualification is a formally recognised award for educational or training attainment by one of the following authorities:
    \begin{itemize}
        \item New Zealand Qualifications Authority and their recognised approval bodies
        \item Universities New Zealand
        \item Associations of Polytechnics of New Zealand
        \item Association of Colleges of Education in New Zealand
        \item Recognised overseas authorities
    \end{itemize}
            & \textbf{highest\_qual}
                \begin{itemize}[leftmargin=1.5em]
            \item[0.]   No formal qualifications
            \item[1.]   Level 1, 2, or 3 certificate
            \item[2.]   Level 4, 5, or 6 certificate
            \item[3.]   Undergraduate degree
            \item[4.]   Postgraduate degree
            \item[9.]   Missing or unidentifiable
                \end{itemize}   \\
    \bottomrule
\end{tabular}
    \end{center}
\end{document}

编辑: 您可能喜欢以下表格格式:

在此处输入图片描述

在它使用的tabularx表环境中(它需要加载tabularx包):

\begin{tabularx}{\linewidth}{@{} ll 
    X 
    p{4.5cm} @{}}
\toprule
     %%%% table body, the same as above
\bottomrule
\end{tabularx}

相关内容