Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

My friends, in the following table, in the first row specifying the column names, I would like to move the "Nominal" and "Wholesale" to the next line (but of course in the same cell).

enter image description here

I would also like to center the contents of those two columns. Please suggest

\documentclass{article}
%\usepackage{showframe}% http://ctan.org/pkg/showframe
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\usepackage{array}% http://ctan.org/pkg/array
\usepackage{tabularx}% http://ctan.org/pkg/tabularx
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\usepackage{array}% http://ctan.org/pkg/array
\usepackage{tabularx}% http://ctan.org/pkg/tabularx
\usepackage{calc}
\begin{document}

% Table generated by Excel2LaTeX from sheet 'Sheet2'
\begin{table}[htbp]
  \noindent\hspace*{-1cm}\begin{tabularx}{\textwidth+2cm}{
>{\raggedleft\arraybackslash\advance\hsize1em}X
>{\raggedright\arraybackslash\advance\hsize1em }X
>{\raggedright\arraybackslash}X
>{\raggedright\arraybackslash\advance\hsize-1em }X
>{\raggedright\arraybackslash\advance\hsize-1em }X
}

\addlinespace
\toprule
\multicolumn{1}{c}{Country} & Price series selected & Retail/Wholesale & Real/Nominal &     Location \\
\midrule
Afghanistan & Bread & R     & R     & Kabul \\
\bottomrule
\end{tabularx}\hspace*{-1cm}%
\label{Selected food price series}%
\end{table}%
\end{document} 
share|improve this question
add comment

1 Answer

up vote 3 down vote accepted
\multicolumn{1}{c}{Country} & Price series selected &
   \centering Retail/\\Wholesale & 
  \centering Real/\\Nominal &     Location \\

enter image description here

or in full:

\documentclass{article}
%\usepackage{showframe}% http://ctan.org/pkg/showframe
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\usepackage{array}% http://ctan.org/pkg/array
\usepackage{tabularx}% http://ctan.org/pkg/tabularx
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\usepackage{array}% http://ctan.org/pkg/array
\usepackage{tabularx}% http://ctan.org/pkg/tabularx
\usepackage{calc}
\begin{document}

% Table generated by Excel2LaTeX from sheet 'Sheet2'
\begin{table}[htbp]
  \noindent\hspace*{-1cm}\begin{tabularx}{\textwidth+2cm}{
>{\raggedleft\advance\hsize1em}X
>{\raggedright\advance\hsize1em }X
>{\centering}X
>{\centering\advance\hsize-1em }X
>{\raggedright\arraybackslash\advance\hsize-1em }X
}

\addlinespace
\toprule
\centering Country & Price series selected & Retail/\\Wholesale &  Real/\\Nominal &     Location \\
\midrule
Afghanistan & Bread & R     & R     & Kabul \\
\bottomrule
\end{tabularx}\hspace*{-1cm}%
\label{Selected food price series}%
\end{table}%
\end{document} 
share|improve this answer
    
Carisle: Thanks. I would also like to center align the contents of columns 3 and 4 as well. The problem I face is that once I substitute center for the corresponding raggedright, the column contents (of columns 3 and 4) including the top row, slide downwards relative to others. Any idea why? –  Abhimanyu Arora May 20 '12 at 13:03
    
I suspect you used \center (the internal part of begin{center} rather than \centering the center environment adds vertical space, I'll add a doc to my answer –  David Carlisle May 20 '12 at 13:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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