值与变量标签一致

值与变量标签一致

我有一个要创建的表格的 latex 代码。我很难用变量名来标出一个值。例如,我想将 3,000 的值放在上面一行的 N 列中(与变量在同一行)。我目前刚接触 latex,一直在尝试使用下面的代码来做到这一点,但遗憾的是,我没有成功。有人知道如何解决这个问题吗?

\documentclass{article}
\usepackage[a4paper,margin=2.5cm]{geometry} % set page parameters suitably
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{fancyhdr}
\usepackage{booktabs}
\usepackage{array}
\usepackage{booktabs}
\usepackage{rotating} % for 'sidewaytable' env.
\usepackage[para]{threeparttable}
\newcommand\mytabC[1]{\begin{tabular}{@{}c@{}} #1 \end{tabular}}
\newcommand\mytabL[1]{\hspace{5mm}\begin{tabular}{@{}l@{}} #1 \end{tabular}}

\begin{document}

\clearpage
\renewcommand\arraystretch{1.0} 

\thispagestyle{empty}

\newenvironment{rotatepage}%
    {\clearpage\pagebreak[4]\global\pdfpageattr\expandafter{\the\pdfpageattr/Rotate 90}}%
    {\clearpage\pagebreak[4]\global\pdfpageattr\expandafter{\the\pdfpageattr/Rotate 0}}%

<!-- \begin{rotatepage} -->

\begin{sidewaystable}
\setlength\tabcolsep{0pt}
\scriptsize
\begin{threeparttable}
\caption[short title]{Long title)}
\label{tab:tab5}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}l*{6}{c} }
\toprule
  &
    \multicolumn{3}{c}{Females\tnote{a}} &
    \multicolumn{3}{c}{Male\tnote{d}} \\ 
    \cmidrule{2-4} \cmidrule{5-7}
  Socioeconomic indicator &
    N & Coefficient\tnote{e} & 95\% CI\tnote{f} &
    N & Coefficient\tnote{e} & 95\% CI\tnote{f} \\
\midrule

\multicolumn{5}{@{}l}{\textbf{Variable name}} \\
  \mytabL{category 1 \\ category 2 \\ category 3} &
  \mytabC{3,000} &
  \mytabC{0.00 (ref)\\ 0.94\\ -1.14} &
  \mytabC{—\\ -1.39, -0.49\\ -1.74, -0.54} &
  \mytabC{3,000} &
  \mytabC{0.00 (ref)\\ -0.59\\ -0.57} &
  \mytabC{—\\ -1.03, -0.15\\ -1.15, -0.02} \\
  \hspace{2.5mm}$p$-values (overall\tnote{g}; test for trend\tnote{h}) &
    & & <0.001; <0.001 & & & 0.025; 0.025  \\
\bottomrule
\end{tabular*}

\smallskip
\begin{tablenotes}    
\item[a] Mode 1: unadjusted.
\end{tablenotes}    
\end{threeparttable}
\end{sidewaystable}

<!-- \end{rotatepage} -->
<!-- \clearpage -->

\end{document}

在此处输入图片描述

答案1

在此处输入图片描述

\documentclass{article}
\usepackage[a4paper,margin=2.5cm]{geometry} % set page parameters suitably
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{fancyhdr}
\usepackage{booktabs}
\usepackage{array}
\usepackage{booktabs}
\usepackage{rotating} % for 'sidewaytable' env.
\usepackage[para]{threeparttable}


\begin{document}



%\begin{sidewaystable} % table is narrow enough to fit on a portrait page --> no need to rotate it
\begin{table}
\setlength\tabcolsep{0pt}
%\scriptsize % table is noarrow enough to fit even with a normalsize font--> no need to reduce the font size.
\begin{threeparttable}
\caption[short title]{Long title)}
\label{tab:tab5}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}l*{6}{c} }
\toprule
  &
    \multicolumn{3}{c}{Females\tnote{a}} &
    \multicolumn{3}{c}{Male\tnote{d}} \\ 
    \cmidrule(lr){2-4} \cmidrule(lr){5-7}
  Socioeconomic indicator &
    N & Coefficient\tnote{e} & 95\% CI\tnote{f} &
    N & Coefficient\tnote{e} & 95\% CI\tnote{f} \\
\midrule

\textbf{Variable name} & 3,000 &            &                & 3,000                             \\
\quad category 1             &       & 0.00 (ref) & --             &       & 0.00 (ref) & --           \\
\quad category 2             &       & 0.94       & -1.39, -0.49   &       & -0.59      & -1.03, -0.15 \\
\quad category 3             &       & -1.14      & -1.74, -0.54   &       & -0.57      & -1.15, -0.02 \\
\quad $p$-values (overall\tnote{g}; test for trend\tnote{h})
                       &       &            & <0.001; <0.001 &       &            & 0.025; 0.025  \\
\bottomrule
\end{tabular*}
\begin{tablenotes}    
\item[a] Mode 1: unadjusted.
\end{tablenotes}    
\end{threeparttable}
\end{table}
%\end{sidewaystable}


\end{document}

相关内容