4

I want to make a table where all the cells will have equal width.enter image description here

Here the cells width of automobile is bigger than the others.So i want to take all the cells have the width of automobile. I tried this code but don't know how to specify width and height of a cell:

\begin{table}[]
\centering
\caption{My caption}
\label{my-label}
\begin{tabular}{|l|l|l|l|l|l|}
\hline
labels     & airplane & automobile & bird & cat & deer \\ \hline
airplane   &          &            &      &     &      \\ \hline
automobile &          &            &      &     &      \\ \hline
bird       &          &            &      &     &      \\ \hline
cat        &          &            &      &     &      \\ \hline
\end{tabular}
\end{table}
  • Either use tabularx package and the X column or replace l with p{3cm} or something like that – user31729 Apr 20 '16 at 18:03
  • can u show me an example?? – Setu Kumar Basak Apr 20 '16 at 18:05
  • The vertical lines are not really nice – user31729 Apr 20 '16 at 18:13
2

The cleanest way is using the X columntype from tabularx package -- it calculates the column width from the width speficied as 1st argument to tabularx.

enter image description here

\documentclass{article}

\usepackage{tabularx}


\begin{document}

\begin{table}
\centering
\caption{My caption}
\label{my-label}
\begin{tabular}{|*{6}{p{1.5cm}|}}
\hline
labels     & airplane & automobile & bird & cat & deer \\ \hline
airplane   &          &            &      &     &      \\ \hline
automobile &          &            &      &     &      \\ \hline
bird       &          &            &      &     &      \\ \hline
cat        &          &            &      &     &      \\ \hline
\end{tabular}
\end{table}


\begin{table}
\centering
\caption{My caption}
\label{my-other-label}
\begin{tabularx}{\linewidth}{|*{6}{X|}}
\hline
labels     & airplane & automobile & bird & cat & deer \\ \hline
airplane   &          &            &      &     &      \\ \hline
automobile &          &            &      &     &      \\ \hline
bird       &          &            &      &     &      \\ \hline
cat        &          &            &      &     &      \\ \hline
\end{tabularx}
\end{table}


\end{document}
|improve this answer|||||
  • ! Extra alignment tab has been changed to \cr. why am i getting this error?? – Setu Kumar Basak Apr 20 '16 at 18:19
  • @setubasak: You have too much & in your example. My posted code works – user31729 Apr 20 '16 at 18:22
  • I have 10x10 table.. yes i have lot of & this.. so what can i do then?? – Setu Kumar Basak Apr 20 '16 at 18:23
  • Replace the 6 from my code with a 10 then ;-) What do you think the 6 does there? ;-) – user31729 Apr 20 '16 at 18:24
  • how can i control the height of the cell?? – Setu Kumar Basak Apr 20 '16 at 18:32
1

A nicer-looking version using booktabs:

enter image description here

\documentclass{article}
\usepackage{tabularx,booktabs}
\begin{document}

\begin{table}
\centering
\caption{My caption}
\label{my-other-label}
\begin{tabularx}{\linewidth}{l*{5}{X}}
\toprule
labels     & airplane & automobile & bird & cat & deer \\ \midrule
airplane   &          &            &      &     &      \\ 
automobile &          &            &      &     &      \\ 
bird       &          &            &      &     &      \\ 
cat        &          &            &      &     &      \\ \bottomrule
\end{tabularx}
\end{table}

\end{document}
|improve this answer|||||
  • how can i increase or decrease overall table size as my table will be 10x10?? – Setu Kumar Basak Apr 20 '16 at 18:25
  • @setubasak - You can rotate your table by 90 degrees using the sidewaystable environment after loading the rotating package. – AboAmmar Apr 20 '16 at 18:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.