3

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} 
3
\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} 
  • 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

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.