how to fix the width of the columns in the latex table?

Welcome to TeX.SE. You can use the p> column type, and use a \parbox for the table content. It would be helpful if you composed a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages as that will help to ensure that the solution actually solves your specific case.

Commented Apr 6, 2012 at 19:00 @peter, thanks , this \parbox will be used with every cell's content? Commented Apr 6, 2012 at 19:01 Better if you compose a small example, and then we can show you how to use it. Commented Apr 6, 2012 at 19:02 @peter, here is an example Commented Apr 6, 2012 at 19:12 Commented Oct 16, 2021 at 6:29

2 Answers 2

Here is an example of using the p<> column type, or wrapping the contents in a \parbox :

enter image description here

For your specific example, since you want the data columns aligned as per the table heading you could use something like:

\newcommand*<\TitleParbox>[1]<\parbox[c]<1.75cm>>% \begin <|l|r|r|r|r|r|>\hline Image & Score & \parbox[c] & \TitleParbox &\TitleParbox& \TitleParbox\\ \hline a \(left\) & 1 & 1 & 1 & 1 & 1 \\ \hline b \(right\)& 1 &1 & 1 & 1 & 1 \\ \hline \end

enter image description here

Notes:

Code:

\documentclass \usepackage \newcommand*<\Title>% \newcommand*<\TitleInParbox><\parbox[c]<0.3\linewidth><\Title>>% \begin \section \noindent \begin \Title & \Title & \Title \end \section column type:> \noindent \begin p <0.3\linewidth>p<0.3\linewidth>> \Title & \Title & \Title \end \section \noindent \begin \TitleInParbox & \TitleInParbox & \TitleInParbox \end \end
answered Apr 6, 2012 at 19:15 Peter Grill Peter Grill 225k 50 50 gold badges 586 586 silver badges 931 931 bronze badges

In addition to considering the methods mentioned in @PeterGrill's answer, you should also consider using a tabularx environment. It provides a column type called X , which is (in effect) a p column -- i.e., it allows line wrapping -- but lets you dispense with the tedium of having to calculate the column widths if you want to make the table fit inside a given width, say, \textwidth .

You may also want to think about giving your table a more "open" look. In the following screenshot, the first table follows the layout provided in your code (except that a tabularx environment is used, with a modified X column type for columns 3 thru 6), whereas the second table achieves the "open" look by getting rid of all vertical rules and using fewer, but well spaced, horizontal rules.

enter image description here

\documentclass \usepackage \newcolumntype<><\RaggedRight\arraybackslash>X> % ragged-right version of "X" \begin \begin[t] \caption \begin <|l|r|L|L|L|L|>\hline Image & Score & here is a lot of text & again a lot & a lot and a lot & and the same here \\ \hline a \emph & 1 & 1 & 1 & 1 & 1 \\ \hline b \emph & 1 &1 & 1 & 1 & 1 \\ \hline \end \end \begin[h] \caption \begin lrLLLL @<>> \toprule Image & Score & here is a lot of text & again a lot & a lot and a lot & and the same here \\ \midrule a \emph & 1 & 1 & 1 & 1 & 1 \\ b \emph & 1 &1 & 1 & 1 & 1 \\ \bottomrule \end \end \end