使表格利用页面宽度

使表格利用页面宽度

最小工作示例:

\documentclass[onecolumn]{article}
\usepackage{listings}

\title{F}

\begin{document}
\maketitle

\secion{foo}
\subsection{Interface (queries, stored procedures)}

\begin{tabular}{|l|}
    \hline
    create\_queue(OUT rv SMALLINT) \\
    delete\_queue(\_queue\_id BIGINT, OUT status SMALLINT) \\
    insert\_message(queue\_id BIGINT, source\_client\_id BIGINT, target\_client\_id BIGINT, rv TEXT, OUT status SMALLINT) \\
    read\_top\_message(\_queue\_id BIGINT, client\_id BIGINT, OUT rv TEXT, OUT status SMALLINT) \\
    delete\_top\_message(\_queue\_id BIGINT, client\_id BIGINT, OUT rv TEXT, OUT status SMALLINT) \\
    queue\_exists(\_queue\_id BIGINT, OUT status SMALLINT) \\
    get\_queues(OUT rv BIGINT) RETURNS SETOF BIGINT \\
    epoche\_ms(OUT rv BIGINT) \\
    get\_queues\_with\_pending\_messages(client\_id BIGINT, OUT rv BIGINT) RETURNS SETOF BIGINT \\
    read\_message\_by\_sender(\_queue\_id BIGINT, \_client\_id BIGINT, \_source\_client\_id BIGINT, OUT rv TEXT, OUT status BIGINT) \\
    delete\_message\_by\_sender(\_queue\_id BIGINT, \_client\_id BIGINT, \_source\_client\_id BIGINT, OUT rv TEXT, OUT status SMALLINT) \\
    create\_client(\_clientId BIGINT, OUT status SMALLINT) \\
    client\_exists(\_clientId BIGINT, OUT status SMALLINT) \\
    get\_clients(OUT rv BIGINT) RETURNS SETOF BIGINT \\
    create\_client(\_clientId BIGINT, OUT status SMALLINT) \\
    \hline
\end{tabular}
\end{document}

输出(本质上):在此处输入图片描述 如何让表格利用其左侧的空白空间?

注意:我搜索了解决方案并找到了相当多的解决方案 - 许多涉及表格* - 但不幸的是我无法让它们为我工作。

答案1

以下是您的选择

首先,使用p{\dimexpr\textwidth-2\tabcolsep-2\arrayrulewidth\relax}代替l列。

\documentclass[onecolumn]{article}
\usepackage{listings}


\title{F}

\begin{document}
\maketitle

\section{foo}
\subsection{Interface (queries, stored procedures)}
\noindent
\begin{tabular}{|p{\dimexpr\textwidth-2\tabcolsep-2\arrayrulewidth\relax}|}
    \hline
    create\_queue(OUT rv SMALLINT) \\
    delete\_queue(\_queue\_id BIGINT, OUT status SMALLINT) \\
    insert\_message(queue\_id BIGINT, source\_client\_id BIGINT, target\_client\_id BIGINT, rv TEXT, OUT status SMALLINT) \\
    read\_top\_message(\_queue\_id BIGINT, client\_id BIGINT, OUT rv TEXT, OUT status SMALLINT) \\
    delete\_top\_message(\_queue\_id BIGINT, client\_id BIGINT, OUT rv TEXT, OUT status SMALLINT) \\
    queue\_exists(\_queue\_id BIGINT, OUT status SMALLINT) \\
    get\_queues(OUT rv BIGINT) RETURNS SETOF BIGINT \\
    epoche\_ms(OUT rv BIGINT) \\
    get\_queues\_with\_pending\_messages(client\_id BIGINT, OUT rv BIGINT) RETURNS SETOF BIGINT \\
    read\_message\_by\_sender(\_queue\_id BIGINT, \_client\_id BIGINT, \_source\_client\_id BIGINT, OUT rv TEXT, OUT status BIGINT) \\
    delete\_message\_by\_sender(\_queue\_id BIGINT, \_client\_id BIGINT, \_source\_client\_id BIGINT, OUT rv TEXT, OUT status SMALLINT) \\
    create\_client(\_clientId BIGINT, OUT status SMALLINT) \\
    client\_exists(\_clientId BIGINT, OUT status SMALLINT) \\
    get\_clients(OUT rv BIGINT) RETURNS SETOF BIGINT \\
    create\_client(\_clientId BIGINT, OUT status SMALLINT) \\
    \hline
\end{tabular}
\end{document}

在此处输入图片描述

二、使用tabularx

\documentclass[onecolumn]{article}
\usepackage{listings}
\usepackage{tabularx}

\title{F}

\begin{document}
\maketitle

\section{foo}
\subsection{Interface (queries, stored procedures)}
\noindent
\begin{tabularx}{\textwidth}{|X|}
    \hline
    create\_queue(OUT rv SMALLINT) \\
    delete\_queue(\_queue\_id BIGINT, OUT status SMALLINT) \\
    insert\_message(queue\_id BIGINT, source\_client\_id BIGINT, target\_client\_id BIGINT, rv TEXT, OUT status SMALLINT) \\
    read\_top\_message(\_queue\_id BIGINT, client\_id BIGINT, OUT rv TEXT, OUT status SMALLINT) \\
    delete\_top\_message(\_queue\_id BIGINT, client\_id BIGINT, OUT rv TEXT, OUT status SMALLINT) \\
    queue\_exists(\_queue\_id BIGINT, OUT status SMALLINT) \\
    get\_queues(OUT rv BIGINT) RETURNS SETOF BIGINT \\
    epoche\_ms(OUT rv BIGINT) \\
    get\_queues\_with\_pending\_messages(client\_id BIGINT, OUT rv BIGINT) RETURNS SETOF BIGINT \\
    read\_message\_by\_sender(\_queue\_id BIGINT, \_client\_id BIGINT, \_source\_client\_id BIGINT, OUT rv TEXT, OUT status BIGINT) \\
    delete\_message\_by\_sender(\_queue\_id BIGINT, \_client\_id BIGINT, \_source\_client\_id BIGINT, OUT rv TEXT, OUT status SMALLINT) \\
    create\_client(\_clientId BIGINT, OUT status SMALLINT) \\
    client\_exists(\_clientId BIGINT, OUT status SMALLINT) \\
    get\_clients(OUT rv BIGINT) RETURNS SETOF BIGINT \\
    create\_client(\_clientId BIGINT, OUT status SMALLINT) \\
    \hline
\end{tabularx}
\end{document}

第三,如果您想坚持使用l列类型,请使用以下命令:

\documentclass[onecolumn]{article}
\usepackage{listings}


\title{F}

\begin{document}
\maketitle

\section{foo}
\subsection{Interface (queries, stored procedures)}
\noindent
\makebox[\textwidth][c]{%
\footnotesize
\begin{tabular}{|l|}
    \hline
    create\_queue(OUT rv SMALLINT) \\
    delete\_queue(\_queue\_id BIGINT, OUT status SMALLINT) \\
    insert\_message(queue\_id BIGINT, source\_client\_id BIGINT, target\_client\_id BIGINT, rv TEXT, OUT status SMALLINT) \\
    read\_top\_message(\_queue\_id BIGINT, client\_id BIGINT, OUT rv TEXT, OUT status SMALLINT) \\
    delete\_top\_message(\_queue\_id BIGINT, client\_id BIGINT, OUT rv TEXT, OUT status SMALLINT) \\
    queue\_exists(\_queue\_id BIGINT, OUT status SMALLINT) \\
    get\_queues(OUT rv BIGINT) RETURNS SETOF BIGINT \\
    epoche\_ms(OUT rv BIGINT) \\
    get\_queues\_with\_pending\_messages(client\_id BIGINT, OUT rv BIGINT) RETURNS SETOF BIGINT \\
    read\_message\_by\_sender(\_queue\_id BIGINT, \_client\_id BIGINT, \_source\_client\_id BIGINT, OUT rv TEXT, OUT status BIGINT) \\
    delete\_message\_by\_sender(\_queue\_id BIGINT, \_client\_id BIGINT, \_source\_client\_id BIGINT, OUT rv TEXT, OUT status SMALLINT) \\
    create\_client(\_clientId BIGINT, OUT status SMALLINT) \\
    client\_exists(\_clientId BIGINT, OUT status SMALLINT) \\
    get\_clients(OUT rv BIGINT) RETURNS SETOF BIGINT \\
    create\_client(\_clientId BIGINT, OUT status SMALLINT) \\
    \hline
\end{tabular}
}
\end{document}

在此处输入图片描述

这里我使用了一个框\textwidth并将其居中。由于表格太宽,我还将文本大小缩小到了\footnotesize(一般来说人们不喜欢这样)。

相关内容