Graphics, Figures & TablesAre embedded tabular the answer?

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
eidolon1977
Posts: 4
Joined: Sun Mar 31, 2013 5:22 pm

Are embedded tabular the answer?

Post by eidolon1977 »

Hi,

I've been struggling for some time trying to format a moderately complex table of numbers and I'm starting to wonder if embedding multiple tabular blocks was a good idea to start with...

At this point, I was trying to place the row headings for my data: "case 1", "case 2", etc, and it started looking very much like my approach was flawed.

You'll probably get a good idea of what I want just by looking at the compiled result. It's the vertical lines that should coincide (although the detached sub-tables under "First Order" and "Second Order" also look fine this way, after all...)

Here's my horrendous code :oops:

Code: Select all

\begin{table}[h]
\centering 
\caption{\label{tab_results_alpha+} Method results on the $\alpha_+$ branch}
\scriptsize{

\begin{tabular}{|c|c|c|}
\hline
& $\beta_+$ & $\beta_-$ \\          
&
	\begin{tabular}{|c|c|}
	\hline
	First Order & Second Order \\
	        \begin{tabular}{|c|c|c|}
                   \hline
                   n & nr & t \\
                   \hline
                   1 & 2 & 3 \\
                   \hline
                   4 & 5 & 6
                   \end{tabular}
           &
	        \begin{tabular}{|c|c|c|c|}
                   \hline
                   n & nr & nf & t \\
                   \hline
                   1 & 2 & 3 & 4 \\
                   \hline
                   5 & 6 & 7 & 8
                   \end{tabular}
	\end{tabular}
&
	\begin{tabular}{|c|c|c|}
	\hline
	First Order & Second Order \\
	        \begin{tabular}{|c|c|c|}
                   \hline
                   n & nr & t \\
                   \hline
                   1 & 2 & 3 \\
                   \hline
                   4 & 5 & 6
                   \end{tabular}
           &
	        \begin{tabular}{|c|c|c|c|}
                   \hline
                   n & nr & nf & t \\
                   \hline
                   1 & 2 & 3 & 4 \\
                   \hline
                   5 & 6 & 7 & 8
                   \end{tabular}
	\end{tabular} \\
\hline
\end{tabular}
}
\end{table}
I'm still fairly noob in LaTeX and any help would be greatly appreciated.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

tom
Posts: 73
Joined: Thu Apr 18, 2013 4:02 am

Are embedded tabular the answer?

Post by tom »

Try multicolumn instead.

Code: Select all

\documentclass[11pt]{article}
\begin{document}
\begin{table}[h]
\centering 
\caption{\label{tab_results_alpha+} Method results on the $\alpha_+$ branch}
\scriptsize{
\begin{tabular}{*{7}{c}|*{7}{c}}
	\hline
	\multicolumn{7}{c}{$\beta_+$} & \multicolumn{7}{c}{$\beta_-$} \\          
	\multicolumn{3}{c}{First Order} & \multicolumn{4}{c}{Second Order} & \multicolumn{3}{c}{First Order} & \multicolumn{4}{c}{Second Order} \\
	\hline      
	n & nr & t & n & nr & nf & t & n & nr & t  & n & nr & nf & t \\
	1 & 2 & 3 & 1 & 2 & 3 & 4 & 1 & 2 & 3 & 1 & 2 & 3 & 4 \\
	4 & 5 & 6 & 5 & 6 & 7 & 8 & 4 & 5 & 6 & 5 & 6 & 7 & 8\\
	\hline
\end{tabular}
}
\end{table}
\end{document}
eidolon1977
Posts: 4
Joined: Sun Mar 31, 2013 5:22 pm

Re: Are embedded tabular the answer?

Post by eidolon1977 »

It does the trick. I learnt something new about LaTeX today.

Cheers, mate!
Post Reply