0

I'm trying to change the margin of a page containing a table so that the table start after 1cm from left and right. I found this solution but when I tried it, it only changes one side of the table. Does anyone know how to change it for both sides?!

Output

\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}
5
  • What do you mean with margin of the table? Your table leaks into the left margin, which is the consequence of \hspace*{-1cm}...
    – user31729
    Commented Jun 4, 2017 at 22:10
  • @ChristianHupfer I meant that the table has to start after 1cm from each side.
    – F 505
    Commented Jun 4, 2017 at 22:12
  • You should probably use a \newgeometry statement, with respective margin settings, but please note that that \newgeometry will ship a new page first
    – user31729
    Commented Jun 4, 2017 at 22:22
  • @Christian Hupfer: Why did you delete your answer, which is what I would have posted, had you not done it before?
    – Bernard
    Commented Jun 4, 2017 at 22:55
  • @Bernard: Because I think I have misunderstood the question -- I think that the O.P wants the page margins should be changed, not the shifting of the table inwards.
    – user31729
    Commented Jun 4, 2017 at 22:56

2 Answers 2

1

You need to increase the width of the table by the same amount 2cm by setting \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}

enter image description here

0

The adjustwidth environment, from changepage is done for that. In addition, I removed the white strips at top and bottom of the coloured row due to the padding around booktabs rules:

\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} 

enter image description here

You must log in to answer this question.

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