-1

I have 4 columns with long text in each column. The text overflows to next column if tried below code: enter image description here]1

\documentclass{article}

\usepackage{longtable}
\usepackage{multirow}

\title{A longtable example}

\begin{document}

\begin{center}
\begin{longtable}{p{2.8cm} p{2.8cm}p{2.8cm}p{2.8cm}}
\caption{A sample long table.} \label{tab:long} \\

\hline \multicolumn{1}{c}{\textbf{First column}} & \multicolumn{1}{c}{\textbf{Second column}} & \multicolumn{1}{c}{\textbf{Third column}}& 
\multicolumn{1}{c}{\textbf{TForth column}}\\ \hline 
\endfirsthead

\multirow{4}{c}%
{{\bfseries \tablename\ \thetable{} -- continued from previous page}} \\
\hline \multicolumn{1}{c}{\textbf{Reference}} & \multicolumn{1}{c}{\textbf{techniqued}} & \multicolumn{1}{c}{\textbf{issues}}
\multicolumn{1}{c}{\textbf{future}}\\ \hline 
\endhead

\hline \multicolumn{4}{r}{{Continued on next page}} \\ \hline
\endfoot

\hline \hline
\endlastfoot

\multirow{4}{*} textttttttttttttttttttttttt & abcdef ghjijklmn & 123.456778 & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 \\
\end{longtable}
\end{center}

\end{document}][1]][1]

I want to restrict long text to each specific column.

Case Msee
  • 229
  • 2
    Maybe unsurprisingly, LaTeX has not been programmed to "know" how to line-break the string textttttttttttttttttttttttt. In your opinion, how and where should this string be line-broken? Please advise. – Mico Feb 05 '20 at 12:32
  • 2
    Try replacing texttttttttttttttttttttttttttt with some real words that have spaces between them: you will find that LaTeX will keep everything within the space for that column in that case. If you need to tell LaTeX exactly where to break the line, then you can use \newline. – rbrignall Feb 05 '20 at 12:34
  • 2
    Off-topic but still relevant: A longtable environment should never, ever be encased in a center environment. – Mico Feb 05 '20 at 12:35
  • @mico: why not? If this is an important piece of information to help this user, perhaps explain why, or give a link to an explanation. This user came here for help. – rbrignall Feb 05 '20 at 12:37
  • 2
    @rbrignall because longtable does the centering of its contents itself and center gives inconsistent spacing above and below the longtable. – Skillmon Feb 05 '20 at 12:44
  • @rbrignall - The longtable environment centers its contents automatically. Encasing a longtable in a center environment achieves nothing except that it inserts unneeded and unwanted whitespace above and below the longtable material. Quite a few postings on this site make this point; see, for instance, my comment under the posting how to have a caption on top of longtable. – Mico Feb 05 '20 at 12:56
  • Don't tell me that, tell the questioner that! – rbrignall Feb 05 '20 at 13:05
  • @rbrignall - The OP gets to see all comments. Hopefully they'll have an effect. – Mico Feb 05 '20 at 13:55
  • Yes, I know the OP gets to see all comments. My point is that you should never, ever, tell someone what not to do without offering some kind of explanation (see https://tex.meta.stackexchange.com/questions/8467/empathy-for-those-who-dont-know-latex-well?cb=1). – rbrignall Feb 05 '20 at 14:14
  • @Mico @ rbrignall.... I think the question is not about centering a text in longtable. – Case Msee Feb 06 '20 at 03:35
  • @CaseMsee - I deliberately started my comment with the word "off-topic", as I was well aware that nesting center and longtable environments was not the main subject of your query. Unfortunately, that comment subsequently got hijacked and blown out of all proportion. Anyway, do please provide some information about how you believe the string textttttttttttttttttttttttt (or all other strings whose widths exceed the width of the cell) should be line-broken. – Mico Feb 06 '20 at 11:45

1 Answers1

0
  • Syntax of \multirow{4}{*} textttttttttttttttttttttttt is wrong. Missing are curly braces around textttttttttttttttttttttttt: \multirow{4}{*}{textttttttttttttttttttttttt}
  • If you like to have multirow cel has the same width as prescribed for columns where it is, than you you can exploit new options of multirow caption: \multirow{4}{=}{textttttttttttttttttttttttt}
  • real word on place of textttttttttttttttttttttttt is not natural word, which is consider in hyphenation rules, than you can insert hyphenation point manually. For example: text\-ttttt\-tttt\-tttttt\-ttt\-ttttt
  • It is not clear why you use \multirow cell. Its contents is only move below and overwrite rows below it.

Off-topic:

  • use of the \thead command from makecell package can simplify to write column headers
  • for numbers in the last two columns seems to be the use of the S column type defined in siunitx package more appropriate than p type.

Considering above, the resulted table is:

enter image description here

(red lines marked page layout)

\documentclass{article}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\usepackage{longtable, makecell}
\renewcommand\theadfont{\small\bfseries}
\usepackage{siunitx}

\title{A longtable example}

\begin{document}
    \begin{longtable}{ *{2}{p{2.8cm}} 
                       *{2}{S[table-format=3.6]}}
\caption{A sample long table.} 
\label{tab:long} \\
    \hline 
\thead{First\\ column}
    & \thead{Second\\ column}
                        & {\thead{Third\\ column}}
                                    & {\thead{Forth\\ column}}  \\
    \hline
\endfirsthead
\caption[]{A sample long table -- continued from previous page} \\ 
    \hline
\thead{First\\ column}
    & \thead{Second\\ column}
                        & {\thead{Third\\ column}}
                                    & {\thead{Forth\\ column}}  \\
    \hline
\endhead
    \hline 
    \multicolumn{4}{r}{\footnotesize\textit{Continued on next page}} \\ 
\endfoot
    \hline \hline
\endlastfoot

text\-ttttt\-tttt\-tttttt\-ttt\-ttttt
    & abcdef ghjijklmn & 123.456778 & 123.456778 \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
One & abcdef ghjijklmn & 123.456778 & \\
    \end{longtable}
\end{document}
Zarko
  • 296,517