我怎样才能把线装进单元格内
\documentclass[12pt]{article}
\usepackage{array}
\usepackage{multirow}
\usepackage{makecell, cellspace, caption}
\usepackage[table, svgnames, dvipsnames]{xcolor}
\begin{document}
\begin{table}[h]
\begin{center}
\label{1}
\scriptsize
\renewcommand{\arraystretch}{2.4}
\begin{tabular}{|>{\centering\arraybackslash}p{0.7\textwidth}|
>{\centering\arraybackslash}p{0.1\textwidth}|
>{\centering\arraybackslash}p{0.1\textwidth}|
}
\hline\hline
\rowcolor{Gainsboro!60}
Course Learning Outcomes (CLO)$^\star$ &Question &Grade \\
\hline
\multirow{3}{*}{
1- Understand complex plane and the concepts of complex exponential functions, phasors, impedances and admittances.}
& 1&1 \\ \cline{2-3}
& 2 & 1 \\ \cline{2-3}
& 3 &1 \\ \cline{2-3}
& 4 &1 \\ \cline{2-3}
& 5& 1 \\ \cline{2-3}
\hline
\end{tabular}
\end{center}
\end{table}
\end{document}
答案1
要使\multirow
单元格的宽度与其周围的列一样宽,请使用=
而不是*
。*
使多行单元格的宽度与其内容一样宽,因此会出现溢出。如果您还想确保内容相对于相邻列垂直居中,则可以使用\multirow{5}{*}{...}
。
在以下 MWE 中,我还就如何改进代码及其输出提出了一些建议:
\documentclass[12pt]{article}
\usepackage{array}
\usepackage{multirow}
\usepackage{makecell}
\usepackage[column=0]{cellspace}
\usepackage{caption}
\usepackage[table, svgnames, dvipsnames]{xcolor}
\usepackage{tabularx}
\setlength{\cellspacetoplimit}{\tabcolsep}
\setlength{\cellspacebottomlimit}{\cellspacetoplimit}
\begin{document}
\begin{table}[h]
% \begin{center} % better use \centering instead. The center environment adds vertical white space.
% \label{1} % useless without a corresponding caption
% \scriptsize
% \renewcommand{\arraystretch}{2.4} % replaced with cellspace to ensure vertically centered cell contents
\begin{tabularx}{\textwidth}{|>{\centering\arraybackslash}X|
0{wc{0.125\textwidth}}| % from the array package that you already load
0{wc{0.125\textwidth}}|
}
\hline\hline
\rowcolor{Gainsboro!60}
Course Learning Outcomes (CLO)$^\star$ &Question &Grade \\
\hline
\multirow{6}{=}{
1- Understand complex plane and the concepts of complex exponential functions, phasors, impedances and admittances.}
& 1&1 \\ \cline{2-3}
& 2 & 1 \\ \cline{2-3}
& 3 &1 \\ \cline{2-3}
& 4 &1 \\ \cline{2-3}
& 5& 1 \\ \cline{2-3}
\hline
\end{tabularx}
% \end{center}
\end{table}
\end{document}
答案2
与 @lenardiis 的回答有一点小变化(+1):
\multirow
增加了在单元格中对文本进行连字符连接的可能性- 用于表格水平规则包
\Xhline{...}
中的定义makecell
\documentclass[12pt]{article}
\usepackage{ragged2e} % new
\hyphenation{im-ped-ance im-ped-ances} % <--- (source: https://www.hyphenator.net/en/word/)
\usepackage{array, makecell, multirow, tabularx}
\usepackage[column=0]{cellspace}
\setlength\cellspacetoplimit{\tabcolsep}
\setlength\cellspacebottomlimit{\cellspacetoplimit}
%\addparagraphcolumntypes{X}
\usepackage{caption}
\usepackage[table, svgnames, dvipsnames]{xcolor}
\begin{document}
\begin{table}[ht]
\renewcommand\multirowsetup{\RaggedRight} % <--- new
\begin{tabularx}{\textwidth}{|>{\Centering}X | % <--- changed
wc{0.12\textwidth} |
0{wc{0.12\textwidth}}|
}
\Xhline{1pt}
\rowcolor{Gainsboro!60}
Course Learning Outcomes (CLO)$^\star$
& Question & Grade \\
\Xhline{0.8pt}
\multirow{6}{=}{% <---
1- Understand complex plane and the concepts of complex exponential functions, phasors, impedances and admittances.}
& 1 & 1 \\ \cline{2-3}
& 2 & 1 \\ \cline{2-3}
& 3 & 1 \\ \cline{2-3}
& 4 & 1 \\ \cline{2-3}
& 5 & 1 \\ \cline{2-3}
\Xhline{1pt}
\end{tabularx}
\end{table}
\end{document}