Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Centering a table wider than the text column

Tags:

center

latex

I'm including a table in my LaTeX document and the centering works fine if the table isn't wider than the text column above it, but when the table is wider, the left side of the table sticks to the left side of the text column, and the additional width of the table is on the right side of the page, how can I center the table?

like image 446
Zequj Avatar asked Apr 06 '09 18:04

Zequj


People also ask

How do you center a table that is too wide in latex?

Put your table into \centerline{} . The table will extend evenly into both margins if it's wider than \textwidth . This works great as long as there is no new lines between centerline and the table.

What command is used to align the table at the center?

We can use the shorthand property margin and set it to auto for aligning the table at the center rather than using the margin-left and margin-right property. Instead of aligning the table to center, the text-align: center; property only centers the table content, such as the text inside the table.

How do you scale a table in latex?

You can resize it using \resizebox{<width>}{<height>} from the graphics package. The column width is \columnwidth and you can select ! for the height to make it scale along with the width. Should the table include verbatim or similar material than \resizebox isn't good enough.

How do you make a table bigger in latex?

Use p{width} column specifier: e.g. \begin{tabular}{ l p{10cm} } will put column's content into 10cm-wide parbox, and the text will be properly broken to several lines, like in normal paragraph. You can also use tabular* environment to specify width for the entire table.


5 Answers

I'd recommend trying the chngpage package.

\documentclass{article}

% allows for temporary adjustment of side margins
\usepackage{chngpage}

% provides filler text
\usepackage{lipsum}

% just makes the table prettier (see \toprule, \bottomrule, etc. commands below)
\usepackage{booktabs}

\begin{document}

\lipsum[1]% just a paragraph of filler text

\medskip% adds some space before the table
\begin{adjustwidth}{-1in}{-1in}% adjust the L and R margins by 1 inch
  \begin{tabular}{ll}
    \toprule
    Sequence & Wide column \\
    \midrule
    First & Vestibulum porta ultricies felis. In nec mi. \\
    Second & Nam vestibulum auctor nibh. In eleifend, 
    lacus id tristique ullamcorper, mauris urna convallis elit. \\
    Third & Ut luctus nisi quam lobortis magna. Aenean sit amet odio 
   et sapien rutrum lobortis. \\ 
    Fourth & Integer dictum accumsan purus. Nullam erat ligula,
    dictum sed, feugiat nec, faucibus id, ipsum. \\
    \bottomrule
  \end{tabular}
\end{adjustwidth}
\medskip% adds some space after the table

\noindent\lipsum[2]% just a paragraph of filler text

\end{document}

The documentation for the chngpage package is located at the bottom of the chngpage.sty file. I've pulled out the docs for the adjustwidth environment:

Within an adjustwidth environment the left and right margins can be adjusted. The environment takes one optional argument and two required length arguments:

\begin{adjustwidth}[]{leftmargin}{rightmargin}

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.

For example, to extend the text into the right margin:

\begin{adjustwidth}{}{-8em}

Any appearance of the optional argument (even just []) will cause the values of the margins to switch between odd and even pages.

If the document is being set twosided it might be advantageous to have any wider text extending into the outside margin. This could be done via the optional argument, as:

\begin{adjustwidth}[]{}{-8em}

To have the adjusted text horizontally centered with respect to any surrounding text, the margins should be adjusted equally:

\begin{adjustwidth}{-4em}{-4em}

like image 88
godbyk Avatar answered Oct 27 '22 04:10

godbyk


Latex: Centering table larger than textwidth

Usually, you can center tables with \center. But when the table is longer than the \textwidth, it will be align with the left side margin. You can temporarily adjust the textwidth.

% allows for temporary adjustment of side margins
\usepackage{chngpage}

\begin{table}
    \begin{adjustwidth}{-.5in}{-.5in}  
        \begin{center}
        \begin{tabular}{|c|}
            \hline
And here comes a very long line. And here comes a very long line. And here comes a very long line.  \\
            \hline
        \end{tabular} 

        \caption{This Table is longer than the text width. And its caption is really long, too. This Table is longer than the text width. And its caption is really long, too. This Table is longer than the text width. And its caption is really long, too. This Table is longer than the text width. }
        \label{myTable}
        \end{center}
    \end{adjustwidth}
\end{table}
like image 36
user835611 Avatar answered Oct 27 '22 05:10

user835611


If you're using a \table float, the \begin{adjustwidth} ... \end{adjustwidth} has to be contained inside it.

like image 39
db. Avatar answered Oct 27 '22 04:10

db.


In figures, the figure environment must contain the adjustwidth env.. Furthermore, caption should be left outside of this environment to align with the overall figure's width:

\begin{figure}[h]
  \begin{adjustwidth}{-1in}{-1in}% adjust the L and R margins by 1 inch
    \centering
    \includegraphics[scale=0.44]{res/sth.png}
  \end{adjustwidth}
  \caption{sth}
  \label{fig:sth}
\end{figure}
like image 34
juanmirocks Avatar answered Oct 27 '22 05:10

juanmirocks


Are you using a multi-column document? I so, consider the table* variant environment.

In a single column environment your options run to:

  • Increase the textwidth. But the default margin were choosen for good ergonomic reasons, so this is to be discouraged beyond a minimal tweaking.
  • Reduce the text size in the table (i.e. \small or even \footnotesize inside the tabular environment). Again, this is less than optimal.
  • Use the rotating package as suggested in the link Stephan202 gave. I used this for a couple of very large tables in my dissertation (with only the p positioning options) and it came out very nicely.
like image 35
dmckee --- ex-moderator kitten Avatar answered Oct 27 '22 04:10

dmckee --- ex-moderator kitten