Make text in table fit in page [closed] - latex

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 2 years ago.
Improve this question
I have a latex table that extends beyond the page like this
The latex code looks as follows
% Please add the following required packages to your document preamble:
% \usepackage{longtable}
% Note: It may be necessary to compile the document several times to get a multi-page table to line up properly
\begin{longtable}[c]{|l|l|l|}
\hline
Term & Explanation & Comment \\ \hline
\endfirsthead
%
\endhead
%
Product Owner & Otto \& Lene & \\ \hline
Lene & Team Manager & \\ \hline
Otto & Software Engineer & \\ \hline
Angular & Frontend javascript framework to build modern single page applications & \\ \hline
GFS Upload & \begin{tabular}[c]{#{}l#{}}GFS Upload is an internal system used by employees at to insert the extra financial statements that haven't been inserted automatically yet.\\ \\ While there are different financial information the different places want GFS upload sorts by having Chart Bookings and Account Bookings.\end{tabular} & \\ \hline
Chart Booking & Chart Booking is financial statements used to report to Nationalbanken. & \\ \hline
Account Booking & Account booking is used for internal account reporting. & \\ \hline
Cloud 2 & cloud service & \\ \hline
\end{longtable}
I would like the text to fit inside the page, automatically inserting linebreaks. How can I achieve this?

You can use a column of fixed width. You will have to find out yourself which width you'll need for your document, as this will depend from the exact page geometry you use and unfortunately you only provided a not-compilable code fragment and no minimal working example
\documentclass{article}
\usepackage{geometry}
\usepackage{longtable}
\begin{document}
% Please add the following required packages to your document preamble:
% \usepackage{longtable}
% Note: It may be necessary to compile the document several times to get a multi-page table to line up properly
\begin{longtable}[c]{|l|p{9.7cm}|l|}
\hline
Term & Explanation & Comment \\ \hline
\endfirsthead
%
\endhead
%
Product Owner & Otto \& Lene & \\ \hline
Lene & Team Manager & \\ \hline
Otto & Software Engineer & \\ \hline
Angular & Frontend javascript framework to build modern single page applications & \\ \hline
GFS Upload & GFS Upload is an internal system used by employees at to insert the extra financial statements that haven't been inserted automatically yet. While there are different financial information the different places want GFS upload sorts by having Chart Bookings and Account Bookings. & \\ \hline
Chart Booking & Chart Booking is financial statements used to report to Nationalbanken. & \\ \hline
Account Booking & Account booking is used for internal account reporting. & \\ \hline
Cloud 2 & cloud service & \\ \hline
\end{longtable}
\end{document}

Related

RMarkdown Knitr Won't Render LaTeX tabular table in pdf

I'm trying to format a table using latex notation in RMarkdown. My code is the following:
\begin{table}[h!]
\center
\begin{tabular}{l|c|c}
\hline
Model & Coefficient & \\
Predictors & Value $ p-value\\
\hline
Intercept & -1.716 & 0.022\\
Retire & 0.197 & 0.020\\
Age & -0.015 & 0.020\\
Health Status & 0.312 & <0.001\\
Income & 0.002 & 0.002\\
Years of Education & 0.114 & <0.001\\
Married & 0.579 & <0.001\\
Hispanic & -0.810 & <0.001\\
\hline
\end{tabular}
\end{table}
For some reason though, when I go to knit the document together, I get the following error:
You may need to add $ $ around a certain inline R expression `r ` in draft.Rmd (see the above hint). See https://github.com/rstudio/rmarkdown/issues/385 for more info.
Error: LaTeX failed to compile draft.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See draft.log for more info.
Execution halted
When I remove this chunk, it knits together fine (including other tables I have put together using this method) and I can't figure out what is going on with this code. Any help would be great!
Two problems:
you have one $ instead of a &
it is \centering or \begin{center}...\end{center}, but not \center (this kind of works only by accident)
Furthermore, I suggest you take a look at the siunitx package to get correct minus/< signs and proper alignment of the cells. Also the booktabs package might be worth a look to get a good looking table.
\documentclass{article}
\begin{document}
\begin{table}[h!]
\centering
\begin{tabular}{l|c|c}
\hline
Model & Coefficient & \\
Predictors & Value & p-value\\
\hline
Intercept & -1.716 & 0.022\\
Retire & 0.197 & 0.020\\
Age & -0.015 & 0.020\\
Health Status & 0.312 & <0.001\\
Income & 0.002 & 0.002\\
Years of Education & 0.114 & <0.001\\
Married & 0.579 & <0.001\\
Hispanic & -0.810 & <0.001\\
\hline
\end{tabular}
\end{table}
\end{document}

how to wrap the text inside the cell while using tabularx in latex? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 3 years ago.
Improve this question
\begin{tabularx}{\textwidth}{|c|X|X|c|}
\hline
S.no & \multicolumn{1}{|c|}{\textbf{headline}} & \multicolumn{1}{|c|}{\textbf{article\_link}} & \bf\Centering is\_sarcastic \\ \hline
1 &
man who said 'yes' to life found with mountain bike at bottom of gorge &
{https://local.theonion.com/man-who-said-yes-to-life-found-with-mountain-bike-at-bo-1819573183} &
1\\
\hline
2 &
tina fey is worried about what the internet is doing to society &
{https://www.huffingtonpost.com/entry/tina-fey-internet\_us\_5848252ce4b08c82e888ff80} &
0 \\
\hline
3 &
why a woman refuses to leave her husband who threatened to kill her &
{https://www.huffingtonpost.com/entry/pro-fighter-allegedly-abuses-wife\_n\_6072618.html} &
0 \\ \hline
\end{tabularx}
Don't write urls as text. There are packages like url or hyperref that provide a dedicated \url{} macro for them. This also saves you from manually escaping all special letters.
to enable more possible breaking points to squeeze them into your way to narrow column, try the xurl package
Never use two-letter font commands like \bf, they are deprecated
Have a look at https://inf.ethz.ch/personal/markusp/teaching/guides/guide-tables.pdf for some suggestions about professional looking tables. Main point: don't use vertical lines
\documentclass{article}
\usepackage{tabularx}
\usepackage{xurl}
\begin{document}
\begin{tabularx}{\textwidth}{|c|X|X|c|}
\hline
S.no & \textbf{headline} & \textbf{article\_link} & \textbf{is\_sarcastic} \\ \hline
1 &
man who said 'yes' to life found with mountain bike at bottom of gorge &
\url{https://local.theonion.com/man-who-said-yes-to-life-found-with-mountain-bike-at-bo-1819573183} &
1\\
\hline
2 &
tina fey is worried about what the internet is doing to society &
\url{https://www.huffingtonpost.com/entry/tina-fey-internet_us_5848252ce4b08c82e888ff80} &
0 \\
\hline
3 &
why a woman refuses to leave her husband who threatened to kill her &
\url{https://www.huffingtonpost.com/entry/pro-fighter-allegedly-abuses-wife_n_6072618.html} &
0 \\ \hline
\end{tabularx}
\end{document}

Making self-adjusting table in latex

I am trying to create self-adjusting table in latex. THis is going to be a big table so I need text to go to the next line if not enough space but I am not able to do this. I need to have 5 columns.
Below is the image of what I have managed but "description" is now going into the next cell. I'd appreciate if someone could tell me where I am going wrong. I have spent so much time on this
Code I am using,
\begin{table}[h]
\begin{tabularx}{\textwidth}{|l|X|X|X|X|}
\hline
Author & Clustering Technique & Dataset & Description & Industry\\
\hline
\citeauthor{shen2009study} & Quantiles & Customer and Transaction Department store & RFM; Customer Lifetime Value; Target Marketing; Data Mining
& Retail Store \\
\hline
\citeauthor{aggelis2005customer} & Quantiles & E-Banking Dataset & Data Mining; e-banking; RFM analysis & Banking\\
\hline
\end{tabularx}
\end{table}
EDIT: I also need it either to fit on one page or be able to continue in the next page.
Very belated answer...
To adjust the width of the column I have used p{.1\textwidth}, this is paragraph alignment with width of the column equal to 0.1 times the width of the text body (or other fraction of it).
For the table to continue in next page(s), if necessary, I have used the excellent environment longtable from the package with the same name.
\documentclass{article}
\usepackage{longtable,natbib}
\begin{document}
\begin{longtable}{|p{.1\textwidth}|p{.15\textwidth}|p{.25\textwidth}|p{.3\textwidth}|p{.15\textwidth}|}
%\caption[Short caption]{Full caption}\label{longt}\\
\hline
% content of first header
Author & Clustering Technique & Dataset & Description & Industry\\
\hline
\endfirsthead
% content of following headers if the table continues in other page(s)
Author & Clustering Technique & Dataset & Description & Industry\\
\hline
\endhead
% content of all footers
\hline
\endfoot
% content of last footer
\hline
\endlastfoot
\citeauthor{shen2009study} & Quantiles & Customer and Transaction Department store & RFM; Customer Lifetime Value; Target Marketing; Data Mining & Retail Store\\
\hline
\citeauthor{aggelis2005customer} & Quantiles & E-Banking Dataset & Data Mining; e-banking; RFM analysis & Banking\\
\end{longtable}
\end{document}
The output of the code above:
To avoid intruding into the next cell, you can help latex by suggesting possible hyphenation points for description
\documentclass{book}
\usepackage{tabularx}
\begin{document}
\begin{table}[h]
\begin{tabularx}{\textwidth}{|l|X|X|X|X|}
\hline
Author & Clustering Technique & Dataset & De\-scrip\-tion & Industry\\
\hline
xxx & Quantiles & Customer and Transaction Department store & RFM; Customer Lifetime Value; Target Marketing; Data Mining
& Retail Store \\
\hline
xxxxxx xxx xxxx xxxxxx xxx & Quantiles & E-Banking Dataset & Data Mining; e-banking; RFM analysis & Banking\\
\hline
\end{tabularx}
\end{table}
\end{document}
(if you need the table to allow page breaks, use the xltabular package instead)

Creating a Gantt Chart and to fit page correctly in Latex

At the moment I have made a Gantt Chart, but as you see from the image you cannot see it properly and looks messy. I have tried to tweak but have had no luck with it. If anyone can help me to make it look better please. This is my first attempt of trying to create a Gantt Chart. Also I have tried making it so that it shows both an active line to where we are currently in the process. Additionally if a task is less then week a way of showing this without making the Gantt Chart exceedingly long. Any suggestions?
http://imgur.com/a/TJqgl
\documentclass[final]{cmpreport}
\subsection{Gantt Chart \& Critical Path}
\begin{sideways}
\newganttchartelement{voidbar}{
voidbar/.style={
draw=black,
top color=black!25,
bottom color=black!23
}}
\begin{ganttchart}[x unit=0.27cm, vgrid, title label font=\footnotesize,
canvas/.style={draw=black, dotted}]{1}{44}
\gantttitlelist{1,...,22}{2} \\
%the elements, bars and milestones, are identified as elem0, elem1, etc
%elem1
\ganttbar{A.Project Assigned}{1}{2} \\ %elem0
\ganttbar{B. Create Plan}{1}{4} \\ %elem1
\ganttbar{C. Ambassador Requirements}{5}{6} \\ %elem2
\ganttbar{D. Recruit Ambassadors} {7}{8} \\
\ganttbar{E. Communicate with Ambassadors } {9}{10} \\
\ganttbar {F. Set Marketing Objectives} {11}{11} \\
\ganttbar {G. Design, publish \& evaluate survey} {11}{14} \\
\ganttbar {H. Design Marketing Comms} {15}{18} \\
\ganttbar {I. Execute Plan} {19}{24} \\
\ganttbar {J. Set Webpage Objectives} {25}{25} \\
\ganttbar {K. Website Research} {25}{26} \\
\ganttbar {L. Website Prototype} {27}{28} \\
\ganttbar {M. Approve design/develop} {28}{29} \\
\ganttbar {N. Test \& evaluate} {30}{30} \\
\ganttbar {O. Venue \& theme} {31}{34} \\
\ganttbar {P. Choose Catering \& Entertainment } {35}{36} \\
\ganttbar {Q. Final Presentation} {37}{37} \\
\ganttlink{elem0}{elem2}
\ganttlink{elem1}{elem2}
\ganttlink{elem2}{elem3}
\ganttlink{elem5}{elem6}
\ganttlink{elem8}{elem9}
\ganttlink{elem9}{elem10}
\ganttlink{elem9}{elem11}
\end{ganttchart}
\end{sideways}
I know it's a very old question but today I began learning about pgfgantt and I found that there is the expand chart option for ganttchart to resize the diagram. Example:
expand chart=1.2\textwidth
More info at the pgfgantt package documentation:
http://bay.uchicago.edu/CTAN/graphics/pgf/contrib/pgfgantt/pgfgantt.pdf

Length parbox LaTeX

I am trying to build a table on LaTeX with parbox. I have found how to do with parbox. However, the length between rows makes the text so pack. Do you know how to increase the length?
\documentclass{article}
\usepackage{multirow}
\begin{document}
{\raggedright
\vspace{3pt} \noindent
\begin{tabular}{|p{108pt}|p{223pt}|p{52pt}|}
\hline
\parbox{108pt}{\raggedright
Attribute
} & \parbox{223pt}{\raggedright
Description
} & \parbox{52pt}{\raggedright
Characteristic
} \\
\hline
\parbox{108pt}{\raggedright
Language
} & \parbox{223pt}{\raggedright
Programming language of the source code.
} & \parbox{52pt}{\raggedright \multirow{5}{*}{
Project
}} \\
\cline{1-3}
\parbox{108pt}{\raggedright
Team\_size
} & \parbox[70em]{223pt}{\raggedright
Number of active core team members during the last 3 months prior to creation.
} & \\
\cline{1-3}
\parbox[15em]{108pt}{\raggedright
Perc\_external\_contribs
} & \parbox{223pt}{\raggedright
Ratio of commits from external contributors over core team members in the last 3 months prior to creation of pull request.
} & \\
\cline{1-2}
\hline
\end{tabular}
\vspace{2pt}
\end{document}
Thank you for your help.
The tabular columns are already set using a paragraph specification, so there's no need to set each cell using a \parbox (of similar width) as well.
You might be interested in tabularx as it allows for a flexibly-width X-column:
\documentclass{article}
\usepackage{tabularx}% Loads the array package
\begin{document}
\noindent
\begin{tabularx}{\linewidth}{|>{\raggedright}p{108pt}|>{\raggedright}X|>{\raggedright\arraybackslash}p{62pt}|}
\hline
Attribute & Description & Characteristic \\
\hline
Language & Programming language of the source code. & Project \\
\hline
Team\_size & Number of active core team members during the last 3 months prior to creation. & \\
\hline
Perc\_external\_contribs & Ratio of commits from external contributors over core team
members in the last 3 months prior to creation of pull request. & \\
\hline
\end{tabularx}
\end{document}
If you wish to adjust the padding further, consider reading up on Column and row padding in tables.

Resources