Graphics, Figures & TablesHow can I make a table like this?

Information and discussion about graphics, figures & tables in LaTeX documents.
niotio910
Posts: 12
Joined: Mon Aug 02, 2010 4:10 pm

How can I make a table like this?

Post by niotio910 »

Hi,

Please help me make a table which looks like this:

Code: Select all

 
 ______________________
|  A   |       B       |
|------|---------------|
| A1\n | B1 B1 B1 B1\  |
| A2\n | B1 B1 B1 B1\n | 
| A3\n | B2 B2 B2 B2\  |
|      | B2 B2 B2 B2\n |
|      | B3 B3 B3 B3   |
|      | ....          |


Requirements:
1. Must be automatically split whenever it's longer a page.
2. Text should start on top of both columns. Newlines in both columns don't affect each other. For example, This is wrong:

Code: Select all

 ______________________
|  A   |      B        |
|------|---------------|
| A1\n |               |   
| A2\n |               | 
| A3\n |               |
|      | B1 B1 B1 B1\  |
|      | B1 B1 B1 B1\n | 
|      | B2 B2 B2 B2\  |
|      | B2 B2 B2 B2\n |
|      | B3 B3 B3 B3   |
|      | ....          |

In the following code, I used tabular inside longtable. It solved newlines problem, but didn't auto split with long table.

Code: Select all

\documentclass[a4paper]{report}
\usepackage{longtable}
\begin{document}
{\centering
\begin{longtable}{|p{3cm}|p{3cm}|}
\hline
\begin{tabular}[t]{p{3cm}}
A
\end{tabular}
&\begin{tabular}[t]{p{3cm}}
B
\end{tabular}

\tabularnewline
\hline
\begin{tabular}[t]{p{3cm}}
A1\\A2\\A3
\end{tabular}
&\begin{tabular}[t]{p{3cm}}
B1\ B1\ B1\ B1\\B2\ B2\ B2\ B2\ B2\ B2\\B3\ B3\ B3\ B3\ B3\ B3\ <lots of text...>
\end{tabular}
\tabularnewline
\hline
\end{longtable}
}
\end{document}

Thanks a lot!
Last edited by niotio910 on Tue Aug 03, 2010 5:16 pm, edited 2 times in total.

Recommended reading 2024:

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

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

frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Re: How can I make a table like this?

Post by frabjous »

We’re (or at least I’m) waiting for you to follow board rules, and provide a MWE and explain why it doesn’t work as-is.
niotio910
Posts: 12
Joined: Mon Aug 02, 2010 4:10 pm

How can I make a table like this?

Post by niotio910 »

frabjous wrote:We’re (or at least I’m) waiting for you to follow board rules, and provide a MWE and explain why it doesn’t work as-is.
Did I break some rules here?
niotio910
Posts: 12
Joined: Mon Aug 02, 2010 4:10 pm

How can I make a table like this?

Post by niotio910 »

niotio910 wrote:
frabjous wrote:We’re (or at least I’m) waiting for you to follow board rules, and provide a MWE and explain why it doesn’t work as-is.
Did I break some rules here?
OK, I got it! I'll make some MWE...
Sorry for my first thread!
niotio910
Posts: 12
Joined: Mon Aug 02, 2010 4:10 pm

Re: How can I make a table like this?

Post by niotio910 »

Hi,

I put some code in the original post. Please help!
niotio910
Posts: 12
Joined: Mon Aug 02, 2010 4:10 pm

Re: How can I make a table like this?

Post by niotio910 »

no one :(
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Re: How can I make a table like this?

Post by frabjous »

You need to be more patient. I don't do a lot of forum-checking between 4AM and 9AM my time, and other people lead busy lives too, and everyone here is just an interested volunteer. Even right now I only have a few seconds. I’ll look at it again in an hour or two when I get a chance.

I’m a bit confused about what you want. Why is your code divided into a bunch of different tabular environments? I thought you just wanted one table.
niotio910
Posts: 12
Joined: Mon Aug 02, 2010 4:10 pm

How can I make a table like this?

Post by niotio910 »

frabjous wrote:You need to be more patient. I don't do a lot of forum-checking between 4AM and 9AM my time, and other people lead busy lives too, and everyone here is just an interested volunteer. Even right now I only have a few seconds. I’ll look at it again in an hour or two when I get a chance.

I’m a bit confused about what you want. Why is your code divided into a bunch of different tabular environments? I thought you just wanted one table.
Thanks for your reply!
If you look at my requirements. The first one (splitting table into pages) can be done easily with only longtable, but using only longtable doesn't fulfill the second requirement which is related to newlines in 2 columns (please look at the example). I've tried a lot of ways, and found that using longtable + tabular combination solves the second requirement but doesn't work with the first one :(
meho_r
Posts: 823
Joined: Tue Aug 07, 2007 5:28 pm

How can I make a table like this?

Post by meho_r »

Keep in mind the following:

1. The break across the pages comes after a row, not in the middle of it (no matter how large it is).

2. The command \\ means row break, so you cannot use it to break text in a cell. Rather create a new row (with an empty cell in the first column; take a look at lines 26–31 in the example code below).

3. Because of notice 1., you'll probably have to tweak the appearance manually from time to time.

Here's an example code to start with:

Code: Select all

\documentclass[a4paper]{report}
\usepackage{longtable}

\begin{document}
{\centering
\begin{longtable}{|p{3cm}|p{3cm}|}
\hline

A & B\\

\hline

A1\ A2\ A3 & B1\ B1\ B1\ B1 
B2\ B2\ B2\ B2\ B2\ B2\ B3\ B3\ B3\ B3\ B3\ B3\ 
B1\ B1\ B1\ B1\ B2\ B2\ B2\ B2\ B2\ B2\ B3\ B3\ B3\ B3\ B3\ B3\ 
B1\ B1\ B1\ B1\ B2\ B2\ B2\ B2\ B2\ B2\ B3\ B3\ B3\ B3\ B3\ B3\ 
B1\ B1\ B1\ B1\ B2\ B2\ B2\ B2\ B2\ B2\ B3\ B3\ B3\ B3\ B3\ B3\ 
B1\ B1\ B1\ B1\ B2\ B2\ B2\ B2\ B2\ B2\ B3\ B3\ B3\ B3\ B3\ B3\ 
B1\ B1\ B1\ B1\ B2\ B2\ B2\ B2\ B2\ B2\ B3\ B3\ B3\ B3\ B3\ B3\ 
B1\ B1\ B1\ B1\ B2\ B2\ B2\ B2\ B2\ B2\ B3\ B3\ B3\ B3\ B3\ B3\ 
B1\ B1\ B1\ B1\ B2\ B2\ B2\ B2\ B2\ B2\ B3\ B3\ B3\ B3\ B3\ 
END OF ROW 1\\

\hline

 & B1\ B1\ B1\\

\hline

 & B2\ B2\ B2\\
 & B3\ B3\ B3\\

\hline

 & B1\ B2\ B2\ B2\ B2\ B2\ B2\ B3\ B3\ B3\ B3\ B3\ B3\ 
B1\ B1\ B1\ B1\ B2\ B2\ B2\ B2\ B2\ B2\ B3\ B3\ B3\ B3\ B3\ B3\ 
B1\ B1\ B1\ B1\ B2\ B2\ B2\ B2\ B2\ B2\ B3\ B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\end{document}

niotio910
Posts: 12
Joined: Mon Aug 02, 2010 4:10 pm

How can I make a table like this?

Post by niotio910 »

Hi meho_r,

I want A1, A2, and A3 in different lines as well. Is there any possibility like this (notice A1, A2 and A3):

Code: Select all

\documentclass[a4paper]{report}
\usepackage{longtable}

\begin{document}
{\centering
\begin{longtable}{|p{3cm}|p{3cm}|}
\hline

A & B\\

\hline

A1\\ A2\\ A3 & B1\ B1\ B1\ B1
B2\ B2\ B2\ B2\ B2\ B2\ B3\ B3\ B3\ B3\ B3\ B3\
B1\ B1\ B1\ B1\ B2\ B2\ B2\ B2\ B2\ B2\ B3\ B3\ B3\ B3\ B3\ B3\
B1\ B1\ B1\ B1\ B2\ B2\ B2\ B2\ B2\ B2\ B3\ B3\ B3\ B3\ B3\ B3\
B1\ B1\ B1\ B1\ B2\ B2\ B2\ B2\ B2\ B2\ B3\ B3\ B3\ B3\ B3\ B3\
B1\ B1\ B1\ B1\ B2\ B2\ B2\ B2\ B2\ B2\ B3\ B3\ B3\ B3\ B3\ B3\
B1\ B1\ B1\ B1\ B2\ B2\ B2\ B2\ B2\ B2\ B3\ B3\ B3\ B3\ B3\ B3\
B1\ B1\ B1\ B1\ B2\ B2\ B2\ B2\ B2\ B2\ B3\ B3\ B3\ B3\ B3\ B3\
B1\ B1\ B1\ B1\ B2\ B2\ B2\ B2\ B2\ B2\ B3\ B3\ B3\ B3\ B3\
END OF ROW 1\\

\hline

& B1\ B1\ B1\\

\hline

& B2\ B2\ B2\\
& B3\ B3\ B3\\

\hline

& B1\ B2\ B2\ B2\ B2\ B2\ B2\ B3\ B3\ B3\ B3\ B3\ B3\
B1\ B1\ B1\ B1\ B2\ B2\ B2\ B2\ B2\ B2\ B3\ B3\ B3\ B3\ B3\ B3\
B1\ B1\ B1\ B1\ B2\ B2\ B2\ B2\ B2\ B2\ B3\ B3\ B3\ B3\ B3\ B3\
B1\ B1\ B1\ B1\ B2\ B2\ B2\ B2\ B2\ B2\ B3\ B3\ B3\ B3\ B3\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