49

我在我的 LaTeX 文档中包含了一个表格,如果表格不比其上方的文本列宽,则居中工作正常,但是当表格更宽时,表格的左侧粘在文本的左侧列,并且表格的附加宽度在页面的右侧,我怎样才能使表格居中?

4

5 回答 5

39

我建议尝试这个chngpage包。

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

包的文档chngpage位于chngpage.sty文件的底部。我已经提取了adjustwidth环境文档:

在 adjustwidth 环境中,可以调整左右边距。环境采用一个可选参数和两个必需的长度参数:

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

A positive length value will increase the relevant margin

(缩短文本行),而负长度值将减少边距(延长文本行)。一个空的长度参数意味着边距没有变化。在环境结束时,边距恢复为原始值。

例如,要将文本扩展到右边距:

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

可选参数的任何出现(甚至只是[])都会导致边距值在奇数页和偶数页之间切换。

如果文档被设置为双面,则将任何更宽的文本延伸到外边距可能是有利的。这可以通过可选参数来完成,如:

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

要使调整后的文本相对于任何周围的文本水平居中,应同样调整边距:

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

于 2009-04-06T20:01:09.913 回答
23

Latex:居中表格大于文本宽度

通常,您可以使用 \center 使表格居中。但是当表格长于 \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}
于 2011-07-08T15:09:23.240 回答
17

如果您使用的是 \table 浮点数,则 \begin{adjustwidth} ... \end{adjustwidth} 必须包含在其中。

于 2009-11-04T12:58:11.227 回答
5

在图形中,图形环境必须包含adjustwidthenv.. 此外,caption应将其留在此环境之外以与整个图形的宽度对齐:

\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}
于 2011-02-15T17:41:41.603 回答
1

您是否使用多列文档?我是这样,考虑table*变体环境。

在单列环境中,您的选项运行到:

  • 增加textwidth. 但是出于良好的人体工程学原因选择了默认边距,因此除了最小的调整之外,不鼓励这样做。
  • 减小表格中的文本大小(即\small甚至\footnotesizetabular环境中)。同样,这不是最佳的。
  • 使用Stephan202 给出的链接中建议的rotating。我在我的论文中将它用于几个非常大的表格(只有定位选项),结果非常好。p
于 2009-04-06T20:00:33.830 回答