Since you're bound to the column width of .5 cm, I'd suggest abbreviating your header texts adding some footnotes at the end of the table.
\documentclass{ifacconf}
\usepackage{graphicx} % include this line if your document contains figures
\usepackage{natbib} % required for bibliography
% The following packages can be found on http:\\www.ctan.org
%\usepackage{graphicx} % for pdf, bitmapped graphics files
\usepackage{epsfig} % for postscript graphics files
\usepackage{mathptmx} % assumes new font selection scheme installed
\usepackage{times} % assumes new font selection scheme installed
\usepackage{amsmath} % assumes amsmath package installed
\usepackage{amssymb} % assumes amsmath package installed
\usepackage{multirow}
\usepackage{epstopdf}
%\usepackage{cite}
\usepackage{subfigure}
\usepackage{color}
\usepackage{enumerate}
\DeclareMathOperator*{\argmax}{arg\,max}
\usepackage{tabularx,ragged2e,booktabs}
\usepackage[T1]{fontenc}
\usepackage{multirow}
\usepackage{array}
\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}
\renewcommand\tabularxcolumn[1]{C{#1}}
\begin{document}
\begin{table}[t]
\centering\caption{Details\label{10_PKPD}}% put label near caption
\begin{tabular}{|C{0.5cm}|C{0.5cm}|C{0.5cm}|C{0.5cm}|}
% after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
\hline
No.& A & H & W\\\hline
11& 56& 160& 88 \\
\hline
\multicolumn{4}{@{}l@{}}{\footnotesize \begin{tabular}{@{}l@{}}
\rule{0pt}{9pt}A = Age [years]\\
H = Height [cm]\\
W = Weight [kg]\\
\end{tabular}}
\end{tabular}
\end{table}
\begin{table}[htb]
\centering\caption{A better layout\label{better}}% put label near caption
\begin{tabular}{C{0.5cm}C{0.5cm}C{0.5cm}C{0.5cm}}
% after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
\toprule
No.& A & H & W\\\midrule
11& 56& 160& 88 \\
\bottomrule
\multicolumn{4}{@{}l}{\footnotesize \begin{tabular}{@{}l@{}}
\rule{0pt}{9pt}A = Age [years]\\
H = Height [cm]\\
W = Weight [kg]\\
\end{tabular}}
\end{tabular}
\end{table}
\end{document}
you have many issues with your table:
ltablex
doesn't work well with \adjustwidth
. is your table really multi page long?
- use of
ltablex
preserve X
column tape only if cells' contents are wider than standard width of X
column, otherwise it shrink column width to width if you have l
column tape. a cure is add \keepXColumns
to document preamble
- regardless that you have contents only one column of table (and others empty), you need always to write all ampersands. adding missed ampersands fixed your mine problem (if you not use
ltablex
but simple tabularx
).
\adjustwidth
is not intended to change text width of more pages. for this is more appropriate to use \newgeometry
from geometry
package
consider above comments, the table can be written as:
\documentclass[a4paper, 12pt]{article}
\usepackage[margin=1.1in]{geometry}
\usepackage{booktabs,
makecell,
tabularx,
threeparttable}
\renewcommand\theadfont{\footnotesize\bfseries}
\renewcommand\theadgape{}
\newcommand\mcl[1]{\multicolumn{1}{l}{#1}}
\usepackage[strict]{changepage}
\usepackage[font=footnotesize,
labelfont=bf,
labelsep=space]{caption}
\captionsetup[table]{singlelinecheck=false,
justification=raggedright}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\begin{document}
\begin{table}[htb]
\begin{adjustwidth}{-1cm}{-1cm}
\footnotesize
\renewcommand{\arraystretch}{1.4}
\caption{caption}
\label{resultstable}
\begin{tabularx}{\linewidth}{>{\quad}l X X X X X }
\toprule
\thead[b]{variables}
& \thead[b]{1}
& \thead[b]{Cluster \\ 2 \\(n=111)}
& \thead[b]{3 \\(n=111)}
& \thead[b]{4\\()}
& \thead[b]{5\\()} \\
\midrule
\mcl{\textit{Very very very very Long variable name}}
& & & & \\
\mcl{var2} & & & & & \\
varx & 0.92 (0.13)
& 0.65 (0.26)
& 0.65 (0.19)
& 0.49 (0.23)
& 0.44 (0.23) \\
vary & 0.93 (0.12)
& 0.52 (0.28)
& 0.53 (0.21)
& 0.23 (0.22)
& 0.02 (0.07) \\
\mcl{varz} & & & & & \\
varu & & & & & \\
varrn & & & & & \\
varrqe & & & & & \\
\mcl{var)} & & & & & \\
\bottomrule
\end{tabularx}
\end{adjustwidth}
\end{table}
\end{document}
which gives:
if you make Very very very very Long variable name
shorter, for example with use of abrevation or with break it into two or more lines, than the use of \adjustwidth
wouldn't be necessary anymore. in this case use of ltablex
for this table will works as expected:
\documentclass[a4paper, 12pt]{article}
\usepackage[margin=1.1in]{geometry}
\usepackage{booktabs,
longtable,
ltablex,
makecell,
threeparttable}
\keepXColumns
\renewcommand\theadfont{\footnotesize\bfseries}
\renewcommand\theadgape{}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\newcommand\mcx[1]{\multicolumn{1}{@{}>{\hsize=1.75\hsize}X}{#1}}
\usepackage[strict]{changepage}
\usepackage[font=footnotesize,
labelfont=bf,
labelsep=space]{caption}
\captionsetup[table]{singlelinecheck=false,
justification=raggedright}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\begin{document}
\footnotesize
\renewcommand{\arraystretch}{1.4}
\begin{tabularx}{\linewidth}{@{}>{\quad\hsize=1.75\hsize}L
*{5}{>{\hsize=0.95\hsize}C}
@{}}
\caption{caption}
\label{resultstable} \\
\toprule
\thead[b]{variables}
& \thead[b]{1}
& \thead[b]{Cluster \\ 2 \\(n=111)}
& \thead[b]{3 \\(n=111)}
& \thead[b]{4\\()}
& \thead[b]{5\\()} \\
\midrule
\endfirsthead
\caption{caption (cont.)}
\label{resultstable} \\
\toprule
\thead[b]{variables}
& \thead[b]{1}
& \thead[b]{Cluster \\ 2 \\(n=111)}
& \thead[b]{3 \\(n=111)}
& \thead[b]{4\\()}
& \thead[b]{5\\()} \\
\midrule
\endhead
\midrule
\multicolumn{6}{r}{\textit{continue on the next page}}
\endfoot
\bottomrule
\endlastfoot
\mcx{\itshape
Very very very very Long variable name}
& & & & \\
\mcx{var2} & & & & & \\
varx & 0.92 (0.13)
& 0.65 (0.26)
& 0.65 (0.19)
& 0.49 (0.23)
& 0.44 (0.23) \\
vary & 0.93 (0.12)
& 0.52 (0.28)
& 0.53 (0.21)
& 0.23 (0.22)
& 0.02 (0.07) \\
\mcx{varz} & & & & & \\
varu & & & & & \\
varrn & & & & & \\
varrqe & & & & & \\
\mcx{var)} & & & & & \\
\end{tabularx}
\end{document}
addendum:
According to your comment below, (one of the possible) solutions is to add a one column to the table and to redesign the \mcx
command. i also suggest to ad more vertical space before row with \mcx
command (all changes are in code indicated by % <---
):
\documentclass[a4paper, 12pt]{article}
\usepackage[margin=1.1in]{geometry}
\usepackage{booktabs,
longtable,
ltablex,
makecell,
threeparttable}
\keepXColumns
\renewcommand\theadfont{\footnotesize\bfseries}
\renewcommand\theadgape{}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\usepackage[strict]{changepage}
\usepackage[font=footnotesize,
labelfont=bf,
labelsep=space,
skip=1ex]{caption}
\captionsetup[table]{singlelinecheck=false,
justification=raggedright}
\begin{document}
\begingroup % <---
\footnotesize\linespread{0.84}\selectfont % <---
\renewcommand{\arraystretch}{1.2} % <---
\setlength\tabcolsep{4pt} % <---
\newcommand\mcx[1]{\multicolumn{2}%
{@{}>{\hsize=\dimexpr1.75\hsize+2\tabcolsep}L}{#1}} % <---
\begin{tabularx}{\linewidth}{@{}
l % <---
>{\hsize=1.75\hsize}L
*{5}{>{\hsize=0.95\hsize}C}
@{}}
\caption{caption}
\label{resultstable} \\
\toprule
& \thead[bl]{variables}
& \thead[b]{1}
& \thead[b]{Cluster \\ 2 \\(n=111)}
& \thead[b]{3 \\(n=111)}
& \thead[b]{4\\()}
& \thead[b]{5\\()} \\
\midrule
\endfirsthead
\caption{caption (cont.)}
\label{resultstable} \\
\toprule
& \thead[bl]{variables}
& \thead[b]{1}
& \thead[b]{Cluster \\ 2 \\(n=111)}
& \thead[b]{3 \\(n=111)}
& \thead[b]{4\\()}
& \thead[b]{5\\()} \\
\midrule
\endhead
\midrule
\multicolumn{6}{r}{\textit{continue on the next page}}
\endfoot
\bottomrule
\endlastfoot
\mcx{some very long variable name without indented text}
& & & & \\
\addlinespace
\mcx{var2} & & & & & \\
& varx & 0.92 (0.13)
& 0.65 (0.26)
& 0.65 (0.19)
& 0.49 (0.23)
& 0.44 (0.23) \\
& vary & 0.93 (0.12)
& 0.52 (0.28)
& 0.53 (0.21)
& 0.23 (0.22)
& 0.02 (0.07) \\
\addlinespace
\mcx{varz} & & & & & \\
& varu & & & & & \\
& varrn & & & & & \\
& No. of product switches in 2 yr, median (IRQ)
& 0.93 (0.12)
& 0.52 (0.28)
& 0.53 (0.21)
& 0.23 (0.22)
& 0.02 (0.07) \\
& varx & 0.92 (0.13)
& 0.65 (0.26)
& 0.65 (0.19)
& 0.49 (0.23)
& 0.44 (0.23) \\
\addlinespace
\mcx{var)} & & & & & \\
\end{tabularx}
\endgroup % <---
\end{document}
(red lines indicate text borders)
Best Answer
In LaTeX terminology, a
table
is a "floating environment", meaning that it may get typeset not exactly where it's encountered in the input file but somewhere else (usually not too far away though) in order to obtain a decent page layout. The main content of atable
environment -- other content being, for instance, the table's caption, legend, and table-related footnotes -- is usually placed inside atabular
environment (if the tabular material is mostly text) or anarray
environment (if the material is mostly math).Left-alignment of the contents of a column is achieved by using the
l
column type, specified as an argument to\begin{tabular}
or\begin{array}
. To change the distance between columns, modify either\tabcolsep
(fortabular
environments) or\arraycolsep
(forarray
environments).In the case of your example, I would suggest you use an
array
environment, as it contains all mathy stuff.