更改包含表格的页面的边距

更改包含表格的页面的边距

我正在尝试更改包含表格的页面的边距,以便表格从左右各 1 厘米处开始。我发现此解决方案但是当我尝试时,它只改变了桌子的一侧。有人知道如何改变两边吗?!

输出

\documentclass{article}

\usepackage[margin=2.3cm]{geometry} %The margin for the whole document
\usepackage[hidelinks]{hyperref}

\usepackage{color, colortbl}
\usepackage{caption} 


\captionsetup[table]{skip=5pt}

\usepackage{enumitem, etoolbox, tabularx, makecell, booktabs}
\makeatletter
\newcommand*{\compress}{\@minipagetrue}
\makeatother



\begin{document}



You can find table \ref{table:Mytable} on page \pageref{table:Mytable}.


 \newpage


            \definecolor{Gray}{gray}{0.9}

               \begin{table}[!htbp]

                \caption{My table}
                \label{table:Mytable}


                {\renewcommand{\arraystretch}{3}
                \setlist[itemize]{wide=0pt, leftmargin=*, topsep=0pt, after=\vspace*{-\baselineskip}}
                \AtBeginEnvironment{itemize}{\compress}


                \hspace*{-1cm}\begin{tabularx}{\linewidth}{X *{3}{p{20mm}} p{18mm}p{42mm}}
                 \rowcolor{Gray}
                 \toprule
                 & \textbf{\thead{Column \\ 2}} & \textbf{\thead{Column \\ 3}} & \textbf{\thead{Column \\ 4}} & \textbf{\thead{Column \\ 5}} & \textbf{\thead{Column \\ 6}} \\
                 \midrule

                %Row1
               entry1 & \centering entry2 & \centering entry3 & \centering  entry4 & \centering entry5 & \begin{itemize} \item entry6.1 \item  entry6.2  \end{itemize}
                  \\


                 \bottomrule
                \end{tabularx}\hspace*{-1cm}}

                \end{table}



        \newpage


\end{document}

答案1

您需要2cm通过设置来增加表格的宽度相同的量\begin{tabularx}{\dimexpr\linewidth+2cm}

\documentclass{article}
\usepackage[margin=2.3cm]{geometry} %The margin for the whole document
\usepackage[hidelinks]{hyperref}
\usepackage{color, colortbl}
\usepackage{caption} 
\captionsetup[table]{skip=5pt}
\usepackage{enumitem, etoolbox, tabularx, makecell, booktabs}
\makeatletter
\newcommand*{\compress}{\@minipagetrue}
\makeatother

\begin{document}    
You can find table \ref{table:Mytable} on page \pageref{table:Mytable}.    
\newpage
\definecolor{Gray}{gray}{0.9}
               \begin{table}[!htbp]
                \caption{My table}
                \label{table:Mytable}
                {\renewcommand{\arraystretch}{3}
                \setlist[itemize]{wide=0pt, leftmargin=*, topsep=0pt, after=\vspace*{-\baselineskip}}
                \AtBeginEnvironment{itemize}{\compress}
                \hspace*{-1cm}\begin{tabularx}{\dimexpr\linewidth+2cm}{X *{3}{p{20mm}} p{18mm}p{42mm}}
                 \rowcolor{Gray}
                 \toprule
                 & \textbf{\thead{Column \\ 2}} & \textbf{\thead{Column \\ 3}} & \textbf{\thead{Column \\ 4}} & \textbf{\thead{Column \\ 5}} & \textbf{\thead{Column \\ 6}} \\
                 \midrule
                %Row1
               entry1 & \centering entry2 & \centering entry3 & \centering  entry4 & \centering entry5 & \begin{itemize} \item entry6.1 \item  entry6.2  \end{itemize}   \\
                 \bottomrule
                \end{tabularx}\hspace*{-1cm}}
                \end{table}
        \newpage

\end{document}

在此处输入图片描述

答案2

环境adjustwidth从此changepage完成。此外,由于 booktabs 规则周围的填充,我删除了彩色行顶部和底部的白色条纹:

\documentclass{article}

\usepackage[margin=2.3cm, showframe]{geometry} %The margin for the whole document
\usepackage[hidelinks]{hyperref}

\usepackage{color, colortbl}
\usepackage{caption}
\usepackage{changepage}
\captionsetup[table]{skip=5pt}

\usepackage{enumitem, etoolbox, tabularx, makecell, booktabs}
\makeatletter
\newcommand*{\compress}{\@minipagetrue}
\makeatother

\begin{document}

You can find table \ref{table:Mytable} on page \pageref{table:Mytable}.

 \newpage

            \definecolor{Gray}{gray}{0.9}

               \begin{table}[!htbp]

                \caption{My table}
                \label{table:Mytable}

               \renewcommand{\arraystretch}{3}
                \setlist[itemize]{wide=0pt, leftmargin=*, topsep=0pt, after=\vspace*{-\baselineskip}}
                \AtBeginEnvironment{itemize}{\compress}

        \begin{adjustwidth}{-1cm}{-1cm}
                \begin{tabularx}{\linewidth}{X *{3}{p{20mm}} p{18mm}p{42mm}}
                 \rowcolor{Gray}
                 \toprule\noalign{\vspace*{-\belowrulesep}}
                 & \textbf{\thead{Column \\ 2}} & \textbf{\thead{Column \\ 3}} & \textbf{\thead{Column \\ 4}} & \textbf{\thead{Column \\ 5}} & \textbf{\thead{Column \\ 6}} \\[-\aboverulesep]
                 \midrule

                %Row1
               entry1 & \centering entry2 & \centering entry3 & \centering entry4 & \centering entry5 & \begin{itemize} \item entry6.1 \item entry6.2 \end{itemize}
                  \\

                 \bottomrule
                \end{tabularx}\
        \end{adjustwidth}

                \end{table}

\end{document} 

在此处输入图片描述

相关内容