I have a table defined as follows where the first column is right-justified:
\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{array}
\begin{document}
\begin{table}
\centering
\begin{tabular}{>{\hfill}p{3.50cm}p{5.50cm}p{5.50cm}}
\hline\noalign{\smallskip}
\textbf{Column 1} & \textbf{Column 2} & \textbf{Column 3} \\ [0.5ex]
\hline\noalign{\smallskip}
1 & text & text \\
2 & text & text \\
\hline\noalign{\smallskip}
\end{tabular}
\caption{thisTable.}
\label{tab:thisTable}
\end{table}
\end{document}
However, the column heading of the first column is also right-justified.
Can I change the column heading to be left-justified but leave the values contents of the data part of the column right-aligned?
Best Answer
Yes. Just place the cell's contents in a
\multicolumn{1}{l}{...}
"wrapper".Incidentally, instead of using the somewhat kludgy
\hline\noalign{\smallskip}
directives, I suggest you load thebooktabs
package and use its macros\toprule
,\midrule
, and\botttomrule
to get well-spaced horizontal lines.And, instead of the
>{\hfill}p{3.50cm}
specification of the left-most column, I suggest you load thearray
andragged2e
packages and define a raggedleft (flushright) column type that takes a width parameter, as is done in the example below.Addendum to address the OP's follow-up question: If the cell in question has a lot of text that needs to span several lines, you can still use
\multicolumn
, but not with thel
column type specifier. E.g., you might typein the preamble and then write
instead of the earlier
In short,
\multicolumn
is a very powerful and flexible tool.