1

enter image description hereI am preparing an article having a table, for a Springer journal. I am using tabularx, multirow. My table code is attached. I am not able to bring the lines 'xxxxxxxxxx xxxxxxxxxxx xxxxxxxxxxxx' and 'yyyyyyy yyyyyyyyyyyyy yyyyyyyy yyyyyyyyy' into two lines, so the lines don't cross the page boundary. How to do that?

%\documentclass{svjour3}                     % onecolumn (standard format)
\documentclass[smallcondensed]{svjour3}     % onecolumn (ditto)
%\documentclass[smallextended]{svjour3}       % onecolumn (second format)
%\documentclass[twocolumn]{svjour3}          % twocolumn
%\documentclass[12pt]{report}
%\linespread{1.5}
\huge
%
%\smartqed  % flush right qed marks, e.g. at end of proof
%
%\usepackage[12pt]{extsizes}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{setspace}
\usepackage{spreadtab}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}

%\usepackage{mathtools}
\title{}
\author{}

\begin{document}
\begin{table}
\caption{vvvv vvvv vvv hjgksjd ldkfjlsad}
\label{tab:2} 

\begin{tabularx}{\textwidth}{ll p{1.5cm}p{1.5cm}p{1.5cm}p{1.5cm} }
\toprule
size & Type & \multicolumn{2}{c}{xxxxxxxxxx xxxxxxxxxxx xxxxxxxxxxxx} & \multicolumn{2}{c}{yyyyyyy yyyyyyyyyyyyy yyyyyyyy yyyyyyyyy} \\
\cmidrule(lr){3-4} \cmidrule(ll){5-6}
& & XYZ & P-XYZ & XYZ & P-XYZ \\
\midrule
100 & A &  \\
    & B &  \\
    & C &  \\
    & Ds &  \\\addlinespace
200 & A &  \\
    & B & \\
    & C & \\
    & Ds & \\\addlinespace
300 & A & \\
    & B &\\
    & C &\\
    & Ds &  \\\addlinespace
400 & A & \\
    & B &\\
    & C \\
    & Ds\\
\bottomrule
\end{tabularx}
\end{table}

\maketitle
\tableofcontents

\begin{abstract}
\end{abstract}

\section{}

\end{document}
2

1 Answer 1

3

See, if the following MWE can help you:

\documentclass[12pt]{report}

\usepackage{graphicx}
\usepackage{setspace}
\usepackage{spreadtab}
\usepackage{booktabs,makecell,multirow,tabularx}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}

\begin{document}
    \begin{table}
\caption{vvvv vvvv vvv hjgksjd ldkfjlsad}
\label{tab:2}

\begin{tabularx}{\textwidth}{ll *{4}{X} }
\toprule
size & Type & \multicolumn{2}{c}{\thead{xxxxxxxxxx\\ xxxxxxxxxxx xxxxxxxxxxxx}} & \multicolumn{2}{c}{\thead{yyyyyyy yyyyyyyyyyyyy\\ yyyyyyyy yyyyyyyyy}} \\
\cmidrule(lr){3-4} \cmidrule(ll){5-6}
& & XYZ & P-XYZ & XYZ & P-XYZ \\
\midrule
100 & A &  \\
    & B &  \\
    & C &  \\
    & Ds &  \\\addlinespace
200 & A &  \\
    & B & \\
    & C & \\
    & Ds & \\\addlinespace
300 & A & \\
    & B &\\
    & C &\\
    & Ds &  \\\addlinespace
400 & A & \\
    & B &\\
    & C \\
    & Ds\\
\bottomrule
\end{tabularx}
\end{table}
    \end{document}

This MWE gives

enter image description here

For multi line cells is used macro thead from makecells package. It fonts can be customized by \renewcommand\theadfont{...} and vertical align with options \thead[t]{...} for top align or \thead[b]{...} for bottom align. Lines in it had to be broken manulally.

In code I replace your p{...} with X from tabularx package. They also can be customized for example as

\newcolumntype{C}{>{\centering\arraybackslash}X}

for horizontal centering of cells content. Similarly you can defined with raggedright or raggedleft the let and right align of cell's content.

2
  • It works perfectly. Thank You. What is \thead? May 26, 2016 at 11:31
  • If you liked answer, you can vote it :-). For thead see edits of answer.
    – Zarko
    May 26, 2016 at 12:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .