Graphics, Figures & TablesCentering Text in Tables - Could not find answer

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
cirasj
Posts: 25
Joined: Mon Mar 09, 2009 3:26 pm

Centering Text in Tables - Could not find answer

Post by cirasj »

I hope I am not annoying anyone with this question. There seems to have been some discussion in the past about it. What I am trying to to is center text in a table and also give the columns defined widths with no luck. I have tried defining \newcolumntype{Z}{>{\centering\arraybackslash}X} with no luck.

Here is the code.

Code: Select all

\begin{sidewaystable}             
  \centering
  \caption{Add caption}
\begin{tabular}{p{.56in}|p{1.0in}|p{.75in}|p{.875in}|p{.875in}|p{.75in}|p{.625in}|p{.625in}}
    \bfseries Grade and Class & {\bfseries Dia (in)} & {\bfseries Tensile min (ksi)} & {\bfseries Yield 0.2\% Offset (min)} & {\bfseries Elongation in 2 in. (\%)} & {\bfseries Reduction of Area (\%)} & \multicolumn{ 2}{c}{{\bfseries Hardness Max}} \\\hline
     &       &  &  &  &  & {\bfseries{\underline{Brinell}} & {\bfseries{\underline{Rockwell}} \\
    Class 1\footnote{B8, B8C, B8M, B8P, B8T, B8LN, B8MLN} & All   & 75    & 30    & 30    & 50    & 223   & B96 \\ \hline
    Class 2\footnote{B8, B8C, B8P, B8T, B8N} & to ¾  & 125   & 100   & 12    & 35    & 321   & C35 \\
     & over ¾ to 1 & 115   & 80    & 15    & 35    & 321   & C35 \\
     & over 1 to 1 1/2 & 100   & 50    & 28    & 45    & 321   & C35 \\ \hline
    \end{tabular}
  \label{tab:addlabel}
\end{sidewaystable}
Thank you for your help
Last edited by cirasj on Mon Jun 06, 2011 12:43 pm, edited 2 times in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Centering Text in Tables - Could not find answer

Post by frabjous »

In the future, please always provide a complete minimal working example -- it is no fun trying to guess what is needed and what isn't to make your sample work. You'd also discover errors in your code, such as the missing end braces near where you have "Brinell" and "Rockwell".

It's a pain to do over and over, but it should work to do:

Code: Select all

    \begin{tabular}{>{\centering}p{.56in}
                    |>{\centering}p{1.0in}
                    |>{\centering}p{.75in}
                    |>{\centering}p{.875in}
                    |>{\centering}p{.875in}
                    |>{\centering}p{.75in}
                    |>{\centering}p{.625in}
                    |>{\centering\arraybackslash}p{.625in}}
Or at least I can't see any reason why that shouldn't work, if the array package is loaded anyway. You might have other options with other packages, but it's not clear from your snippet what your requirements and packages are.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Centering Text in Tables - Could not find answer

Post by localghost »

cirasj wrote:[…] There seems to have been some discussion in the past about it. […]
And you could have found the answer by doing a search in the forum.

Thorsten
cirasj
Posts: 25
Joined: Mon Mar 09, 2009 3:26 pm

Re: Centering Text in Tables - Could not find answer

Post by cirasj »

Thank you.
Post Reply