0

I want my tabularx table to span (almost) the full page in width instead of just textwidth. Here's an image of it currently (with \usepackage{showframe}: enter image description here I want the width of the table to be that of the outer right box in the image, but applied on both sides (so it leaves a little bit of white space on both sides). Anybody know how I could do this? Here's the code:

\documentclass[a4paper,12pt]{article}

\usepackage[margin=1.in]{geometry}
\usepackage{fancyhdr}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{ltablex}
\usepackage{siunitx}[input-decimal-markers=.]
\usepackage{lipsum}
\usepackage{threeparttable}
\usepackage{showframe}
\usepackage[sort, numbers, compress]{natbib}
\usepackage{amsmath}
\usepackage{makebox}
\usepackage[font=scriptsize,labelfont=bf,labelsep=period]{caption}
\usepackage[export]{adjustbox}
\usepackage[hidelinks]{hyperref}

\begin{document}

\renewcommand{\arraystretch}{2} 
    \begin{tiny}
    \begin{tabularx}{\linewidth}{@{}XXXXXX@{}}
        \caption{a table}\\
        \toprule
        \multicolumn{1}{l}{1}&\multicolumn{1}{l}{2}&\multicolumn{1}{c}{3 }&\multicolumn{1}{c}{4 }&\multicolumn{1}{c}{5}&\multicolumn{1}{c}{6} \\
        \midrule
        \textbf{text123 test test test test test test test}&textasddsa&textasdasd&textas sada &textasd asd adas das&test 123 test 123 test 123 test 123 test 123 tesrt 123 test 123 test 123\\
        \\

        \bottomrule
    \end{tabularx}
    \end{tiny}

\end{document}
user21398
  • 189

1 Answers1

1

to make table wider as textwidth you have two options:

  • increase text width locally. for example with use of adjustwidth macro
  • turn the pages with table into landscape orientation

the mwe below consider both those options:

\documentclass[a4paper,12pt]{article}

\usepackage[margin=1 in]{geometry}
\usepackage{ragged2e}
\usepackage{booktabs, ltablex, makecell}
\keepXColumns
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\setcellgapes{3pt}
\renewcommand\theadfont{\small\bfseries}
\renewcommand\theadgape{}
\usepackage[strict]{changepage}

\usepackage{pdflscape}

%---------------- 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{adjustwidth}{}{-\dimexpr\marginparsep+\marginparwidth}
    \footnotesize
    \makegapedcells
    \setlength\tabcolsep{3pt}
\begin{tabularx}{\linewidth}{@{}>{\bfseries}*{6}{L}@{}}
    \caption{A wide table}\\
    \toprule
\thead{1}   & \thead{2} & \thead{3} & \thead{4} & \thead{5} & \thead{6} \\
    \midrule
\endfirsthead
    \caption*{Table~\thetable: A wide table \hfill(cont.)}\\
    \toprule
\thead{1}   & \thead{2} & \thead{3} & \thead{4} & \thead{5} & \thead{6} \\
    \midrule
\endhead
    \multicolumn{6}{r}{continue on the next page}
\endfoot
    \bottomrule
\endlastfoot
% table body
text123 test test test test test test test
    & textasddsa & textasdasd & textas sada & textasd asd adas das & test 123 test 123 test 123 test 123 test 123 tesrt 123 test 123 test 123                   \\
    \midrule
\lipsum*[66]    &   &   &   &   &   \\
    \midrule
\lipsum*[66]    &   &   &   &   &   \\
\end{tabularx}
\end{adjustwidth}
\lipsum[66]

second option: table in landscape orientation

    \begin{landscape}
    \footnotesize
    \makegapedcells
    \setlength\tabcolsep{3pt}
\begin{tabularx}{\linewidth}{@{}>{\bfseries}*{6}{L}@{}}
    \caption{A wide table}\\
    \toprule
\thead{1}   & \thead{2} & \thead{3} & \thead{4} & \thead{5} & \thead{6} \\
\endfirsthead
    \caption*{Table~\thetable: A wide table \hfill(cont.)}\\
    \toprule
\thead{1}   & \thead{2} & \thead{3} & \thead{4} & \thead{5} & \thead{6} \\
    \midrule
\endhead
    \multicolumn{6}{r}{continue on the next page}
\endfoot
    \bottomrule
\endlastfoot
% table body
\lipsum*[66]    &   &   &   &   &   \\
    \midrule
\lipsum*[66]    &   &   &   &   &   \\
    \midrule
\lipsum*[66]    &   &   &   &   &   \\
\end{tabularx}
    \end{landscape}
\end{document}

if in some columns are cells with short, one line text, than is sensible for this columns use column type l.

Zarko
  • 296,517
  • Thanks for respond. Your first example did not work for me. It only extends it to the right and not the left. I might consider your landscape mode option though if there's no other solution. – user21398 Feb 19 '19 at 00:32
  • personally ii thing that is not good idea to extend table to binding side of document, however if you like that extend to left side too, just add amount of this extension, for example for 0.5 in: \begin{adjustwidth}{-0.5in}{-\dimexpr\marginparsep+\marginparwidth} – Zarko Feb 19 '19 at 01:01