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

Information and discussion about graphics, figures & tables in LaTeX documents.
meho_r
Posts: 823
Joined: Tue Aug 07, 2007 5:28 pm

How can I make a table like this?

Post by meho_r »

A little bit of experimenting and I got this (I still believe it's better to use new rows instead of \newline because with more rows you give LaTeX more options for better table breaking across pages):

Code: Select all

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

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

A & B\\

\hline

A1\newline
A2\newline 
A3\newline & 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\newline
%
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\newline
%
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\ B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}

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 »

Use \newline or paragraph breaks (blank lines or \par) instead of \\ to create linebreaks in a table.

So A1 \newline A2 \newline A3 etc.

(Ugh. Getting out-ninjaed a lot lately.)
meho_r
Posts: 823
Joined: Tue Aug 07, 2007 5:28 pm

How can I make a table like this?

Post by meho_r »

LOL, I believe we're even now ;)
niotio910
Posts: 12
Joined: Mon Aug 02, 2010 4:10 pm

Re: How can I make a table like this?

Post by niotio910 »

That does the trick! Thanks a lot!
meho_r
Posts: 823
Joined: Tue Aug 07, 2007 5:28 pm

Re: How can I make a table like this?

Post by meho_r »

Before localghost reminds you, I'll do it instead: edit your first post and mark the thread as solved, please.
Post Reply