0

I have a (horizontally) big table constructed with table, ThreePartTable and longtabu. I want it to fit in a single page. For that I am trying to increase margins with adjustwidth, then expanding the length of the table using 1.1\textwidth, see code example below.

However, all the adjustment seems to be applied to the right margin, thus for example {adjustwidth}{-1cm}{} yields the same output as adjustwidth{}{-1cm}. Similarly, {adjustwidth}{-1cm}{-1cm}, {adjustwidth}{-2cm}{} and {adjustwidth}{}{-2cm} all generate the same output, with all margin reduction done on the right of the page, so that the original left alignment of the table remains unchanged.

Bottom line is that I want to increase margins to allow the table to fit into one page, while keeping it centered in the page. Can anybody point out as to why the below code is not achieving this?

Code example:

\documentclass{article}

\usepackage{booktabs}
\usepackage{chngpage}
\usepackage{float}
\usepackage{longtable}
\usepackage{tabu}
\usepackage{threeparttablex}

\begin{document}

\begin{adjustwidth}{-1cm}{-1cm}
\begin{table}[H]
    \scriptsize
    \centering
    \begin{ThreePartTable}
    \begin{longtabu} to 1.1\textwidth
                    {X[0.5,C]
                     X[1.75,L] 
                     X[1.2,L]
                     X[1.175,L]
                     X[2.325,L] 
                     X[0.75,C]
                     X[0.9,C]}
    \rowfont[c]{\bfseries}
    Field1  
    & Field2
    & Field3
    & Field4
    & Field5
    & Field6\tnote{1} 
    & Field7\tnote{2,3} 
    \\
    \toprule
    \endhead
    \bottomrule
    \endfoot
    \bottomrule
    \\
    \endlastfoot

    Field1.Value1
    & Field2.Value1
    & Field3.Value1
    & Field4.Value1
    & Field5.Value1
    & Field6.Value1
    & Field7.Value1
    \\  

    [...]

    \bottomrule
    \end{longtabu}
        \begin{tablenotes}
        \item[1] FootNote1
        \item[2] FootNote2
        \item[3] Footnote3  
        \end{tablenotes}
    \end{ThreePartTable}
    \captionsetup{font=normal}
    \caption{Caption1}
    \label{tab:table_1}
\end{table}
\end{adjustwidth}

\end{document}
4
  • Please make sure your code include all packages used. If I just copy your code and add \documentclass{article} to the top, it fails to compile, due to missing \toprule and unknown float option H. For the former probably you are using something like booktab. Nov 19, 2019 at 18:15
  • Actually, I am using a corporate environment, so I cannot really display it in my code snippet. I believe it mimics the article class plus some additional formatting. My assumption is that it is not having any impact on this issue... I have added an article initialization to my question. I have also added booktabs as a package, I think that is the right one (lot of colleagues working on this doc and everyone adding their own packages so it can be difficult to identify all required packages...). Nov 19, 2019 at 18:23
  • Added also package float in case it is the one which enables the H option. Nov 19, 2019 at 18:24
  • You also need the caption package. Anyway, there are several problems here. First is that floats don't work with adjustwidth, second is that how adjustwidth works seems not to work well with the table environments you are using. Nov 19, 2019 at 18:38

3 Answers 3

1

\adjustwidth works inside the table environment. The adjustwidth environment changes the textblock/margins inside the environment but table is a float and moves outside the changed margins (without knowing about them). The following is a modification and extension of your MWE (but which had a problem for me with the longtabu), showing that adjustwidth inside table does work.

% adjustwidthprob2.tex  SE 517141 adjustwidth & tables

\documentclass{article}
\usepackage{lipsum}
\usepackage{booktabs}
\usepackage{chngpage}
\usepackage{float}
\usepackage{longtable}
\usepackage{tabu}
\usepackage{threeparttablex}

\begin{document}

\lipsum[1]

%\begin{adjustwidth}{-1cm}{-1cm}
\begin{table}[H]
\begin{adjustwidth}{-1cm}{-1cm}
    \scriptsize
    \centering
    \begin{ThreePartTable}
    \begin{longtabu} to 1.1\textwidth
                    {X[0.5,C]
                     X[1.75,L] 
                     X[1.2,L]
                     X[1.175,L]
                     X[2.325,L] 
                     X[0.75,C]
                     X[0.9,C]}
    \rowfont[c]{\bfseries}
    Field1  
    & Field2
    & Field3
    & Field4
    & Field5
    & Field6\tnote{1} 
    & Field7\tnote{2,3} 
    \\
    \toprule
    \endhead
    \bottomrule
    \endfoot
    \bottomrule
    \\
    \endlastfoot

    Field1.Value1
    & Field2.Value1
    & Field3.Value1
    & Field4.Value1
    & Field5.Value1
    & Field6.Value1
    & Field7.Value1
    \\  

    [...]

    \bottomrule
    \end{longtabu}
        \begin{tablenotes}
        \item[1] FootNote1
        \item[2] FootNote2
        \item[3] Footnote3  
        \end{tablenotes}
    \end{ThreePartTable}
    \captionsetup{font=normal}
    \caption{Caption1}
    \label{tab:table_1}
\end{adjustwidth}
\end{table}
%\end{adjustwidth}

\lipsum[2]

\begin{table}
\begin{adjustwidth}{-1cm}{-1cm}
\centering
Start of table. \lipsum[1]
\caption{An odd table}
\end{adjustwidth}
\end{table}

\end{document}
0

A workaround is to use the fullwidth package instead. Note also since the package changes the \textwidth, you should not set your table to have width 1.1\textwidth but just leave it at \textwidth so that it won't overflow further the widened box.

\documentclass{article}
\usepackage{showframe}

\usepackage{booktabs}
\usepackage{float}
\usepackage{fullwidth}
\usepackage{longtable}
\usepackage{tabu}
\usepackage{threeparttablex}
\usepackage{caption}

\begin{document}

\begin{fullwidth}[leftmargin=-2cm, rightmargin=-2cm, width=\linewidth+4cm]
\begin{table}[H]
    \scriptsize
    \begin{ThreePartTable}
    \begin{longtabu} to \textwidth
                    {X[0.5,C]
                     X[1.75,L] 
                     X[1.2,L]
                     X[1.175,L]
                     X[2.325,L] 
                     X[0.75,C]
                     X[0.9,C]}
    \rowfont[c]{\bfseries}
    Field1  
    & Field2
    & Field3
    & Field4
    & Field5
    & Field6\tnote{1} 
    & Field7\tnote{2,3} 
    \\
    \toprule
    \endhead
    \bottomrule
    \endfoot
    \bottomrule
    \\
    \endlastfoot

    Field1.Value1
    & Field2.Value1
    & Field3.Value1
    & Field4.Value1
    & Field5.Value1
    & Field6.Value1
    & Field7.Value1
    \\  

    \bottomrule
    \end{longtabu}
        \begin{tablenotes}
        \item[1] FootNote1
        \item[2] FootNote2
        \item[3] Footnote3  
        \end{tablenotes}
    \end{ThreePartTable}
    \captionsetup{font=normal}
    \caption{Caption1}
    \label{tab:table_1}

\end{table}
\end{fullwidth}

\end{document}

The output looks like (with frames shown)

enter image description here

0
  • if you like to have table on one page, then you do not need longtable (it should not be inside table environment)
  • adjustwidth should be inside table float environment
  • I would not use tabu package. It is not maintained and regardless to some fixes after new version of article document class it is still buggy
  • sum of columns widths adjustment should be integer number (i.e. 7, -in MWE below I consider that all columns have equal width. This you can change for example width
>{\hsize=0.5\hsize}C

where you should obey rule that sum of columns widths adjustment should be integer number (i.e. 7, since you have 7 columns)

MWE:

\documentclass{article}
\usepackage{ragged2e}   % <---
\usepackage{booktabs, 
            tabularx,   % <---
            threeparttablex}
\newcolumntype{C}{>{\Centering\hspace{0pt}}X}   % <---
\newcolumntype{L}{>{\RaggedRight\hspace{0pt}}X} % <---
\newcolumntype{R}{>{\RaggedLeft\hspace{0pt}}X}  % <---
\usepackage[strict]{chngpage}   % <---
\usepackage{caption}            % <---

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

\begin{document}
    \lipsum[66]
\begin{table}[ht]
    \scriptsize
    \centering
\begin{adjustwidth}{-1cm}{-3cm}
    \begin{ThreePartTable}
    \begin{tabularx}{\linewidth}{@{} C LLLL CC @{}}
    \toprule
\textbf{Field1} & \textbf{Field2}   & \textbf{Field3}   & \textbf{Field4}   & \textbf{Field5} 
                & \textbf{Field}\tnote{1}               & \textbf{Field7}\tnote{2,3}    \\
    \midrule
Field1.Value1
    & Field2.Value1
    & Field3.Value1
    & Field4.Value1
    & Field5.Value1
    & Field6.Value1
    & Field7.Value1 \\
    \bottomrule
    \end{tabularx}
        \begin{tablenotes}[flushleft,para]\footnotesize
        \item[1] FootNote1
        \item[2] FootNote2
        \item[3] Footnote3
        \end{tablenotes}
    \end{ThreePartTable}
    \captionsetup{font=normal}
    \caption{Caption1}
    \label{tab:table_1}
\end{adjustwidth}
\end{table}

\lipsum[67]
\end{document}

enter image description here

(red lines indicate page layout)

1
  • @Bernard, than you for edit!
    – Zarko
    Nov 19, 2019 at 19:20

You must log in to answer this question.

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