将表格宽度精确设置为线宽

将表格宽度精确设置为线宽

我正在尝试创建一个与周围文本宽度完全相同的表格。

我期望该命令\resizebox{\linewidth}{!}{..table..}可以完成这项工作。但是,表格宽度仍然太小。

在此处输入图片描述

\documentclass{scrartcl} 
\usepackage{graphicx}
\usepackage[table]{xcolor}
\setlength{\parindent}{0pt}

\usepackage[
  top=0.600cm, 
  bottom=0.600cm,
  left=0.600cm, 
  right=0.600cm]
  {geometry}


\begin{document}
bla blub blaaa bla blub blaaabla blub blaaa bla blub blaaa bla blub blaaa bla blub blaaaa
bla blub blaaa bla blub blaaabla blub blaaa bla blub blaaa bla blub blaaa bla blub blaaaa
bla blub blaaa bla blub blaaabla blub blaaa bla blub blaaa bla blub blaaa bla blub blaaaa
bla blub blaaa bla blub blaaabla blub blaaa bla blub blaaa bla blub blaaa bla blub


\resizebox{\linewidth}{!}{
\begin{tabular}{|l|l|l|l|}
  \hline
  test entry & test entry & test entry & test entry \\
  test entry & test entry & test entry & test entry \\
  test entry & test entry & test entry & test entry \\
  \hline
\end{tabular}
}

\end{document}

答案1

我认为你有两个不错的选择和一个(可能)糟糕的选择:

  • 使用tabular*环境,

  • 使用tabularx环境(或其近亲tabulary

  • 使用基本tabular环境并使用 将其扩大(或缩小)\resizebox

结果如下(第一条水平线只是为了说明文本块的宽度;身体四个表格完全相同,即,它们的区别仅在于布局):

在此处输入图片描述

你能说出为什么我认为以前的方法\resizebox简直太可怕了吗?

\documentclass{scrartcl} 
\usepackage{graphicx} % for '\resizebox` macro
\usepackage{tabularx} % for 'tabularx' environment
\setlength{\parindent}{0pt}
\usepackage[margin=0.6cm]{geometry}
\newcommand\TestTable{% define body of test table
  \hline
  test entry & test entry & test entry & test entry \\
  test entry & test entry & test entry & test entry \\
  test entry & test entry & test entry & test entry \\
  \hline}
\begin{document}
\hrule

\subsubsection*{Unscaled}

\begin{tabular}{llll}
\TestTable
\end{tabular}

\subsubsection*{Using \texttt{tabular*}}

\begin{tabular*}{\textwidth}{l@{\extracolsep{\fill}}lll}
\TestTable
\end{tabular*}

\subsubsection*{Using \texttt{tabularx}}

\begin{tabularx}{\textwidth}{XXXX}
\TestTable
\end{tabularx}

\subsubsection*{Scaled with \texttt{\textbackslash resizebox}}

\resizebox{\linewidth}{!}{%
\begin{tabular}{llll}
\TestTable
\end{tabular}}

\end{document}

相关内容