I am trying to centre a table with a lot of content whose width is larger than the text width. The problem is that I am defining the table environment in the preamble so I can reuse it, and this seems to create a lot of issues.
\NewEnviron{reqtable}{
\table
\tabularx{1.3\textwidth}{cX}
\toprule
\BODY
\bottomrule
}[
\endtabularx
\endtable
]
I initialise my table with
\begin{reqtable}
item & item \\
\end{reqtable}
The reason I am using NewEnviron from the environ package is so that I can use rules from the booktabs package (see bottomrule not working in a self-made environment)
I have tried the following alterations to center the table.
- use
\centeringjust after\table-- no errors, doesn't center. - use
\adjustwidth[]{}{-8em}just after the\table(see https://stackoverflow.com/questions/722613/latex-centering-a-table-wider-than-the-text-column) -- produces error! File ended while scanning use of TX@get@body. - use
\begin{fullwidth}to wrap the\table-- produces error! LaTeX Error: Not in outer par mode.
What else can I try to centre my table?
Note: I am using a twoside layout, so margins are different on odd and even pages. This is why the \adjustwidth command appeals to me most, as it can handle varying margins.
Here is an MWE with tables on different pages wider than the textwidth that I am trying to center.
\documentclass[11pt,a4paper,twoside]{report}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{environ}
\usepackage{lipsum}
\NewEnviron{reqtable}{
\renewcommand{\arraystretch}{1.3}
\table
\tabularx{1.3\textwidth}{lX}
\toprule
\BODY
\bottomrule
}[
\endtabularx
\endtable
\renewcommand{\arraystretch}{1}
\vspace{10pt}
]
\begin{document}
\lipsum[1]
\begin{reqtable}
Some text & \lipsum[1] \\
\end{reqtable}
\lipsum[3]
% This table is on the second page which has different margins
\begin{reqtable}
Other text & \lipsum[1] \\
\end{reqtable}
\end{document}
