创建表时的对齐问题

创建表时的对齐问题

我正在尝试使用以下代码在两列 ieeetransaction 类下创建一个表。但是,由于属性的大小不一,我无法正确对齐属性。请帮忙。

%Table packages
\usepackage{booktabs, makecell, multirow, tabularx}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\usepackage[figuresright]{rotating}
\setlength{\rotFPtop}{0pt plus 1fil}
\renewcommand{\theadfont}{\bfseries}
\renewcommand{\theadfont}{\footnotesize\bfseries}
\renewcommand\theadgape{}



 \begin{table}
  \centering
  \begin{tabularx}
                {\linewidth}{>{\raggedright\arraybackslash}p{0.5in}
                            >{\raggedright\arraybackslash}p{0.5in}
                             >{\raggedright\arraybackslash}p{0.5in}
                             >{\raggedright\arraybackslash}p{1.2in}
                             }
\toprule
\thead{ID} &\thead{AGE/Gender} & \thead{Earlier\\Fall} & \thead{Known attributes}\\
\midrule\\
\textbf{1} & 70/M & No & osteoarthritis; low back pain\\
\addlinespace
\textbf{2} & 75/F & No & Right knee prosthesis\\
\addlinespace
\textbf{3} & 78/M & Yes & Meniscus surgery in both knees\\
\addlinespace
\textbf{4} & 80/F & No & Anemia; pacemaker; left knee pain\\
\addlinespace
\textbf{5} & 82/M & Yes & Heart surgery. Lower limbs weakness\\
\addlinespace
\noalign{\smallskip}\hline
\end{tabularx}
  \caption{Initial attributes}\label{volunteers}
\end{table}

目前的输出看起来像 在此处输入图片描述

答案1

像这样?

在此处输入图片描述

  • 请始终提供可重现问题的 MWE(最小工作示例)
  • tabularx表必须至少有一个列属于X其派生类型
  • 在 IEEEtran 中,文章标题必须位于表格顶部
\documentclass{ieeetran}

\usepackage{booktabs, makecell, multirow, tabularx}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\usepackage[figuresright]{rotating}
\setlength{\rotFPtop}{0pt plus 1fil}
\renewcommand{\theadfont}{\footnotesize\bfseries}
\renewcommand\theadgape{}

\usepackage{lipsum}

\begin{document}
    \begin{table}
    \centering
\caption{Initial attributes}
\label{volunteers}

\begin{tabularx}{\linewidth}{ >{\bfseries}c c c L }
    \toprule
\thead{ID} &\thead{AGE/\\ Gender} & \thead{Earlier\\Fall} & \thead{Known\\ attributes}\\
    \midrule
1   & 70/M & No & osteoarthritis; low back pain\\
    \addlinespace
2   & 75/F & No & Right knee prosthesis\\
    \addlinespace
3   & 78/M & Yes & Meniscus surgery in both knees\\
    \addlinespace
4   & 80/F & No & Anemia; pacemaker; left knee pain\\
    \addlinespace
5   & 82/M & Yes & Heart surgery. Lower limbs weakness\\
    \bottomrule
\end{tabularx}
    \end{table}
\lipsum
\end{document}

附录:
由于您使用makecell包,您的表也可以写成:

\documentclass{ieeetran}

\usepackage{booktabs, makecell, multirow, tabularx}
\setcellgapes{3pt}  % <--- new
\renewcommand{\theadfont}{\footnotesize\bfseries}
\renewcommand\theadgape{}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}

\usepackage{lipsum}

\begin{document}
    \begin{table}
    \centering
    \makegapedcells  % <--- new
\caption{Initial attributes}
\label{volunteers}

\begin{tabularx}{\linewidth}{ >{\bfseries}c c c L }
    \toprule
\thead{ID} &\thead{AGE/\\ Gender} & \thead{Earlier\\Fall} & \thead{Known\\ attributes}\\
    \midrule
1   & 70/M & No & osteoarthritis; low back pain\\
2   & 75/F & No & Right knee prosthesis\\
3   & 78/M & Yes & Meniscus surgery in both knees\\
4   & 80/F & No & Anemia; pacemaker; left knee pain\\
5   & 82/M & Yes & Heart surgery. Lower limbs weakness\\
    \bottomrule
\end{tabularx}
    \end{table}
\lipsum
\end{document}

结果与以前非常相似。

编辑:
关于 OP 评论:您可以使用tabulartable 代替tabularx并使用 columnl代替来使表格变窄L

\documentclass{ieeetran}

\usepackage{booktabs, makecell, multirow, tabularx}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\usepackage[figuresright]{rotating}
\setlength{\rotFPtop}{0pt plus 1fil}
\renewcommand{\theadfont}{\footnotesize\bfseries}
\renewcommand\theadgape{}

\usepackage{lipsum}  % for dummy text filler

\begin{document}
    \begin{table}
    \centering
\caption{Initial attributes}
\label{volunteers}

\begin{tabular}{ >{\bfseries}c c c l }
    \toprule
\thead{ID} &\thead{AGE/\\ Gender} & \thead{Earlier\\Fall} & \thead{Known\\ attributes}\\
    \midrule
1   & 70/M & No & osteoarthritis; low back pain\\
    \addlinespace
2   & 75/F & No & Right knee prosthesis\\
    \addlinespace
3   & 78/M & Yes & Meniscus surgery in both knees\\
    \addlinespace
4   & 80/F & No & Anemia; pacemaker; left knee pain\\
    \addlinespace
5   & 82/M & Yes & Heart surgery. Lower limbs weakness\\
    \bottomrule
\end{tabular}
    \end{table}
\lipsum
\end{document}

在此处输入图片描述

相关内容