Latex will automatically adjust the width of a cell in a table. If you wish to have a table where each cell in a row has the same width, you would use the p
option instead of l
, c
or r
for left, centre or right alignment.
Example:
\documentclass[11pt]{article} \begin{document} \begin{table}[ht] \caption{Table with equal cell width.} \begin{center} \begin{tabular}{p{1cm}|p{1cm}} \hline a&bbb\\ \hline a&bbb\\ a&bbb\\ \hline \end{tabular} \end{center} \end{table} \end{document}
This is true, but the p{} command implies left alignment.
What if you want a fixed width column _and_ center (or right) alignment?
Hi Dector,
Thanks for your comment, you are perfectly right. As this is not an easy thing to do and it is best explained with some pieces of latex code, let me write a new post on that issue.
Hope you don’t mind,
Tom
Fwd: Equal cell width right and centre aligned content « Blog on Latex Matters
[…] Fwd: Equal cell width right and centre aligned content One of my last posts was on how to define the width of a column in a table (see here). […]
Hi,
I found a round-about way. I used {c c c c} but for the first row I inserted \hspace {1cm} on either side of each entry. This way I could introduce space as much I wished to, and also had the text centered. Once done for the first row u do not need to repeat it for the following rows.
Hi,
I was wondering, is there was a way to define an overall table width without affect text sizes? Any info would help immensely, thanks!
Hey Jackie,
If I understand your question correctly, you can use a fixed cell width to produce a fixed table width, where the text size will not influence the size as described in the post.
Ok?
Tom.
Cool! Thank you very much
Hi,
You can use array package and do as follows:
Thank you
It is nice
Thank you very much. Saved me a whole lot of wasted time!
Another solution is to use, e.g.:
Before
Hi Gideon,
Nice, I didn’t know that, thanks! There seems to be a slight difference though. Setting
tabcolsep
keeps the cell width flexible. In other words, when the content takes more space, the width is automatically adjusted. Withp{width}
however, the cell width will not change, no matter what.Best, Tom.
Hi Gideon,
Thanks a lot. I struggled half a day to change column width.Once again thanks.
C
Thanks, glad I could help. Tom.