表格单元格中的第二列有多行

表格单元格中的第二列有多行

我有以下内容:

\begin{table}[H]
\centering
\begin{tabular}{| l | l |}
\hline
\cellcolor{lightgray}Ligand & \cellcolor{lightgray}Residue Changes\\
\hline
Olmesartan & {19 Resides from Table \ref{tab:atomDistance} \\ Changed Lys326 to a Gly}\\
\hline
Losartan & 19 Resides from Table \ref{tab:atomDistance}\\
\hline
Result \#1 & 19 Resides from Table \ref{tab:atomDistance}\\
\hline
Result \#6 & 19 Resides from Table \ref{tab:atomDistance}\\
\hline
Result \#7 & {19 Resides from Table \ref{tab:atomDistance} \\ TK}\\
\hline
Result \#16 & {19 Resides from Table \ref{tab:atomDistance} \\TK}\\
\hline
Result \#24 & {19 Resides from Table \ref{tab:atomDistance} \\ TK}\\
\hline
\end{tabular}
\caption{Protein Structural Changes}
\label{tab:structureChanges}
\end{table}

我的输出是: 在此处输入图片描述

但我希望“TK”位于第二列,而不是第一列。有人能帮忙吗?

答案1

您不能使用\\在调用中插入换行符。您可以使用\newline,但您还需要将列定义更改为p{5cm}(或其他固定宽度)。

\documentclass{article}
\usepackage[table]{xcolor}

\begin{document}

\begin{tabular}{| l | p{5cm} |}
\hline
\cellcolor{lightgray}Ligand & \cellcolor{lightgray}Residue Changes\\
\hline
Olmesartan & { 19 Resides from Table \ref{tab:atomDistance} \newline Changed Lys326 to a Gly } \\
\hline
Losartan & 19 Resides from Table \ref{tab:atomDistance} \\
\hline
Result \#1 & 19 Resides from Table \ref{tab:atomDistance} \\
\hline
Result \#6 & 19 Resides from Table \ref{tab:atomDistance} \\
\hline
Result \#7 & { 19 Resides from Table \ref{tab:atomDistance} \newline TK } \\
\hline
Result \#16 & { 19 Resides from Table \ref{tab:atomDistance} \newline TK } \\
\hline
Result \#24 & { 19 Resides from Table \ref{tab:atomDistance} \newline TK } \\
\hline
\end{tabular}

\end{document}

在此处输入图片描述

当然,您也可以简单地插入新行并将左侧单元格留空(并坚持l列类型):

\documentclass{article}
\usepackage[table]{xcolor}

\begin{document}

\begin{tabular}{| l | l |}
\hline
\cellcolor{lightgray}Ligand & \cellcolor{lightgray}Residue Changes\\
\hline
Olmesartan & 19 Resides from Table \ref{tab:atomDistance} \\ 
    & Changed Lys326 to a Gly \\
\hline
Losartan & 19 Resides from Table \ref{tab:atomDistance} \\
\hline
Result \#1 & 19 Resides from Table \ref{tab:atomDistance} \\
\hline
Result \#6 & 19 Resides from Table \ref{tab:atomDistance} \\
\hline
Result \#7 & 19 Resides from Table \ref{tab:atomDistance} \\
    & TK \\
\hline
Result \#16 & 19 Resides from Table \ref{tab:atomDistance} \\
    & TK \\
\hline
Result \#24 & 19 Resides from Table \ref{tab:atomDistance} \\ 
    & TK \\
\hline
\end{tabular}

\end{document}

我建议你尝试一下这个tabularray包。它允许你使用你的语法,无需多言:

\documentclass{article}
\usepackage{tabularray, xcolor}

\begin{document}

\begin{tblr}{ | l | l | }
\hline\SetRow{bg=lightgray}
Ligand & Residue Changes \\
\hline
Olmesartan & { 19 Resides from Table \ref{tab:atomDistance} \\ Changed Lys326 to a Gly } \\
\hline
Losartan & 19 Resides from Table \ref{tab:atomDistance}\\
\hline
Result \#1 & 19 Resides from Table \ref{tab:atomDistance}\\
\hline
Result \#6 & 19 Resides from Table \ref{tab:atomDistance}\\
\hline
Result \#7 & { 19 Resides from Table \ref{tab:atomDistance} \\ TK } \\
\hline
Result \#16 & { 19 Resides from Table \ref{tab:atomDistance} \\ TK } \\
\hline
Result \#24 & { 19 Resides from Table \ref{tab:atomDistance} \\ TK } \\
\hline
\end{tblr}

\end{document}

在此处输入图片描述

相关内容