![如何使表格文本不与下一列重叠](https://linux22.com/image/477806/%E5%A6%82%E4%BD%95%E4%BD%BF%E8%A1%A8%E6%A0%BC%E6%96%87%E6%9C%AC%E4%B8%8D%E4%B8%8E%E4%B8%8B%E4%B8%80%E5%88%97%E9%87%8D%E5%8F%A0.png)
这是我为其编写的代码:
\documentclass{article}
%Table formatting
\usepackage[none]{hyphenat}
\usepackage{array}
\newcolumntype{$}{>{\global\let\currentrowstyle\relax}}
\newcolumntype{^}{>{\currentrowstyle}}
\newcommand{\rowstyle}[1]{\gdef\currentrowstyle{#1} #1\ignorespaces}
\usepackage{multirow}
\usepackage{adjustbox}
\begin{table} [ht]
\centering
\label{tab:test}
\begin{adjustbox}{max width=\textwidth}
\begin{tabular}{$c^c^p{0.9in}^c^c^c^c}
\hline
\rowstyle{\bfseries}ID & Requirement & Description & Inputs & Expected outputs & Pass/Fail & Comments \\
\hline
A1.1 & FR1 & \multirow{2}{0.9in}{checking attendants can only park certain vehicles} & 1-3 & Nothing & P & \\
& \multicolumn{2}{c}{} & 4-5 & produces error & F & doesn't check input of vehicleType \\
\hline
A1.2 & FR2 & \multirow{2}{0.9in}{checking attendants can only park certain vehicles} & 1-3 & Nothing & P & \\
& \multicolumn{2}{c}{} & 4-5 & produces error & F & doesn't check input of vehicleType \\
\end{tabular}
\end{adjustbox}
\caption{Test table}
\end{table}
当前输出导致描述中的文本与下一行重叠。我知道有人问过类似的问题,但我对 LaTeX 还不熟悉,不明白他们的解决方案是如何解决这个问题的。
答案1
切勿使用adjustbox
with tabless,因为它会产生不一致的字体大小。最好调整字体大小和 的值\tabcolsep
。
话虽如此,您可以使用多行,不是在第 3 列,而是在第 4-7 列。
为了适应,\textwidth
我建议使用tabularx
,第 3 列和第 7 列为类型X
。在这种情况下,您只需要\multirow
对第 4-6 列使用。此外,我加载了几何图形,以获得更合理的边距(如果您不需要边注)。最后,我使用了规则booktabs
,在水平线周围添加一些垂直填充:
\documentclass{article}
%Table formatting
\usepackage[none]{hyphenat}
\usepackage{array}
\usepackage{ragged2e}
\newcolumntype{$}{>{\global\let\currentrowstyle\relax}}
\newcolumntype{^}{>{\currentrowstyle}}
\newcommand{\rowstyle}[1]{\gdef\currentrowstyle{#1} #1\ignorespaces}
\usepackage{multirow, makecell, tabularx, booktabs}
\usepackage{adjustbox}
\usepackage{geometry}
\begin{document}
\begin{table} [!htb]
\centering\renewcommand{\cellalign}{tc}
\label{tab:test}
\begin{adjustbox}{max width=\textwidth}
\begin{tabular}{$c^c^p{0.9in}^c^c^c^c}
\toprule
\rowstyle{\bfseries}ID & Requirement & Description & Inputs & Expected outputs & Pass/Fail & Comments \\
\midrule
A1.1 & FR1 & \RaggedRight checking attendants can only park certain vehicles & \makecell{1-3\\4-5} & \makecell{Nothing\\produces error} & \makecell{P \\F }& \makecell{\\doesn't check input of vehicleType}\\
\midrule
A1.2 & FR2 & \multirow{2}{=}{checking attendants can only park certain vehicles} & 1-3 & Nothing & P & \\
& \multicolumn{2}{c}{} & 4-5 & produces error & F & doesn't check input of vehicleType \\[8ex]
\bottomrule
\end{tabular}
\end{adjustbox}
\caption{Test table}
\end{table}
\begin{table} [! htb]
\centering\footnotesize\renewcommand{\cellalign}{tc}
\setlength{\tabcolsep}{4pt}
\label{tab:test}
\begin{tabularx}{\linewidth}{$c^c^X^c^c^c^X}
\toprule
\rowstyle{\bfseries}ID & Requirement & Description & Inputs & Expected outputs & Pass/Fail & Comments \\
\midrule
A1.1 & FR1 & \RaggedRight checking attendants can only park certain vehicles & \makecell{1-3\\4-5} & \makecell{Nothing\\produces error} & \makecell{P \\F }&\mbox{} \newline doesn't check input of vehicleType \\
\midrule
A1.2 & FR2 & \multirow{3}{=}{\RaggedRight checking attendants can only park certain vehicles} & 1-3 & Nothing & P & \\
& \multicolumn{2}{c}{} & 4-5 & produces error & F & doesn't check input of vehicleType \\%[8.5ex]
\bottomrule
\end{tabularx}
\caption{Test table}
\end{table}
\end{document}