我想将第一行单元格居中对齐,其他行居左对齐。因此,我编写了以下代码
\documentclass[conference]{IEEEtran}
\IEEEoverridecommandlockouts
\usepackage{multirow}
\begin{document}
Table \ref{wrk-desc} briefly
\begin{table}[]
\caption{}
\label{prt-desc}
\begin{tabular}{|p{1cm}|p{7cm}|}
\hline
\multicolumn{1}{c}\textbf{Suite} & \multicolumn{1}{c} \textbf{Workload} \\
\hline
Item1 & program1, program2, ... \\
\hline
Item1 & program10, program11, ... \\
\hline
Item1 & program20, program21, ... \\
\hline
\end{tabular}%
\end{table}
\end{document}
但是输出并不正确。
我该如何修复它?
答案1
thead
它使用以下命令工作makecell
:
\documentclass[conference]{IEEEtran}
\IEEEoverridecommandlockouts
\usepackage{array, multirow}
\usepackage{makecell}
\begin{document}
Table \ref{wrk-desc} briefly
\begin{table}[]
\caption{}\label{wrk-desc}
\label{prt-desc}
\begin{tabular}{|p{1cm}|p{7cm}|}
\hline
\thead{\bfseries Suite} & \thead{\bfseries Workload} \\
\hline
Item1 & program1, program2, ... \\
\hline
Item1 & program10, program11, ... \\
\hline
Item1 & program20, program21, ... \\
\hline
\end{tabular}%
\end{table}
\end{document}
答案2
列标题有误。改为使用
\multicolumn{1}{c}\textbf{Suite} & \multicolumn{1}{c} \textbf{Workload} \\
它应该是
\multicolumn{1}{c}{\textbf{Suite}} & \multicolumn{1}{c}{\textbf{Workload}} \\
(观察花括号中的差异)。使用上面的代码行,您的 MWE 可以正常工作。无论如何,我会考虑 @Bernard 的建议\thead
(在序言中使用适当的设置)并使用tabularx
以下表格:
\documentclass[conference]{IEEEtran}
\IEEEoverridecommandlockouts
\usepackage{ragged2e}
\usepackage{makecell, tabularx}
\setcellgapes{2pt}
\renewcommand\theadfont{\bfseries}
\renewcommand\theadgape{}
\newcolumntype{L}{>{\RaggedRight\hspace{0pt}}X}
\usepackage{lipsum}
\begin{document}
Table \ref{wrk-desc} briefly
\begin{table}[htb]
\makegapedcells
\caption{}\label{wrk-desc}
\label{prt-desc}
\begin{tabularx}{\linewidth}{|l|L|}
\hline
\thead{Suite} & \thead{Workload} \\
\hline
Item 1 & program1, program2, ... \\
\hline
Item 2 & program10, program11, ... \\
\hline
Item 3 & program20, program21, ... \\
\hline
\end{tabularx}%
\end{table}
\lipsum
\end{document}