4

I would like to indent a tabular environment so that it is to the left than usual. This is because my table doesn't quite fit the page. (Don't worry that it is not the "right" thing to do; this is just an informal document.)

\documentclass[fontsize=11pt]{scrartcl}
\usepackage{amsmath,amssymb,amsfonts,amsthm,url,hyperref}

\begin{document}

\begin{tabular}{ | p{3cm} | p{3cm} | p{3cm} | p{2cm} | p{2cm} | p{2cm} | }
\hline
abcdabcd abcd & abcdabcd abcd & abcdabcd abcd & abcdabcd & abcdabcd & abcdabcd \\ \hline
abcdabcd & abcdabcd & abcdabcd & abcdabcd & abcdabcd & abcdabcd \\ \hline
abcdabcd & abcdabcd & abcdabcd & abcdabcd & abcdabcd & abcdabcd \\ \hline
\end{tabular}

\end{document}

You can see that the table overflows to the right of the document. So it would be nice to move the whole table a little to the left, so the two sides balance out.

I don't want to use \setlength{\parindent}, because that would set the indent globally. It doesn't make sense to use \indent or \noindent either, because that would only make it stay the same or move it to the right. How can I do it?

Dexter
  • 143

4 Answers4

3

You can apply a \hspace*{<length>} with a negative length value:

enter image description here

Notes:

  • The showframe package was used just to show the page margins. It is not needed in your actual use case.

Code:

\documentclass[fontsize=11pt]{scrartcl}
\usepackage{amsmath,amssymb,amsfonts,amsthm,url,hyperref}
\usepackage{showframe}

\begin{document} \hspace*{-2.0cm}% \begin{tabular}{ | p{3cm} | p{3cm} | p{3cm} | p{2cm} | p{2cm} | p{2cm} | } \hline abcdabcd abcd & abcdabcd abcd & abcdabcd abcd & abcdabcd & abcdabcd & abcdabcd \ \hline abcdabcd & abcdabcd & abcdabcd & abcdabcd & abcdabcd & abcdabcd \ \hline abcdabcd & abcdabcd & abcdabcd & abcdabcd & abcdabcd & abcdabcd \ \hline \end{tabular}

\end{document}

Peter Grill
  • 223,288
3

Use of adjustwidth from changepage package. Within an adjustwidth environment the left and right margins can be adjusted. The environment takes two required length arguments:

\begin{adjustwidth}{<leftmargin>}{<rightmargin>} ... \end{adjustwidth}

A positive length value will increase the relevant margin (shortening the text lines) while a negative length value will decrease the margin (lengthening text lines). An empty length argument means no change to the margin. At the end of the environment the margins revert to their original values

enter image description here

Code

\documentclass[fontsize=11pt]{scrartcl}
\usepackage{amsmath,amssymb,amsfonts,amsthm,url,hyperref}
\usepackage{changepage}
\usepackage[showframe]{geometry}
\begin{document}


\begin{adjustwidth}{0cm}{0cm}
\begin{tabular}{ | p{3cm} | p{3cm} | p{3cm} | p{2cm} | p{2cm} | p{2cm} | }
\hline
abcdabcd abcd & abcdabcd abcd & abcdabcd abcd & abcdabcd & abcdabcd & abcdabcd \\ \hline
abcdabcd & abcdabcd & abcdabcd & abcdabcd & abcdabcd & abcdabcd \\ \hline
abcdabcd & abcdabcd & abcdabcd & abcdabcd & abcdabcd & abcdabcd \\ \hline
\end{tabular}
\end{adjustwidth}

\bigskip

\begin{adjustwidth}{-1cm}{0cm}
\begin{tabular}{ | p{3cm} | p{3cm} | p{3cm} | p{2cm} | p{2cm} | p{2cm} | }
\hline
abcdabcd abcd & abcdabcd abcd & abcdabcd abcd & abcdabcd & abcdabcd & abcdabcd \\ \hline
abcdabcd & abcdabcd & abcdabcd & abcdabcd & abcdabcd & abcdabcd \\ \hline
abcdabcd & abcdabcd & abcdabcd & abcdabcd & abcdabcd & abcdabcd \\ \hline
\end{tabular}
\end{adjustwidth}

\bigskip

\begin{adjustwidth}{-2cm}{0cm}
\begin{tabular}{ | p{3cm} | p{3cm} | p{3cm} | p{2cm} | p{2cm} | p{2cm} | }
\hline
abcdabcd abcd & abcdabcd abcd & abcdabcd abcd & abcdabcd & abcdabcd & abcdabcd \\ \hline
abcdabcd & abcdabcd & abcdabcd & abcdabcd & abcdabcd & abcdabcd \\ \hline
abcdabcd & abcdabcd & abcdabcd & abcdabcd & abcdabcd & abcdabcd \\ \hline
\end{tabular}
\end{adjustwidth}

\end{document}
Jesse
  • 29,686
1

You can use a box:

\documentclass{scrartcl}
\usepackage{lipsum,showframe}

\begin{document}

\lipsum[1]

\noindent
\makebox[\textwidth][c]{%   %<-------------
\begin{tabular}{ | p{3cm} | p{3cm} | p{3cm} | p{2cm} | p{2cm} | p{2cm} | }
\hline
abcdabcd abcd & abcdabcd abcd & abcdabcd abcd & abcdabcd & abcdabcd & abcdabcd \\ \hline
abcdabcd & abcdabcd & abcdabcd & abcdabcd & abcdabcd & abcdabcd \\ \hline
abcdabcd & abcdabcd & abcdabcd & abcdabcd & abcdabcd & abcdabcd \\ \hline
\end{tabular}
}%                           %<------------

\end{document}

enter image description here

Or use goodies from adjustbox package:

\documentclass{scrartcl}
\usepackage{lipsum,showframe}
\usepackage{adjustbox}
\begin{document}

\lipsum[1]
\noindent
\begin{adjustbox}{center}
\begin{tabular}{ | p{3cm} | p{3cm} | p{3cm} | p{2cm} | p{2cm} | p{2cm} | }
\hline
abcdabcd abcd & abcdabcd abcd & abcdabcd abcd & abcdabcd & abcdabcd & abcdabcd \\ \hline
abcdabcd & abcdabcd & abcdabcd & abcdabcd & abcdabcd & abcdabcd \\ \hline
abcdabcd & abcdabcd & abcdabcd & abcdabcd & abcdabcd & abcdabcd \\ \hline
\end{tabular}
\end{adjustbox}

\end{document}

There are some more facilities provided by adjustbox package, which, can be found by executing texdoc adjustbox from terminal.

1

I am not entirely sure what you want since you say "It doesn't make sense to use \indent or \noindent either, because that would only make it stay the same or move it to the right."

If you just want to move the tablular environment to the left then the easiest way is probably to use kern:

\documentclass{article}
\usepackage[showframe]{geometry}
\begin{document}

\noindent
\kern-20mm
\begin{tabular}{lll}
  1&2&3 and this one is really really really really really really  really really really really  really really really really long
\end{tabular}

\end{document}

This produces:

enter image description here

  • Adding \kern-20mm before my tabular doesn't seem to have any effect. – Dexter Nov 21 '14 at 05:02
  • @Dexeter You also need the \noindent. This said, Peter Gill's suggestion of using \hspace* is probably the "official" way to do this using LaTeX -- and it also has the advantage of not needing the \noindent. –  Nov 21 '14 at 05:42
  • This did not work until I put it inside the table element just above the tabular command – Robin May 12 '21 at 15:48