控製表格環境中列的寬度

控製表格環境中列的寬度

我希望右欄中的文字片段更接近左欄中的文字片段。同時,我希望表格能夠像現在一樣很好地容納長文本。實現此結果的一種方法是限制左列的寬度,增加右列的寬度,並將右列的左邊距向左移動。但我不知道該怎麼做。

這是我到目前為止所得到的 MWE桌子

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}

\begin{document}

\begin{table}
 \centering
 \begin{tabular}{*{2}{p{.425\linewidth}}}
  \toprule
  first &  second second second second second second second second second second\\
  \midrule
  third & fourth fourth fourth fourth fourth fourth fourth fourth fourth fourth \\
  \bottomrule
 \end{tabular}
\end{table}

\end{document}

感謝您的協助。

答案1

據我理解這個問題,我會嘗試

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}

\begin{document}
\begin{table}
 \centering
 \begin{tabular}{l p{0.5\linewidth}}
  \toprule
  first &  second second second second second second second second second second\\
  \midrule
  third & fourth fourth fourth fourth fourth fourth fourth fourth fourth fourth \\
  \bottomrule
 \end{tabular}
\end{table}
\end{document}

獲得

在此輸入影像描述

答案2

正如@Werner 在評論中已經指出的那樣,對於您的格式化目標來說,一個好的候選解決方案是載入套件tabularx並使用一個tabularx環境(總體寬度設定為\textwidth)而不是tabular。然後,將第一個列規範從 更改為p{...}l並將第二個列規範從 更改p{...}X

在此輸入影像描述

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{tabularx} % for "tabularx" env. and "X" column type

\begin{document}

\begin{table}
\begin{tabularx}{\textwidth}{@{} l X @{}}
  \toprule
  first & second second second second second second second 
          second second second second second second second second \\
  \midrule
  third & fourth fourth fourth fourth fourth fourth fourth fourth 
          fourth fourth fourth fourth \\
  \bottomrule
\end{tabularx}
\end{table}

\end{document} 

相關內容