0

I have the following:

\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}

And my output is: enter image description here

But I want the 'TK' to be in the second column, not the first. Can someone help?

2
  • You need to take care to enter all cell separators & correctly. Also, groups (enclosed with {}) cannot span across cells (at least not in a traditional tabular). The code for the second and third row should read Olmesartan & 19 Resides from Table \ref{tab:atomDistance} \\ Changed Lys326 to a Gly & \\ . Apr 2, 2023 at 0:57
  • 1
    If you want "TK" to be in the second column, the code for the seventh and eighth row should probably read Result \#7 & 19 Resides from Table \ref{tab:atomDistance} \\ & TK \\ . And similarly for the other relevant rows. Apr 2, 2023 at 1:01

1 Answer 1

2

You cannot use \\ to insert a line break inside a call. You could use \newline, but then you also need to change the column definition to p{5cm} (or some other fixed width).

\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}

enter image description here

Of course, you could also simply insert new rows and leave the left cell empty (and stick to the l column type):

\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}

I would suggest that you try the tabularray package. It allows using your syntax without any further ado:

\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}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .