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)
Related
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}
I am making a journal paper with 2 columns. But I need table for the entire column. Using the below code table is pushed out of the comparatively analysis section into a new page.
\section{Comparatively Analysis}
\hfil\break
\begin{table*}
\centerline {TABLE 1}
\begin{center}
\begin{tabular} {|c|c|c|c|c|}
\hline
\multicolumn{5} { | c | }{Comparison Table}\\
\hline
Paper & Dataset & Approach & Model & Evaluation \\
\hline
Mary[7] & Air Pollution & Statistical & ST Correlation & RMSE 3.54 for 15\% missing data\\
\hline
Zhang[10] & Water Quality & Deep Learning & Seq2Seq & RMSE 3.29 \\
\hline
Turabieh[11] & Mammographic Mass, Hepatitis & Soft Computing & ANFIS-GA,ANFIS-PSO& Accuracy 85.2\% \\
\hline
Verma[12] & MIT-BIH ECG & Deep Learning & LSTM & 5-step RMSE 0.1 and 10-step RMSE 0.07 \\
\hline
Al-Milli[13] & Mammographic Mass & Deep Learning & Jordan RNN & Accuracy 84.27\% \\
\hline
\end{tabular}
\end{center}
\end{table*}
\hfil\break
\section{Conclusion}
Due to improper internet communications
TABLE OUT OF SECTION
NEW PAGE TABLE PUSHED
The main issue is that the table is too large. You have to use resizebox method from graphicx package. Here I provide a slightly better-looking table from the tabu package; this format is widely used in academia and in textbooks.
\usepackage{tabu, makecell, graphicx, booktabs}
%%Begin document (...)
\section{Comparatively}
\hfil\break
\begin{center}
\tabulinesep=1.6mm %%height between lines
\resizebox{1.1\columnwidth}{!}{ %% 1.1 is the scale factor of the column width
\begin{tabu}{ccccc}
\toprule
\toprule
\multicolumn{5}{c}{\ \ \ Comparison Table}\\
\multicolumn{1}{c}{\textit{Paper}}&\multicolumn{1}{c}
{\textit{Dataset}}&\multicolumn{1}{c}{\textit{Approach}}&\multicolumn{1}{c}
{Model}&\multicolumn{1}{c}{\textit{ Evaluation}}\\
\cmidrule(lr){1-1} \cmidrule(lr){2-2} \cmidrule(lr){3-3} \cmidrule(lr){4-4}
\cmidrule(lr){5-5}
Mary$[7]$ & Air Pollution & Statistical & ST Correlation & \makecell{RMSE $3.54$ for \\ $15\%$ missing data } \\
Zhang$[10]$ & Water Quality & Deep Learning & Seq$2$Seq & RMSE $3.29$ \\
Turabieh$[11]$ & \makecell{Mammographic mass \\ Hepatitis} & Soft Computing & \makecell{ANFIS-GA,\\ ANGIS-PSO} & Accuracy $85.2\%$ \\
\bottomrule
\bottomrule
\end{tabu}
}
\end{center}
{ \footnotesize\textbf{Table 1:} Table description }
\hfil\break
\section{Conclusion}
Due to improper internet communications
Change the `scale factor back to 1.0 if the table seems to overlap to much on the right side. If not keep it at 1.1 for better visibility.
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}
In my 2nd section I want to add two table. One table is in the right position, but the second table went to the next section. it was supposed to be in the previous section. How can I bring the second table in the right section?
Here is the code I used:
% table 3 begins
\begin{table}[h]
\centering
\caption{}
\label{my-label}
\begin{tabular}{cccc}
\hline
\textbf{Properties} & \textbf{Model 1} & \textbf{Model 2} & \textbf{Model 3} \\ \hline
\begin{tabular}[c]{#{}c#{}}Training\\ Window width\end{tabular} & 2 & 2 & 1 \\
\begin{tabular}[c]{#{}c#{}}Training\\ window step\end{tabular} & 1 & 1 & 1 \\
\begin{tabular}[c]{#{}c#{}}Test\\ window width\end{tabular} & 2 & 2 & 1 \\
Horizon & 5 & 10 & 15 \\
\begin{tabular}[c]{#{}c#{}}Cumulative\\ training\end{tabular} & No & No & No \\ \hline
\end{tabular}
\end{table}
\\
% table 4 begins
\begin{table}[!t]
\centering
\caption{}
\label{my-label}
\begin{tabular}{ccccc}
\hline
\textbf{Date} & \textbf{\begin{tabular}[c]{#{}c#{}}Actual Price\\ (USD)\end{tabular}} & \multicolumn{3}{c}{\textbf{Predicted Price}} \\ \hline
\textbf{} & \textbf{} & \textbf{Model 1} & \textbf{Model 1} & \textbf{Model 1} \\
13-01-15 & 89.30 & 89.44 & 87.90 & 91.71 \\
07-11-14 & 78.76 & 77.63 & 77.72 & 78.08 \\
29-07-14 & 75.44 & 75.00 & 76.43 & 77.59 \\
04-06-14 & 77.12 & 76.26 & 76.96 & 77.53 \\ \hline
\end{tabular}
\end{table}
In addition to Norman Gray:s answer, I might also add that there are several different methods to force your floats (tables/figures and so on) to stay within "their" sections.
One method would be to use the placeins package, as described in its documentation. From the documentation:
Placeins.sty keeps floats ‘in their place’, preventing them from
floating past a “\FloatBarrier” command into another section. To use
it, declare “\usepackage{placeins}” and insert “\FloatBarrier” at
places that floats should not move past, perhaps at every
“\section”.
...
If you specify “\usepackage[section]{placeins}”, then the “\section” command will be redefined with “\FloatBarrier” inserted at the beginning.
So in your case, try adding
\usepackage[section]{placeins}
in your document header.
It's not so much that LaTeX put the second table in the next section, but it put it on the next page that had room. LaTeX has a slightly intricate algorithm for working out how best to relocate tables and figures, but unfortunately its decisions can be rather ... unpredictable.
One solution is to accept that this is OK, and perhaps give the reader a clue by saying see table~\ref{my-label} on page~\pageref{my-label}, which helps the reader find the table. The varioref package can do this in a smarter way. I think, myself, that this is the best solution.
Another is to adjust the maximum fraction of a page that LaTeX will permit to have tables. A command like \renewcommand{\floatpagefraction}{0.75} will permit up to three quarters of the page to be floats – so only a quarter of the page text – before spilling on to a new page. This can quickly look ugly if the fraction is too large, however.
This is a very common problem, and searching online for ‘controlling latex floats’, or similar, should uncover lots of help. There should also be help on this topic elsewhere on Stackoverflow, or on the companion TeX site.
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.