我有这个代码...
\documentclass[a4paper]{article}
\usepackage[margin=1.25in]{geometry}
\usepackage{float}
\usepackage{tabularx}
\renewcommand{\arraystretch}{1.5}
\usepackage{multirow}
\title{}
\author{}
\date{}
\begin{document}
\begin{table}[H]
\centering
\begin{tabularx}{\textwidth}{|p{2cm}|X|m{3cm}|}
\hline
\textbf{Participant} & \textbf{Answer} & \textbf{Themes} \\
\hline\hline
Short text here & I think I think I think I think I think I think I think I think I think I think I think I think I think I think I think I think I think I think I think I think I think I think I think I think I think I think I think I think & \multirow{5}{*}{Something here} \\
\hline
Short text here & test & \\
\hline
Short text here & test & \\
\hline
Short text here & test & \\
\hline
Short text here & test & \\
\hline
\end{tabularx}
\end{table}
\end{document}
如何让主题列占据整个表格列而不使用水平线。我仍然希望其他列也使用水平线。同时将其垂直居中。
答案1
欢迎使用 TeX SX!您必须使用命令\cline{1-2}
确保水平线在第二列的末尾停止。您还必须知道,\multirow
如果行是单行的,命令的第一个参数表示将由其内容替换的行数。在其他情况下,您必须计算相邻列中的行数(在本例中为 12)。此外,更改值 af\arraystretch
会使其变得更加复杂,最好的方法是估计等效行数并通过反复试验进行 - 允许使用小数来微调分位数的位置。最后一点:我将参数替换{*}
为,{=}
因为第三列具有固定宽度。
\documentclass[a4paper]{article}
\usepackage[margin=1.25in]{geometry}
\usepackage{float}
\usepackage{tabularx}
\renewcommand{\arraystretch}{1.5}
\usepackage{multirow}
\title{}
\author{}
\date{}
\begin{document}
\begin{table}[H]
\centering
\begin{tabularx}{\textwidth}{|p{2cm}|X|m{2.5cm}|}
\hline
\textbf{Participant} & \textbf{Answer} & \textbf{Themes} \\
\hline\hline
Short text here & I think I think I think I think I think I think I think I think I think I think I think I think I think I think I think I think I think I think I think I think I think I think I think I think I think I think I think I think & \multirow{9.5}{=}{Something here} \\
\cline{1-2}
Short text here & test & \\
\cline{1-2}
Short text here & test & \\
\cline{1-2}
Short text here & test & \\
\cline{1-2}
Short text here & test & \\
\hline
\end{tabularx}
\end{table}
\end{document}
答案2
该nicematrix
包本身提供了该表所需的所有元素。此外,代码简洁明了。
使用的主要命令\Block
允许识别和格式化多行/列单元格。
(重要的:该命令\Block{}
创建一个允许使用\\
内部的整体单元,从而在您想要的位置切割线,而不是依赖左对齐文本中的列宽。)
请注意,所有单元格都(很好地)垂直居中,无需任何手动调整的参数,并且使用单元格的自然宽度。
\documentclass[a4paper]{article}
\usepackage[margin=1.25in]{geometry}
\usepackage{float}
%\usepackage{tabularx}
%\renewcommand{\arraystretch}{1.5}
%\usepackage{multirow}
\usepackage{nicematrix}
\title{}
\author{}
\date{}
\begin{document}
\begin{table}[H]
\centering
%\begin{NiceTabular}{>{\raggedright\arraybackslash}p{2cm} l wc{3cm}}[% use this to retain your original width values
\begin{NiceTabular}{clc}[%
cell-space-top-limit = 5pt,
cell-space-bottom-limit = 5pt,
hvlines]
\hline
\textbf{Participant} & \Block[c]{}{\textbf{Answer}} & \textbf{Themes} \\
\hline
Short text here &\Block{}{I think I think I think I think I think \\I think I think I think I think\\ I think I think I think I think I think I think I think \\I think I think I think I think I think I think I think\\ I think \\I think I think I think I think} & \Block{5-1}{Something here} \\
Short text here & test & \\
Short text here & test & \\
Short text here & test & \\
Short text here & test & \\
\end{NiceTabular}
\end{table}
\end{document