Graphics, Figures & Tableswrap text in table

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
Julien
Posts: 5
Joined: Sun Aug 02, 2009 12:31 pm

wrap text in table

Post by Julien »

Hi everyone!

I'm trying to create table whose 2nd a 3rd columns have text in it. Therefore, if I don't want the text to go in the margin I specified p{3cm} twice in the option of my tabular.

However this doesn't produce the output I want. I've been looking on website and all give the solution with p{} but it however doesn't work for me for a reason I've no clue about.

Here is the table I'm trying to compile:

Code: Select all

\begin{tabular}{l|p{3cm}p{3cm}}

{\bf Simulation} & {\bf Advantage} & {\bf Drawback} \\
\hline
{\bf Monte Carlo } & Accurate for all instruments & Computationally intensive and time-consuming \\

           & Provide a full distribution of potential portfolio values & Quantifies fat-tailed risk only if market scenarios are generated from the appropriate distribution \\

           & Permit use of various distributional assumption and therefore has potential to address the issue of fat tails &            \\

           & No need for extensive historical data &            \\
\hline
{\bf Historical} & Accurate for all instruments & Requires a significant amount of daily rate history \\

           & Provide a full distribution of potential portfolio values & Difficult to scale far into the future \\

           & No need to make distributional assumption & Coarse at high confidence levels \\

           & Faster than Monte Carlo simulation because less scenarios are used & Somewhat computationally intensive and time-consuming \\

           &            & Incorporate tail risk only if historical data set includes tail events \\

\end{tabular}
And attached is the output I get.

Would really appreciate if you can tell me what I'm doing incorrectly!

Thanks a lot!

Julien
Attachments
problem table.pdf
(11.75 KiB) Downloaded 298 times

Recommended reading 2024:

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

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

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

wrap text in table

Post by localghost »

After completing your code to a [urlhttp://www.latex-einfuehrung.de/mini-en.html]minimal working example[/url] (MWE), I got no problems with the right output. See the attachment.

Code: Select all

\documentclass{article}

\begin{document}
\begin{tabular}{l|p{3cm}p{3cm}}
  \textbf{Simulation} & \textbf{Advantage} & \textbf{Drawback}\\ \hline
  \textbf {Monte Carlo} & Accurate for all instruments & Computationally intensive and time-consuming \\
  & Provide a full distribution of potential portfolio values & Quantifies fat-tailed risk only if market scenarios are generated from the appropriate distribution \\
  & Permit use of various distributional assumption and therefore has potential to address the issue of fat tails & \\
  & No need for extensive historical data & \\ \hline
 \textbf{Historical} & Accurate for all instruments & Requires a significant amount of daily rate history \\
  & Provide a full distribution of potential portfolio values & Difficult to scale far into the future \\
  & No need to make distributional assumption & Coarse at high confidence levels \\
  & Faster than Monte Carlo simulation because less scenarios are used & Somewhat computationally intensive and time-consuming \\
  & & Incorporate tail risk only if historical data set includes tail events \\
\end{tabular}
\end{document}
Check the log file for any occurring warnings or errors. Provide a MWE that generates the output seen in the file you attached to your request.


Best regards
Thorsten
Attachments
table-prblm.pdf
Obtained output from the provided code.
(19.52 KiB) Downloaded 327 times
Julien
Posts: 5
Joined: Sun Aug 02, 2009 12:31 pm

wrap text in table

Post by Julien »

Hi Thorsten,

Many thanks for your help.

This is quite misleading to me. I tried removing all the package I use and the output was looking much better. I guess then it's a problem with one of those.

Here is the code I run (MWE) to generate the table that have the problem I had before:

Code: Select all

\documentclass[a4paper,english,12pt]{article}
\usepackage[T1]{fontenc}
\usepackage{abstract}
\usepackage{bbm} 
\usepackage{amsmath, amsthm, amssymb}
\usepackage{fancyhdr} 
\usepackage[english]{babel}
\usepackage{enumerate}
\usepackage{rotating}
\usepackage{color}
\usepackage{graphicx}
\usepackage{array}
\usepackage{pdfsync}
\usepackage{ifpdf}\DeclareGraphicsExtensions{.eps,.bmp}
\usepackage{colortbl}
\usepackage{multirow}
\usepackage{setspace}
\usepackage{hyperref}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}

\begin{tabular}{l|p{3cm}p{3cm}}

{\bf Simulation} & {\bf Advantage} & {\bf Drawback} \\
\hline
{\bf Monte Carlo } & Accurate for all instruments & Computationally intensive and time-consuming \\

           & Provide a full distribution of potential portfolio values & Quantifies fat-tailed risk only if market scenarios are generated from the appropriate distribution \\

           & Permit use of various distributional assumption and therefore has potential to address the issue of fat tails &            \\

           & No need for extensive historical data &            \\
\hline
{\bf Historical} & Accurate for all instruments & Requires a significant amount of daily rate history \\

           & Provide a full distribution of potential portfolio values & Difficult to scale far into the future \\

           & No need to make distributional assumption & Coarse at high confidence levels \\

           & Faster than Monte Carlo simulation because less scenarios are used & Somewhat computationally intensive and time-consuming \\

           &            & Incorporate tail risk only if historical data set includes tail events \\

\end{tabular}

\end{document}
Thanks a lot again!

Julien
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

wrap text in table

Post by localghost »

The problem is caused by the pdfsync package. If you don't really need it, omit it unless you use a PDf viewer that supports this. Use only packages from which you know what they are for and what they do. I consider ifpdf in this case superfluous. And you don't really need the \DeclareGraphicsExtensions command. Use \textbf{...} instead of the obsolete \bf command.
Julien
Posts: 5
Joined: Sun Aug 02, 2009 12:31 pm

wrap text in table

Post by Julien »

Great it worked out! Thanks a lot!

If I may ask further:

I would like now to insert itemize or small into the a collumn.

I don't get any errors with itemize with the code below:

Code: Select all

\documentclass[a4paper,english,12pt]{article}
\usepackage[T1]{fontenc}
\usepackage{abstract}
\usepackage{bbm} 
\usepackage{amsmath, amsthm, amssymb}
\usepackage{fancyhdr} 
\usepackage[english]{babel}
\usepackage{enumerate}
\usepackage{rotating}
\usepackage{color}
\usepackage{graphicx}
\usepackage{array}
\usepackage{colortbl}
\usepackage{multirow}
\usepackage{setspace}
\usepackage{hyperref}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}

\begin{tabular}{l|p{5cm}p{5cm}}
\textbf{Simulation} & \textbf{Advantage} & \textbf{Drawback} \\
\hline
\textbf{Monte Carlo} & 
{\begin{itemize}
	\item Accurate for all instruments
	\item Provide a full distribution of potential portfolio values
	\item Permit use of various distributional assumption and therefore has potential to address the issue of fat tails
	\item No need for extensive historical data
\end{itemize}} &
{\begin{itemize}
	\item Computationally intensive and time-consuming
	\item Quantifies fat-tailed risk only if market scenarios are generated from the appropriate distribution 
\end{itemize}}\\
\hline
\textbf{Historical} &
{\begin{itemize}
	\item Accurate for all instruments
	\item Provide a full distribution of potential portfolio values
	\item No need to make distributional assumption Coarse at high confidence levels
	\item Faster than Monte Carlo simulation because less scenarios are used
\end{itemize}} &
{\begin{itemize} 
	\item Requires a significant amount of daily rate history
	\item Difficult to scale far into the future
	\item Somewhat computationally intensive and time-consuming
	\item Incorporate tail risk only if historical data set includes tail events
\end{itemize}}
\end{tabular}
\end{document}
The problem is that the environment creates a return before the first item and the last one resulting in a too big table such as the one I attached (problem table.pdf).

So instead of using \begin{itemize} I tried using \begin{small}:

Code: Select all

\documentclass[a4paper,english,12pt]{article}
\usepackage[T1]{fontenc}
\usepackage{abstract}
\usepackage{bbm} 
\usepackage{amsmath, amsthm, amssymb}
\usepackage{fancyhdr} 
\usepackage[english]{babel}
\usepackage{enumerate}
\usepackage{rotating}
\usepackage{color}
\usepackage{graphicx}
\usepackage{array}
\usepackage{colortbl}
\usepackage{multirow}
\usepackage{setspace}
\usepackage{hyperref}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}

\begin{tabular}{l|p{5cm}p{5cm}}
\textbf{Simulation} & \textbf{Advantage} & \textbf{Drawback} \\
\hline
\textbf{Monte Carlo} & 
{\begin{small}
	\item Accurate for all instruments
	\item Provide a full distribution of potential portfolio values
	\item Permit use of various distributional assumption and therefore has potential to address the issue of fat tails
	\item No need for extensive historical data
\end{small}} &
{\begin{small}
	\item Computationally intensive and time-consuming
	\item Quantifies fat-tailed risk only if market scenarios are generated from the appropriate distribution 
\end{small}}\\
\hline
\textbf{Historical} &
{\begin{small}
	\item Accurate for all instruments
	\item Provide a full distribution of potential portfolio values
	\item No need to make distributional assumption Coarse at high confidence levels
	\item Faster than Monte Carlo simulation because less scenarios are used
\end{small}} &
{\begin{small} 
	\item Requires a significant amount of daily rate history
	\item Difficult to scale far into the future
	\item Somewhat computationally intensive and time-consuming
	\item Incorporate tail risk only if historical data set includes tail events
\end{small}}
\end{tabular}
\end{document}
which gives me:
- smaller output which is what want.
- it still keeps the return before first which I'd like to remove.
- and I get errors when compiling such as: "Lonely \item--perhaps a missing list environement.

The output is provided in the problem table2.pdf attachement.

Would be nice if I can sort out this problem!

Thanks a lot again guys!

Julien
Attachments
problem table2.pdf
using small
(13.39 KiB) Downloaded 234 times
problem table.pdf
using itemize
(13.45 KiB) Downloaded 323 times
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

wrap text in table

Post by localghost »

List environments can be customized by using enumitem. Get familiar with the parameters that characterize a list. The manual shows some examples. The search function should also yield usable results concerning lists in tables.
Julien
Posts: 5
Joined: Sun Aug 02, 2009 12:31 pm

Re: wrap text in table

Post by Julien »

Worked fine with this package!

Thank you for your help.

Cheers,

Julien
Post Reply