这张表有几个问题。
我使用
\centering
命令将表格的第一行居中对齐,但它不起作用,所有内容都左对齐表格右上角的边框缺少一些部分
有没有办法最大限度地减少行之间的空白?
代码:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[a4paper, total={6in, 8in}]{geometry}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{amsmath,amssymb}
\usepackage{amsthm}
\usepackage{mathrsfs}
\usepackage{cleveref}
\usepackage{tikz}
\usetikzlibrary{positioning,calc,arrows.meta}%arrows is deprecated
\usepackage{float}
\usepackage{framed}
\usepackage{blindtext}
\newfloat{infobox}{htbp}{lop}
\theoremstyle{definition}
\newtheorem{definition}{Definition}[section]
\pagenumbering{gobble}
\begin{document}
\begin{center}
\begin{table}
\centering
\begin{tabular}{|p{0.4\linewidth} | p{0.5\linewidth}|}
\hline
Visit Type & Fixed-Point Loop? \\ \\
\hline\hline
Circular visit inside of circular visit & No fixed-point loop. Since the parent visit repeats the evaluation, its loop includes the child visit as well.\\ \hline
Non-circular visit in circular visit & No fixed-point loop. Visit has to evaluate only once. \\ \hline
Non-circular visit in non-circular visit & No fixed-point loop. Visit has to evaluate only once. \\ \hline
Circular visit in non-circular visit & Needs fixed-point loop. \\ \hline
\end{tabular}\caption{case-by-case analysis of loop requirement in CRAG visit sequence evaluator}
\end{table}
\end{center}
\end{document}
答案1
- 对于您的下一个问题:您的代码包含许多不必要的包。
- 您两次将(完整的!)表格居中(使用
\begin{center}
和\centering
)。此\centering
版本更好,因为它没有添加额外的垂直空白,请参阅何时应使用 \begin{center} 而不是 \centering?。 - 关于第一个问题(将单元格内容居中),我提供了一个基于在表格环境中对齐特定单元格。
- 对于另一个问题(单词间距),我建议看看表格中 p{length} 框的右对齐或者如何使表格中的段落单元格左对齐?(我现在必须停止拖延并开始做我的实际工作:))。
\documentclass{article}
%\usepackage[utf8]{inputenc}
\begin{document}
\begin{table}
\centering
\begin{tabular}{|p{0.4\linewidth} | p{0.5\linewidth}|}
\hline
% https://tex.stackexchange.com/questions/33486
\multicolumn{1}{|c|}{Visit Type} & \multicolumn{1}{c|}{Fixed-Point Loop?} \\
\hline\hline
Circular visit inside of circular visit & No fixed-point loop. Since the parent visit repeats the evaluation, its loop includes the child visit as well.\\ \hline
Non-circular visit in circular visit & No fixed-point loop. Visit has to evaluate only once. \\ \hline
Non-circular visit in non-circular visit & No fixed-point loop. Visit has to evaluate only once. \\ \hline
Circular visit in non-circular visit & Needs fixed-point loop. \\ \hline
\end{tabular}\caption{case-by-case analysis of loop requirement in CRAG visit sequence evaluator}
\end{table}
\end{document}
答案2
您可以\centering
在第一行的单元格中使用,但需要注意的是,\tabularnewline
以便结束它。
不要封闭table
在里面center
:你只能在某处获得垂直空间,不一定在桌子周围。
我还添加了表格的不同渲染,没有垂直规则并且重复较少。
\documentclass{article}
\usepackage[a4paper, total={6in, 8in}]{geometry}
\usepackage{booktabs} % for the second rendering
\begin{document}
\begin{table}[htp]
\centering
\begin{tabular}{|p{0.4\linewidth} | p{0.5\linewidth}|}
\hline
\centering Visit Type & \centering Fixed-Point Loop? \tabularnewline
\hline\hline
Circular visit inside of circular visit &
No fixed-point loop. Since the parent visit repeats the evaluation,
its loop includes the child visit as well. \\
\hline
Non-circular visit in circular visit &
No fixed-point loop. Visit has to evaluate only once. \\
\hline
Non-circular visit in non-circular visit &
No fixed-point loop. Visit has to evaluate only once. \\
\hline
Circular visit in non-circular visit &
Needs fixed-point loop. \\
\hline
\end{tabular}
\caption{Case-by-case analysis of loop requirement in CRAG visit sequence evaluator}
\end{table}
\begin{table}[htp]
\centering
\begin{tabular}{@{} l p{0.6\linewidth} @{}}
\toprule
Visit Type & \centering Fixed-Point Loop? \tabularnewline
\midrule
Circular in circular &
No fixed-point loop. Since the parent visit repeats the evaluation,
its loop includes the child visit as well. \\
\addlinespace
Non-circular in circular &
No fixed-point loop. Visit has to evaluate only once. \\
\addlinespace
Non-circular in non-circular &
No fixed-point loop. Visit has to evaluate only once. \\
\addlinespace
Circular in non-circular &
Needs fixed-point loop. \\
\bottomrule
\end{tabular}
\caption{Case-by-case analysis of loop requirement in CRAG visit sequence evaluator}
\end{table}
\end{document}
答案3
您可以尝试使用tabularray
包。使用它来定义第一行(包含列标题)和线条样式很简单。以下是两个示例/与@egreg 答案 (+1) 中的示例类似/:
\documentclass{article}
\usepackage[a4paper, total={6in, 8in}]{geometry}
\usepackage{tabularray}
\begin{document}
\begin{table}[htp]
\centering
\begin{tblr}{hline{1,Z}=1pt, hline{2}=0.6pt, hline{3-Y}={solid},
vlines,
colspec={Q[j,t, wd=0.4\linewidth] Q[j,t, wd=0.5\linewidth]},
row{1} = {font=\bfseries, c}% content of cells in the first row
% are horizontal centered
}
Visit Type & Fixed-Point Loop? \\
Circular visit inside of circular visit
& No fixed-point loop. Since the parent visit repeats the evaluation,
its loop includes the child visit as well. \\
Non-circular visit in circular visit
& No fixed-point loop. Visit has to evaluate only once. \\
Non-circular visit in non-circular visit
& No fixed-point loop. Visit has to evaluate only once. \\
Circular visit in non-circular visit
& Needs fixed-point loop. \\
\end{tblr}
\caption{Case-by-case analysis of loop requirement in CRAG visit sequence evaluator}
\label{tab:?}
\end{table}
\begin{table}[htp]
\centering
\begin{tblr}{hline{1,Z}=1pt, hline{2}=0.6pt,
colspec={@{} Q[j,t, wd=0.4\linewidth] Q[j,t, wd=0.5\linewidth] @{}},
row{1} = {font=\bfseries, c},
row{2-Y} = {belowsep+=3pt}
}
Visit Type & Fixed-Point Loop? \\
Circular visit inside of circular visit
& No fixed-point loop. Since the parent visit repeats the evaluation,
its loop includes the child visit as well. \\
Non-circular visit in circular visit
& No fixed-point loop. Visit has to evaluate only once. \\
Non-circular visit in non-circular visit
& No fixed-point loop. Visit has to evaluate only once. \\
Circular visit in non-circular visit
& Needs fixed-point loop. \\
\end{tblr}
\caption{Case-by-case analysis of loop requirement in CRAG visit sequence evaluator}
\label{tab:??}
\end{table}
\end{document}
顺便说一句,表格的标题通常位于表格上方。