Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to specify column width and center alignment same time ?

1 view
Skip to first unread message

kothrush

unread,
Oct 28, 2006, 6:08:43 PM10/28/06
to
I have created a table with on two columns. I specified width for one
of them ( say 2in). Now that column is all left aligned when I typeset
it. How do i makes its also center align ?

so, basically how do i specify p{width} and "c" at the same time for a
given column ? any help appreciated. see sample below what i have now.

\begin{table}[htb]
\caption{Material Properties}
\label{tab:prop1}
\begin{center}
\begin{tabular}{|p{2in}|c|}
\hline E$_1$ & 140 GPa \\\hline E$_2$ & 10 GPa \\\hline G$_{12}$ & 6.9
GPa \\\hline v$_{12}$ & 0.3 \\\hline
\end{tabular}
\end{center}
\end{table}

Enrico Gregorio

unread,
Oct 28, 2006, 6:41:06 PM10/28/06
to
kothrush <rushabh...@gmail.com> wrote:

\usepackage{array}

\begin{table}[htb]
\caption{Material Properties}
\label{tab:prop1}

\centering
\begin{tabular}{>{\centering}p{2in}c}
E$_1$ & 140 GPa \\
E$_2$ & 10 GPa \\


G$_{12}$ & 6.9 GPa \\

v$_{12}$ & 0.3

\end{tabular}
\end{table}

Don't use vertical or horizontal lines, they spoil every table.
Have a look at the documentation of the package booktabs.

The same trick doesn't work as is for the /last/ column; for that
the correct way is to add >{\centering\arraybackslash} in front of
the p specifier.

Ciao
Enrico

kothrush

unread,
Oct 28, 2006, 8:26:30 PM10/28/06
to

Is there anyway to do it with vertical and horizontal lines specified ?
Its kinda requirement for the template here, so hard to get by with. if
i just add >{\centering} in front of the p specifier in my code, it
gives error and does not compile.

Enrico Gregorio

unread,
Oct 29, 2006, 4:29:52 AM10/29/06
to
kothrush <allm...@nomail.net> wrote:

> > \begin{table}[htb]
> > \caption{Material Properties}
> > \label{tab:prop1}
> > \centering
> > \begin{tabular}{>{\centering}p{2in}c}
> > E$_1$ & 140 GPa \\
> > E$_2$ & 10 GPa \\
> > G$_{12}$ & 6.9 GPa \\
> > v$_{12}$ & 0.3
> > \end{tabular}
> > \end{table}
> >
> > Don't use vertical or horizontal lines, they spoil every table.
> > Have a look at the documentation of the package booktabs.
> >
> > The same trick doesn't work as is for the /last/ column; for that
> > the correct way is to add >{\centering\arraybackslash} in front of
> > the p specifier.
>

> Is there anyway to do it with vertical and horizontal lines specified ?
> Its kinda requirement for the template here, so hard to get by with. if
> i just add >{\centering} in front of the p specifier in my code, it
> gives error and does not compile.

If you really need lines, then put them in:

\begin{tabular}{|>{\centering}p{2in}|c|}

Ciao
Enrico

Robin Fairbairns

unread,
Oct 29, 2006, 12:06:43 PM10/29/06
to
kothrush <allm...@nomail.net> writes:
>On 2006-10-28 18:41:06 -0400, Enrico Gregorio <greg...@math.unipd.it> said:
>> \usepackage{array}
>>
>> \begin{table}[htb]
>> \caption{Material Properties}
>> \label{tab:prop1}
>> \centering
>> \begin{tabular}{>{\centering}p{2in}c}
>> E$_1$ & 140 GPa \\
>> E$_2$ & 10 GPa \\
>> G$_{12}$ & 6.9 GPa \\
>> v$_{12}$ & 0.3
>> \end{tabular}
>> \end{table}
>
>if i just add >{\centering} in front of the p specifier in my code, it
>gives error and does not compile.

because you left out \usepackage{array}, i expect.
--
Robin Fairbairns, Cambridge

kothrush

unread,
Nov 7, 2006, 9:53:47 AM11/7/06
to

Ok, I think I am doing something wrong here. But it would be great if
someone can explain me whats the advantage of using table as an array
rather than without array ?

Array is giving me problem when i put \hline and gives error.
without array, i can use >{centering} , but i can use /hline, which i need.

so, basically, if I dont want to center align while using p{wd} , I can
just use :

\begin{table}[htb]
\caption{Material Properties}
\label{tab:prop1}

\begin{center}
\begin{tabular}{|p{2in}|c|}
\hline E$_1$ & 140 GPa \\\hline E$_2$ & 10 GPa \\\hline G$_{12}$ & 6.9
GPa \\\hline v$_{12}$ & 0.3 \\\hline
\end{tabular}
\end{center}
\end{table}

No array, nothing. simple table format that I use ALL the time. Now
just to center align, I have go through array ? isn't there any other
way to center align column in above table ?

Lars Madsen

unread,
Nov 7, 2006, 9:57:14 AM11/7/06
to

>
> Ok, I think I am doing something wrong here. But it would be great if
> someone can explain me whats the advantage of using table as an array
> rather than without array ?
>
> Array is giving me problem when i put \hline and gives error.
> without array, i can use >{centering} , but i can use /hline, which i need.
>
> so, basically, if I dont want to center align while using p{wd} , I can
> just use :
>
> \begin{table}[htb]
> \caption{Material Properties}
> \label{tab:prop1}
> \begin{center}
> \begin{tabular}{|p{2in}|c|}
> \hline E$_1$ & 140 GPa \\\hline E$_2$ & 10 GPa \\\hline G$_{12}$ & 6.9
> GPa \\\hline v$_{12}$ & 0.3 \\\hline
> \end{tabular}
> \end{center}
> \end{table}
>
> No array, nothing. simple table format that I use ALL the time. Now just
> to center align, I have go through array ? isn't there any other way to
> center align column in above table ?
>

huh, array is just the name of the package, it enables you to add special things
to arrays and tabulars etc.

I cannot see what the problem is with

>{\centering}p{2in}

(>{\centering\arraybackslash}p{in} if it's the last column)


--

/daleif (remove RTFSIGNATURE from email address)

LaTeX FAQ: http://www.tex.ac.uk/faq
LaTeX book: http://www.imf.au.dk/system/latex/bog/ (in Danish)
Remember to post minimal examples, see URL below
http://www.tex.ac.uk/cgi-bin/texfaq2html?label=minxampl

kothrush

unread,
Nov 7, 2006, 2:46:29 PM11/7/06
to
Thanks for the "last column" syntax. I was getting error because of
that and was getting frustrated with array packgae ( >centering input).
Now it seems to work fine.

Where do you find these advanced table formatting guidelines ? I have
looked all over the internet and found only basic table formatting in
literatures. Any recommened book or links ?

Thanks.

Robin Fairbairns

unread,
Nov 8, 2006, 6:17:21 PM11/8/06
to
"kothrush" <rushabh...@gmail.com> writes:
>Thanks for the "last column" syntax. I was getting error because of
>that and was getting frustrated with array packgae ( >centering input).
>Now it seems to work fine.
>
>Where do you find these advanced table formatting guidelines ? I have
>looked all over the internet and found only basic table formatting in
>literatures. Any recommened book or links ?

the latex companion edition 2 covers most things like this -- i would
be surprised if it didn't cover these ways to use array.sty. not
cheap, though -- definitely not a "pocket" book.

the faq covers some things in the area, but i'm not sure it does this,
precisely: since to first order i do all the writing myself, it
requires a coincidence of me having free time and inclination, and
actually realising that a particular question needs answering.

i bet there are other pages around that discuss it, but i don't know
any detail.
--
Robin Fairbairns, Cambridge

0 new messages