我想使用 LaTeX 创建一个表格。表格如下所示:
我设法制作了一个表格,但它不是我所设想的那样。它看起来像这样:
我使用的代码如下:
\documentclass[a4paper,twocolumn]{article}
\usepackage[margin=1in]{geometry}
\usepackage{multirow,booktabs}
\usepackage{amssymb}
\usepackage{array}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{tabularx,ragged2e,booktabs,caption}
\renewcommand\tabularxcolumn[1]{C{#1}}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\setlength\parindent{0pt}
\begin{document}
\sffamily\small
\setlength{\tabcolsep}{4pt}
\setlength{\extrarowheight}{2pt}
\noindent
\centering
\begin{tabularx}{\linewidth}{|p{2.0cm}|p{2.0cm}|p{2.0cm}|p{2.0cm}| }
\hline
Appointment---related information & Did the information gets posted on the Google Calendar? & & Notes\\
\cline{2-3}
& Yes & No &
\hline
%\multirow{2}{=}
Meeting at 6 & \checkmark & & Correct response \\
\hline
Meeting at 6 & \checkmark & & Correct response \\
\hline
Meeting at 6 & \checkmark & & Correct response \\
\hline
Meeting at 6 & \checkmark & & Correct response \\
\hline
Meeting at 6 & \checkmark & & Correct response \\
\hline
Meeting at 6 & \checkmark & & Correct response \\
\hline
Meeting at 6 & \checkmark & & Correct response \\
\hline
Meeting at 6 & \checkmark & & Correct response \\
\hline
Meeting at 6 & \checkmark & & Correct response \\
\hline
Meeting at 6 & \checkmark & & Correct response \\
\hline
\end{tabularx}
\label{tab:tab1}
\caption{Tabulated app's responses to different usernames and passwords.}
\vspace{60mm}
\end{document}
我的问题是:
我们如何使用 LaTeX 制作一个看起来像上面第一张图片的表格,并且看起来更有吸引力?
答案1
以下 MWE 包含两个不同的建议。第一个建议与问题中的草图非常相似。为此,我使用了包X
中的类型列tabularx
以及一些multirow
命令来垂直居中表格条目。
第二个建议使用更少的线条:我删除了所有垂直线以及大多数水平线,并用 的booktabs
规则替换剩余的线条。我还尝试缩短其中一个列标题。
\documentclass[a4paper,twocolumn]{article}
\usepackage[margin=1in]{geometry}
\usepackage{calc}
\usepackage{amssymb}
\usepackage{array}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{tabularx,ragged2e,multirow,booktabs}
\renewcommand\tabularxcolumn[1]{C{#1}}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\setlength\parindent{0pt}
\begin{document}
\begin{table}
\sffamily\small
\setlength{\tabcolsep}{4pt}
\setlength{\extrarowheight}{2pt}
\noindent
\centering
\begin{tabularx}{\linewidth}{|X|C{1cm-\tabcolsep}|C{1cm-\tabcolsep}|c|}
\hline
\multirow{6}{=}{\centering Appointment-related information} & \multicolumn{2}{C{2cm}|}{Did the information gets posted on the Google Calendar?} & \multirow{6}{*}{\centering Notes}\\
\cline{2-3}
& Yes & No & \\
\hline
Meeting at 6 & \checkmark & & Correct response \\
\hline
a different longer entry & \checkmark & & Correct response \\
\hline
Meeting at 6 & \checkmark & & Correct response \\
\hline
Meeting at 6 & \checkmark & & Correct response \\
\hline
Meeting at 6 & \checkmark & & Correct response \\
\hline
Meeting at 6 & \checkmark & & Correct response \\
\hline
Meeting at 6 & \checkmark & & Correct response \\
\hline
Meeting at 6 & \checkmark & & Correct response \\
\hline
Meeting at 6 & \checkmark & & Correct response \\
\hline
Meeting at 6 & \checkmark & & Correct response \\
\hline
\end{tabularx}
\label{tab:tab1}
\caption{Tabulated app's responses to different usernames and passwords.}
\end{table}
\begin{table}
\sffamily\small
\setlength{\tabcolsep}{4pt}
\setlength{\extrarowheight}{2pt}
\noindent
\centering
\begin{tabularx}{\linewidth}{XC{1cm-\tabcolsep}C{1cm-\tabcolsep}c}
\toprule
\multirow{4}{=}{\centering Appointment-related information} & \multicolumn{2}{C{2cm}}{Info posted on the Google Calendar?} & \multirow{4}{*}{\centering Notes}\\
\cmidrule{2-3}
& Yes & No & \\
\midrule
Meeting at 6 & \checkmark & & Correct response \\
a different longer entry & \checkmark & & Correct response \\
Meeting at 6 & \checkmark & & Correct response \\
Meeting at 6 & \checkmark & & Correct response \\
Meeting at 6 & \checkmark & & Correct response \\
Meeting at 6 & \checkmark & & Correct response \\
Meeting at 6 & \checkmark & & Correct response \\
Meeting at 6 & \checkmark & & Correct response \\
Meeting at 6 & \checkmark & & Correct response \\
Meeting at 6 & \checkmark & & Correct response \\
\bottomrule
\end{tabularx}
\label{tab:tab1}
\caption{Tabulated app's responses to different usernames and passwords.}
\end{table}
\end{document}
答案2
列说明符 p(宽度以厘米为单位)对我来说总是很好用。
%
The following table~\ref{tbl:potential_cal} lists all calibration variables so far considered.
{
\begin{table}[ht]
\caption{Example Calibration Variables} % title of Table
%\centering % used for centering table
\begin{tabular}{|| p{3cm} | l | c | p{6cm} ||} \hline
\rowcolor{LightCyan}
\textbf{Name} & \textbf{\oc{20}} & \textbf{\oc{60}} & \textbf{Comments} \\ \hline
\hline
Offsets of Something & YES & POSS & Should be very close to $\frac{V_{cc}}{2}$ \\ \hline
Offsets of Something even longer & YES & POSS & Should be very close to $\frac{V_{cc}}{2}$ \\ \hline
Offsets of Something even longer and more & YES & POSS & Should be very close to $\frac{V_{cc}}{2}$ and something else as well in the text \\ \hline
\hline
\end{tabular}
\label{tbl:potential_cal}
\end{table}
}
~