我正在努力学习 TeX 语言,为毕业前的最后一个工程项目做准备,虽然我能够在网上找到大多数解决方案,但我似乎找不到这个解决方案。我正在尝试格式化表格,使大文本垂直和水平居中,并且表格本身在页面上居中。大文本,在我现在的格式中,触及了水平线的顶部。
代码如下:
\documentclass[11pt]{article}
\usepackage{array}
\begin{document}
%\begin{center}
\begin{table}[ht]
\caption{Room 6 - Customer Assessments of Competing Products}
\begin{tabular}{|c|c|c|}\hline
\Large
Customer Requirements & \Large Zhang Company & \Large Wisking Company \\[2ex] \hline
Standard size & 3 &1\\ \hline
Pushed Manually & 5&3 \\ \hline
Max Weight = 150 & 2& 3 \\ \hline
Lifespan &3&4\\ \hline
Rigid Backrest &3&3\\ \hline
Adjustable&2&2\\ \hline
Easy Operation&1&3\\ \hline
Left-/Right-hand Steering&3&4\\ \hline
Drive Up Inclines&4&4\\ \hline
Non-Obtrusive Motor&4&3\\ \hline
Non-Obtrusive Electrical Components&3&5\\ \hline
Safety&3&5\\ \hline
Braking&5&5\\ \hline
\multicolumn{3}{c}{1 - Poor; 3 - Good; 5 - Excellent}
\end{tabular}
\end{table}
%\end{center}
\end{document}
非常感谢。希望我的描述足够详细。
答案1
使表格变窄以便可以居中,并在各处添加垂直空间。
(您可以考虑在表格中减少规则......)
\documentclass[11pt]{article}
\usepackage{array}
\begin{document}
\begin{table}[ht]
\setlength\extrarowheight{2pt}
\centering
\caption{Room 6 - Customer Assessments of Competing Products}
\medskip
\begin{tabular}{|c|c|c|}\hline
\Large
\rule{0pt}{1.5em}%
Customer & \Large Zhang & \Large Company \\
\Large Requirements & \Large Company & \Large Company \\[2ex] \hline
Standard size & 3 &1\\ \hline
Pushed Manually & 5&3 \\ \hline
Max Weight = 150 & 2& 3 \\ \hline
Lifespan &3&4\\ \hline
Rigid Backrest &3&3\\ \hline
Adjustable&2&2\\ \hline
Easy Operation&1&3\\ \hline
Left-/Right-hand Steering&3&4\\ \hline
Drive Up Inclines&4&4\\ \hline
Non-Obtrusive Motor&4&3\\ \hline
Non-Obtrusive Electrical Components&3&5\\ \hline
Safety&3&5\\ \hline
Braking&5&5\\ \hline
\multicolumn{3}{c}{\rule{0pt}{1.5em}%
1 - Poor; 3 - Good; 5 - Excellent}
\end{tabular}
\end{table}
\noindent X\dotfill X
\noindent X\dotfill X
\end{document}
答案2
要将表格单独放置在页面上并垂直居中,请[p]
在启动table
环境时使用位置说明符。
如果您愿意将标题行的相对字体大小从 改为\Large
,\large
则可以 (i) 使表格适合文本块,并且 (ii) 有助于避免使用不同字体大小的视觉上相近的项目时可能很容易出现的“勒索信外观”。为了在规则\hline
和其下方的文本之间获得更好的垂直间距,请插入突出在文本行上方的“支柱”(具有一定高度但没有宽度的对象,因此不可见)。我还建议删除表格中的大部分水平线和所有垂直线——它们实际上只会增加视觉混乱。
\documentclass[11pt]{article}
\newcommand{\Tstrut}{\rule{0pt}{2.5ex}} % "top strut"
\begin{document}
\begin{table}[p] % use 'p' specifier to place float on a page by itself
\centering
\caption{Room 6 --- Customer Assessments of Competing Products}
\medskip % add some separation between caption and table
\begin{tabular}{@{}lcc@{}}
\hline
\large Customer Requirements \rule{0pt}{3.5ex} &
\large Zhang Company &
\large Wisking Company \\[1ex]
\hline
Standard size & 3 &1\Tstrut\\
Pushed Manually & 5&3 \\
Max Weight = 150 & 2& 3 \\
Lifespan &3&4\\
Rigid Backrest &3&3\\
Adjustable&2&2\\
Easy Operation&1&3\\
Left-/Right-hand Steering&3&4\\
Drive Up Inclines&4&4\\
Non-Obtrusive Motor&4&3\\
Non-Obtrusive Electrical Components&3&5\\
Safety&3&5\\
Braking&5&5\\
\hline
& \multicolumn{2}{l@{}}{1 - Poor; 3 - Good; 5 - Excellent\Tstrut}\\
\cline{2-3}
\end{tabular}
\end{table}
\end{document}
答案3
您的第一个问题是表格大于 \textwidth。我已将页面设置为最大尺寸。\rules 只是为了帮助显示页面限制在哪里。
我避免使用表格和图形。它们从来都不是我想要的。最后,我修改了 \raisebox,直到它看起来不错。我不知道它是否精确居中。
\documentclass[11pt]{article}
\usepackage{array}
\setlength{\topmargin}{0pt}
\setlength{\headheight}{0pt}
\setlength{\headsep}{0pt}
\setlength{\footskip}{0in}
\setlength{\textheight}{9.5in}
\setlength{\oddsidemargin}{0pt}
\setlength{\evensidemargin}{0pt}
\setlength{\marginparwidth}{0pt}
\setlength{\marginparsep}{0pt}
\setlength{\textwidth}{6.5in}
\pagestyle{empty}
\newcommand{\mybox}[1]{\raisebox{-.05in}[0.2in][0.2in]{#1}}
\begin{document}
\noindent\rule{\textwidth}{1pt}\\
\vfill
\begin{center}
\begin{tabular}{|c|c|c|}
\multicolumn{3}{l}{Room 6 - Customer Assessments of Competing Products}\\
\hline
\mybox{\Large Customer Requirements} & \mybox{\Large Zhang Company}
& \mybox{\Large Wisking Company} \\
\hline
Standard size & 3 &1\\ \hline
Pushed Manually & 5&3 \\ \hline
Max Weight = 150 & 2& 3 \\ \hline
Lifespan &3&4\\ \hline
Rigid Backrest &3&3\\ \hline
Adjustable&2&2\\ \hline
Easy Operation&1&3\\ \hline
Left-/Right-hand Steering&3&4\\ \hline
Drive Up Inclines&4&4\\ \hline
Non-Obtrusive Motor&4&3\\ \hline
Non-Obtrusive Electrical Components&3&5\\ \hline
Safety&3&5\\ \hline
Braking&5&5\\ \hline
\multicolumn{3}{c}{1 - Poor; 3 - Good; 5 - Excellent}
\end{tabular}
\end{center}
\vfill
\noindent\rule{\textwidth}{1pt}\\
\end{document}