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.

Is it possible to automatically adjust the size table cells according to their content, or to make the size of all cells uniform ?

This is an example:

\begin{table}[t]
\center
\footnotesize
\caption{resultsss}
\label{labss}
\begin{tabular}{ c c }

\begin{tabular}{ | c || c | c | c | c | } \hline
\multicolumn{4}{|c|}{\textbf{a text over here a text over here}} \\ \hline
\textit{Method 1} & 19923 & 123 & 123 \\ \hline
\textit{Method 2} & 1203 & 123 & 123 \\ \hline
\end{tabular}

&

\begin{tabular}{ | c || c | c | c | c | } \hline
\multicolumn{5}{|c|}{\textbf{another text over here}} \\ \hline
\textit{Method 1} & 789 & 789 & 789 & 789 \\ \hline
\textit{Method 2} & 789 & 789 & 789 & 789 \\ \hline
\end{tabular}


\end{tabular}
\end{table}
share|improve this question
3  
Please always post complete documemts not just fragments. –  David Carlisle Jul 10 '12 at 15:23
add comment

2 Answers 2

If \multicolumn span is wider than the columns it spans then all the extra width goes into the last spanned column. This is a feature of the underlying \halign primitive. One solution is to make the intercolumn space wider but shrinkable so that the default sum of the column widths is always greater then the span width. this looks better though if you don't have vertical lines.

enter image description here

I also corrected the \center to \centering and added a necessary preamble.

\documentclass{article}

\begin{document}

\begin{table}[t]
\centering
\footnotesize
\caption{resultsss}
\label{labss}
\begin{tabular}{ c c }

\begin{tabular*}{.5\textwidth}{ @{\extracolsep{\textwidth minus \textwidth}}| c || c | c | c |@{} } \hline
\multicolumn{4}{@{}|c|@{}}{\textbf{a text over here a text over here}}\\ \hline
\textit{Method 1} & 19923 & 123 & 123 \\ \hline
\textit{Method 2} & 1203 & 123 & 123 \\ \hline
\end{tabular*}

&

\begin{tabular}{ | c || c | c | c | c | } \hline
\multicolumn{5}{|c|}{\textbf{another text over here}} \\ \hline
\textit{Method 1} & 789 & 789 & 789 & 789 \\ \hline
\textit{Method 2} & 789 & 789 & 789 & 789 \\ \hline
\end{tabular}


\end{tabular}
\end{table}


\end{document}
share|improve this answer
add comment

I'm not entirely sure what you mean by your question whether it's possible to "make the size of all cells uniform": Do you want the column widths to be uniform within a group of columns of a given table, or do you want all columns to be equally wide across all columns of both tables?

In the example below I'm assuming that you want the former. As a result of using two tabularx environments, the first columns of the two tables are equally wide, the three data columns of the first table have equal widths, and the four data columns of the second table have equal width. I hope this is what you're looking for.

\documentclass{article}
\usepackage{tabularx}
\begin{document}
\begin{table}[t]
\footnotesize % Also possible: \small
\caption{Results}
\label{labss}
\begin{tabularx}{0.48\textwidth}{| l || *{3}{>{\centering\arraybackslash}X|}} \hline
\multicolumn{4}{|c|}{\textbf{a text over here a text over here}} \\  \hline
\textit{Method 1} & 19923 & 123 & 123 \\  \hline
\textit{Method 2} & 1203 & 123 & 123 \\  \hline
\end{tabularx}
\hspace*{\fill} % spread the two tables as far apart as is possible
\begin{tabularx}{0.48\textwidth}{| l || *{4}{>{\centering\arraybackslash}X|}} \hline
\multicolumn{5}{|c|}{\textbf{another text over here}} \\ \hline
\textit{Method 1} & 789 & 789 & 789 & 789 \\ \hline
\textit{Method 2} & 789 & 789 & 789 & 789 \\ \hline
\end{tabularx}
\end{table}
\end{document}

enter image description here

share|improve this answer
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.