0

I would like to know what is the best practice to do a table and a longtable in landscape mode over the full width of the page by resizing automatically my columns.

Indeed:

  1. I would like to use a table if I have a few rows

and

  1. when I have a lot of lines, I would like split correctly my table on two pages, for example.

Having evaluated several solutions, I have not obtained what I wished.

For example with the code above my table is split, i don't see the last column :

\documentclass[%
paper=A4,                   % paper size --> A4 is default in Germany
twoside=true,               % onesite or twoside printing
openright,                  % doublepage cleaning ends up right side
parskip=full,               % spacing value / method for paragraphs
chapterprefix=true,         % prefix for chapter marks
12pt,                       % font size
headings=normal,            % size of headings
bibliography=totoc,         % include bib in toc
listof=totoc,               % include listof entries in toc
titlepage=on,               % own page for each title page
captions=tableabove,        % display table captions above the float 
draft=false,                % value for draft version
]{scrbook}%

\begin{document}

\chapter{TEST}

\begin{landscape}
\begin{table}[!h]
\small  % Switch from 12pt to 11pt; otherwise, table won't fit
\setlength\LTleft{0pt}            % default: \parindent
\setlength\LTright{0pt}           % default: \fill
\begin{longtable}{@{\extracolsep{\fill}}c*{6}{c}}
\toprule
{\bfseries Column 1 Text Text Text} &  {\bfseries Column 2 Text} &  
{\bfseries 
Column 3 Text} &  {\bfseries Column 4} &  {\bfseries Column 5 Text} &  

{\bfseries Column 6Text Text} &  {\bfseries Column 7 Text Text}\\
\midrule
Text Text Text & Text Text& Text Text Text  Text Text Text& Text Text 
Text Text Text& Text & Text Text & Text \\
Text Text Text & Text Text& Text Text Text  Text Text Text& Text Text 
Text Text Text& Text & Text Text & Text \\
Text Text Text & Text Text& Text Text Text  Text Text Text& Text 
Text Text Text Text& Text & Text Text & Text \\
Text Text Text & Text Text& Text Text Text  Text Text Text& Text Text 
Text Text Text& Text & Text Text & Text \\
Text Text Text & Text Text& Text Text Text  Text Text Text& Text Text 
Text Text Text& Text & Text Text & Text \\
Text Text Text & Text Text& Text Text Text  Text Text Text& Text Text 
Text Text Text& Text & Text Text & Text \\
Text Text Text & Text Text& Text Text Text  Text Text Text& Text Text 
Text Text Text& Text & Text Text & Text \\
Text Text Text & Text Text& Text Text Text  Text Text Text& Text Text 
Text Text Text& Text & Text Text & Text \\
Text Text Text & Text Text& Text Text Text  Text Text Text& Text Text 
Text Text Text& Text & Text Text & Text \\
\bottomrule  
\end{longtable}
\caption{}
\label{table:chap2}
\end{table}        
\end{landscape}
\end{document}

And the result

And with lot of lines

enter image description here

Tof
  • 145
  • there isn't really a best practice in that generality, the question would be easier to answer if you showed some code and said what output you wished to get from it – David Carlisle Oct 12 '17 at 17:16
  • sorry, i have give an example – Tof Oct 12 '17 at 17:27
  • an example should start \documentclass and end \end{document} so that it demonstrates some issue. Your code fragment doesn't show any issue at all as for example we do not know the page size, so perhaps it fits? or you just need to save 2mm or 5cm of width? But anyway you can not use longtable inside a table environment use one or the other. – David Carlisle Oct 12 '17 at 18:40
  • the comment is wrong, the default value of \LTleft is not parindent. (You do not need to reset either of those lengths or add \extracolsep) – David Carlisle Oct 12 '17 at 18:42
  • i complete the example and i add a picture of the result. – Tof Oct 12 '17 at 21:00
  • once you remove the spurious table environment that table is just too wide because the headings are so much wider than the data and set on one line Column 6Text Text is so much wider then the data in that column, so the fix here is specific to this table (change that heading) and probably does not apply to your real document table. – David Carlisle Oct 12 '17 at 21:09
  • In fact, if I have many columns with very long header and few text. At this moment I have my longtable cutted. – Tof Oct 13 '17 at 06:17
  • if the text is too wide to fit on the page you need to change the text but that requires knowing what the real text is and knowing the subject matter. Usually column headings can be abbreviated or you can write them on more that one line eg replacewide heading by \begin{tabular}{@{}c@{}}wide\\heading\end{tabular} but there is no general rule it is editing the content of your document for that specific table. – David Carlisle Oct 13 '17 at 06:55
  • ok thanks you, but with @sayyidd25's solution that seems to be good (split my rows and add the header into the two pages), \begin{tabular} is not used, is there a solution in this case ? – Tof Oct 13 '17 at 09:27

1 Answers1

0

Using longtable

\documentclass[%
twoside=true,               % onesite or twoside printing
openright,                  % doublepage cleaning ends up right side
parskip=full,               % spacing value / method for paragraphs
chapterprefix=true,         % prefix for chapter marks
12pt,                       % font size
headings=normal,            % size of headings
bibliography=totoc,         % include bib in toc
listof=totoc,               % include listof entries in toc
titlepage=on,               % own page for each title page
captions=tableabove,        % display table captions above the float
draft=false,                % value for draft version
]{scrbook}%
%----------------------
\usepackage[top=2.5cm,bottom=2.5cm,left=2.5cm,right=2cm,headsep=15pt,footskip=27pt,a4paper]{geometry}
\usepackage{hyperref}
\usepackage{pdflscape}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{makecell}
\renewcommand\theadfont{\bfseries}
%----------------------
\begin{document}

\chapter{TEST}
In table \ref{table:chap2}...

\begin{landscape}
\begin{longtable}{ccccccc}
  \caption{Caption for longtable}\label{table:chap2}\\
  \toprule
{\bfseries Column 1 Text} &  {\bfseries Column 2} & {\bfseries Column 3 Text Text} & {\bfseries Column 4 Text} &  {\bfseries Column 5} & {\bfseries Column 6} &  {\bfseries Column 7}\\
  \midrule
  \endfirsthead
  \toprule
{\bfseries Column 1 Text} &  {\bfseries Column 2} & {\bfseries Column 3 Text Text} & {\bfseries Column 4 Text} &  {\bfseries Column 5} & {\bfseries Column 6} &  {\bfseries Column 7}\\
  \midrule
  \endhead
  \bottomrule
  \endfoot
Text Text Text & Text Text& Text Text Text  Text Text Text& Text Text
Text Text Text& Text & Text Text & Text \\
Text Text Text & Text Text& Text Text Text  Text Text Text& Text Text
Text Text Text& Text & Text Text & Text \\
Text Text Text & Text Text& Text Text Text  Text Text Text& Text
Text Text Text Text& Text & Text Text & Text \\
Text Text Text & Text Text& Text Text Text  Text Text Text& Text Text
Text Text Text& Text & Text Text & Text \\
Text Text Text & Text Text& Text Text Text  Text Text Text& Text Text
Text Text Text& Text & Text Text & Text \\
Text Text Text & Text Text& Text Text Text  Text Text Text& Text Text
Text Text Text& Text & Text Text & Text \\
Text Text Text & Text Text& Text Text Text  Text Text Text& Text Text
Text Text Text& Text & Text Text & Text \\
Text Text Text & Text Text& Text Text Text  Text Text Text& Text Text
Text Text Text& Text & Text Text & Text \\
Text Text Text & Text Text& Text Text Text  Text Text Text& Text Text
Text Text Text& Text & Text Text & Text \\
Text Text Text & Text Text& Text Text Text  Text Text Text& Text Text
Text Text Text& Text & Text Text & Text \\
Text Text Text & Text Text& Text Text Text  Text Text Text& Text Text
Text Text Text& Text & Text Text & Text \\
Text Text Text & Text Text& Text Text Text  Text Text Text& Text
Text Text Text Text& Text & Text Text & Text \\
Text Text Text & Text Text& Text Text Text  Text Text Text& Text Text
Text Text Text& Text & Text Text & Text \\
Text Text Text & Text Text& Text Text Text  Text Text Text& Text Text
Text Text Text& Text & Text Text & Text \\
Text Text Text & Text Text& Text Text Text  Text Text Text& Text Text
Text Text Text& Text & Text Text & Text \\
Text Text Text & Text Text& Text Text Text  Text Text Text& Text Text
Text Text Text& Text & Text Text & Text \\
Text Text Text & Text Text& Text Text Text  Text Text Text& Text Text
Text Text Text& Text & Text Text & Text \\
Text Text Text & Text Text& Text Text Text  Text Text Text& Text Text
Text Text Text& Text & Text Text & Text \\
Text Text Text & Text Text& Text Text Text  Text Text Text& Text Text
Text Text Text& Text & Text Text & Text \\
Text Text Text & Text Text& Text Text Text  Text Text Text& Text Text
Text Text Text& Text & Text Text & Text \\
Text Text Text & Text Text& Text Text Text  Text Text Text& Text
Text Text Text Text& Text & Text Text & Text \\
Text Text Text & Text Text& Text Text Text  Text Text Text& Text Text
Text Text Text& Text & Text Text & Text \\
Text Text Text & Text Text& Text Text Text  Text Text Text& Text Text
Text Text Text& Text & Text Text & Text \\
Text Text Text & Text Text& Text Text Text  Text Text Text& Text Text
Text Text Text& Text & Text Text & Text \\
Text Text Text & Text Text& Text Text Text  Text Text Text& Text Text
Text Text Text& Text & Text Text & Text \\
Text Text Text & Text Text& Text Text Text  Text Text Text& Text Text
Text Text Text& Text & Text Text & Text \\
Text Text Text & Text Text& Text Text Text  Text Text Text& Text Text
Text Text Text& Text & Text Text & Text \\
Text Text Text & Text Text& Text Text Text  Text Text Text& Text Text
Text Text Text& Text & Text Text & Text \\
Text Text Text & Text Text& Text Text Text  Text Text Text& Text Text
Text Text Text& Text & Text Text & Text \\
Text Text Text & Text Text& Text Text Text  Text Text Text& Text
Text Text Text Text& Text & Text Text & Text \\
Text Text Text & Text Text& Text Text Text  Text Text Text& Text Text
Text Text Text& Text & Text Text & Text \\
Text Text Text & Text Text& Text Text Text  Text Text Text& Text Text
Text Text Text& Text & Text Text & Text \\
Text Text Text & Text Text& Text Text Text  Text Text Text& Text Text
Text Text Text& Text & Text Text & Text \\
Text Text Text & Text Text& Text Text Text  Text Text Text& Text Text
Text Text Text& Text & Text Text & Text \\
Text Text Text & Text Text& Text Text Text  Text Text Text& Text Text
Text Text Text& Text & Text Text & Text \\
\end{longtable}
\end{landscape}

\end{document}

Result

Result with longtable

sayyidd25
  • 166
  • Thanks you. This solution works fine when i have a lot of rows but i have always a problem if my column's header are too long, my last column is cutted for example like in the picture into my question. Do you know how I might to do ? – Tof Oct 13 '17 at 06:21