3

I am trying to input a longtable in lscape mode, but what I am trying to do is to limit its size, from the bottom of the page all the way to the top where any text should be i.e. considering the header + header offset. If I input the following code:

\documentclass[12pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{lscape}
\usepackage{longtable}
\usepackage{fancyhdr}
\pagestyle{fancy}
\begin{document}
\section{Limiting a table to header + offset}
Here I am trying to limit the size of table, which should be from the bottom of the page (as it is the case now), to where any text would be i.e. all the way to the header + headeroffset.
\begin{landscape}
    \begin{longtable}[c]{
            p{0.125\hsize}
            p{0.125\hsize}
            p{0.125\hsize}
            p{0.125\hsize}
            p{0.125\hsize}
            p{0.125\hsize}
            p{0.125\hsize}
            p{0.125\hsize}}
        \caption{My caption}
        \label{my-label}\\
        \hline
        old IDs         & Score & Mass   & Old Gene Product                                            & signalP & exosomes & new IDs          & New Gene Product                                                            \\ \hline
        \endfirsthead
        %
        \multicolumn{8}{c}%
        {{\bfseries Table \thetable\ continued from previous page}} \\
        \hline
        old IDs         & Score & Mass   & Old Gene Product                                            & signalP & exosomes & new IDs          & New Gene Product                                                            \\ \hline
        \endhead
        %
        \hline
        \endfoot
        %
        \endlastfoot
        %
        LdBPKxxxxxx.1 & 5140  & 71509  & heat-shock protein hsp70, putative                          & no      & yes      & LdBPKxxxxxx & heat-shock protein hsp70, putative                                          \\
        LdBPKxxxxx.1 & 3987  & 94942  & elongation factor 2                                         & no      & yes      & LdBPK\_360006900 & elongation factor 2                                                         \\
        LdBPKxx.1 & 2463  & 77764  & thimet oligopeptidase, putative                             & no      & yes      & LdBPKxxxxx & thimet oligopeptidase, putative                                             \\
        LdBPKxxxxx.1 & 2039  & 87562  & Transitional endoplasmic reticulum ATPase, putative         & no      & yes      & LdBPKxxxxx & Transitional endoplasmic reticulum ATPase, putative                         \\
        LdBPKxxxxx.1 & 1917  & 46634  & enolase                                                     & no      & yes      & LdBPKxxxxx & enolase                                                                     \\ \hline
    \end{longtable}
\end{landscape}

\end{document}

We can see that my table spans over the header + the header offset. How can I limit the height of my table to not span over header + header offset?

In other words, I am trying to assign this distance (bottom of the page all the way to the limit header + header offset) to be my 100% and assign each column of my table a percentage value (making up to 100%) for its width.

I guess there's something to do with the argument I am passing to specify the width of the columns, because I guess\hsize does not consider the header and header offset I guess.

2 Answers 2

1

your table is too wide (see David Carlisle answer).

edit: try to modify your table with use of the package ltablex as follows:

\documentclass[12pt,a4paper]{article}
\usepackage[latin1]{inputenc}
%\usepackage{amsmath}
%\usepackage{amsfonts}
%\usepackage{amssymb}
%\usepackage{graphicx}
\usepackage{pdflscape}
\usepackage{array, ltablex} % <--- changed
\usepackage{fancyhdr}
\pagestyle{fancy}

\begin{document}
\section{Limiting a table to header + offset}
Here I am trying to limit the size of table, which should be from the bottom of the page (as it is the case now), to where any text would be i.e. all the way to the header + headeroffset.

\begin{landscape}
\small
    \begin{tabularx}{\linewidth}{@{}
            l
            c
            c
            >{\raggedright\arraybackslash}X% <--- changed
            c
            c
            l
            >{\raggedright\arraybackslash}X
                        @{}}
        \caption{My caption}
        \label{my-label}\\
        \hline
        old IDs         & Score & Mass   & Old Gene Product                                            & signalP & exosomes & new IDs          & New Gene Product                                                            \\ \hline
        \endfirsthead
        %
        \multicolumn{8}{c}%
        {{\bfseries Table \thetable\ continued from previous page}} \\
        \hline
        old IDs         & Score & Mass   & Old Gene Product                                            & signalP & exosomes & new IDs          & New Gene Product                                                            \\ \hline
        \endhead
        %
        \hline
        \endfoot
        %
        \endlastfoot
        %
        LdBPKxxxxxx.1 & 5140  & 71509  & heat-shock protein hsp70, putative                          & no      & yes      & LdBPKxxxxxx & heat-shock protein hsp70, putative                                          \\
        LdBPKxxxxx.1 & 3987  & 94942  & elongation factor 2                                         & no      & yes      & LdBPK\_360006900 & elongation factor 2                                                         \\
        LdBPKxx.1 & 2463  & 77764  & thimet oligopeptidase, putative                             & no      & yes      & LdBPKxxxxx & thimet oligopeptidase, putative                                             \\
        LdBPKxxxxx.1 & 2039  & 87562  & Transitional endoplasmic reticulum ATPase, putative         & no      & yes      & LdBPKxxxxx & Transitional endoplasmic reticulum ATPase, putative                         \\
        LdBPKxxxxx.1 & 1917  & 46634  & enolase                                                     & no      & yes      & LdBPKxxxxx & enolase                                                                     \\ \hline
    \end{tabularx}
\end{landscape}

enter image description here

the package ltablex integrate features of longtable and tabularx packages. with it you can use column type X, which is calculated from available table width.

2
  • Why did you use 0.15 in >{\raggedright\arraybackslash}p{0.15\hsize}? Is this empirical/ trial and error to fit the width? I have clarified my question above.
    – BCArg
    Commented Mar 22, 2018 at 9:25
  • @BCArg, by trial and experience. however, if you will use package ltablex (see edited answer), you can width of table determine exactly.
    – Zarko
    Commented Mar 22, 2018 at 9:43
1

You are forcing it to be too wide, so just make it narrower. All your columns are fixed width so the table is 8 times the width of a column and each column is \hsize/8+2\tabcolsep so your table is 16\tabcolsep so by default 96pt too wide.

6
  • Any idea of how I can modify the code to fit the table as described in the question?
    – BCArg
    Commented Mar 22, 2018 at 9:04
  • Where exactly shall I put this line of code? Anyway, it returns an error. I have clarified my question: I want the distance bottom:(header + header offset) to be my 100% and assign for each column width a percentage of this newly defined 100%
    – BCArg
    Commented Mar 22, 2018 at 9:24
  • @BCArg sorry typo, I meant use p{\dimexpr(\hsize-16\tabcolsep)/8\relax} for the columns. Commented Mar 22, 2018 at 9:37
  • @BCArg the problem is not related to the head/foot (\hsize already takes care of that) it is that you are not allowing for the padding space between the columns. Commented Mar 22, 2018 at 9:39
  • @ David Carlisle your code now works, thanks. However, I still want to adjust the width of each column based on its content (wider or narrower) without spanning over the header.
    – BCArg
    Commented Mar 22, 2018 at 9:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .