变量描述表左对齐

变量描述表左对齐

我不明白为什么在下面的代码中(我知道我可能需要稍微完善一下序言),我无法将“变量”左对齐。我尝试了不同的解决方案,但它仍然居中。

另一个(次要且不太重要的)问题是,我尝试更改列的顺序,将描述放在最后。但是我总是收到错误消息。有什么想法吗?

\documentclass[11pt]{article}
\usepackage{rotating}

\usepackage{longtable}
\usepackage[labelfont=bf, labelsep=newline, justification=centering, textfont=it]{caption}
\usepackage{adjustbox}
\usepackage{graphicx}
\usepackage{booktabs, makecell, siunitx}
\usepackage{eqparbox}
\pagenumbering{gobble}
\usepackage{booktabs}
\usepackage[referable,para]{threeparttablex}
\usepackage[a4paper,margin=1.5cm]{geometry}
\usepackage{multirow}
\usepackage{pdflscape}
\usepackage{stackengine}
\usepackage{interval}
\usepackage{amsmath,ragged2e} % <-- new
\usepackage{interval,pbox}

\usepackage{booktabs,tabularx}

\sisetup{group-separator={,}, table-format=1.3, table-space-text-post=***, 
table-number-alignment =center}
\newcommand*{\MyIndent}
{\hspace*{1.5cm}}
\usepackage{dcolumn}
\newcolumntype{d}[1]{D..{#1}}
\newcommand\mc[1]{\multicolumn{1}{c}{#1}} % handy shortcut macro

\newcommand\mytab[1]{%
   \smash[b]{\begin{tabular}[c]{@{}c@{}}#1\end{tabular}}}
\hyphenation{bur-kina}

\begin{document}

\begin{table}
\renewcommand{\arraystretch}{1.5} 

\caption{Descriptions of variables\label{A1}}
\begin{tabularx}{\textwidth}{@{}lXSS@{}}
\toprule
\multicolumn{1}{l}{Variables}&\mc{Description}&\mc{Mean}&\mc{SD}\\
\midrule
Health&Test of a really long description which should itself span many rows, in fact occupying much space, hopefully, causing it to span a couple of normal rows. Test of a really long description which should itself span many rows, in fact occupying much space, hopefully, causing it to span a couple of normal rows&\mc{0.8049}&\mc{0.3928}\\
Age&Test of a really long description which should itself span many rows, in fact occupying much space, hopefully, causing it to span a couple of normal rows&\mc{49.16}&\mc{15.82}\\
\bottomrule
\end{tabularx}
\end{table}
\end{document}

答案1

像这样吗?

\documentclass[11pt]{article}
\usepackage{rotating}

\usepackage{longtable}
\usepackage[labelfont=bf, labelsep=newline, justification=centering, textfont=it]{caption}
\usepackage{adjustbox}
\usepackage{graphicx}
\usepackage{booktabs, makecell, siunitx}
\usepackage{eqparbox}
\pagenumbering{gobble}
\usepackage{booktabs}
\usepackage[referable,para]{threeparttablex}
\usepackage[a4paper,margin=1.5cm]{geometry}
\usepackage{multirow}
\usepackage{pdflscape}
\usepackage{stackengine}
\usepackage{interval}
\usepackage{amsmath,ragged2e} % <-- new
\usepackage{interval,pbox}

\usepackage{booktabs,tabularx}

\sisetup{group-separator={,}, table-format=1.3, table-space-text-post=***, 
table-number-alignment =center}
\newcommand*{\MyIndent}
{\hspace*{1.5cm}}
\usepackage{dcolumn}
\newcolumntype{d}[1]{D..{#1}}
\newcommand\mc[1]{\multicolumn{1}{c}{#1}} % handy shortcut macro

\newcommand\mytab[1]{%
   \smash[b]{\begin{tabular}[c]{@{}c@{}}#1\end{tabular}}}
\hyphenation{bur-kina}

\begin{document}

\begin{table}
\renewcommand{\arraystretch}{1.5} 

\caption{Descriptions of variables\label{A1}}
\begin{tabularx}{\textwidth}{@{}lXSS@{}}
\toprule
\multicolumn{1}{@{}l}{Variables}&\mc{Description}&\mc{Mean}&\mc{SD}\\ % @{} here
\midrule
Health&Test of a really long description which should itself span many rows, in fact occupying much space, hopefully, causing it to span a couple of normal rows. Test of a really long description which should itself span many rows, in fact occupying much space, hopefully, causing it to span a couple of normal rows&\mc{0.8049}&\mc{0.3928}\\
Age&Test of a really long description which should itself span many rows, in fact occupying much space, hopefully, causing it to span a couple of normal rows&\mc{49.16}&\mc{15.82}\\
\bottomrule
\end{tabularx}
\end{table}
\end{document}

在此处输入图片描述

相关内容