然而,当我使用https://www.overleaf.com/learn/latex/Tables#Creating_a_simple_table_in_LaTeX,代码如下:
\documentclass{article}
\usepackage{tabularx}
\begin{document}
\begin{tabularx}{0.8\textwidth} {
| >{\raggedright\arraybackslash}X
| >{\centering\arraybackslash}X
| >{\raggedleft\arraybackslash}X | }
\hline
Place/Transition & Explanation & Time \\
\hline
T_1 and T_(2(n+1)) & Robot operation which relates to loadlocks. Transition T_1indicates that wafer unloading from the loadlocks and T_(2(n+1)) means that the robot loads the wafer to the loadlocks. & w \\
\hline
item 31 & item 32 & item 33 \\
\hline
\end{tabularx}
\end{document}
结果如下。
也许,有人有其他参考资料来创建我想要的表格吗?
当我将 \begin{tabularx}{0.8\textwidth} 替换为 \noindent\begin{tabularx}{\linewidth} 时,结果如下:
答案1
问题在于,正如评论中所述,您忽略了数学模式所需的语法。因此,TeX 在某些时候会读取_
仅在数学模式下才有效的字符。因此,它会自动切换到数学模式,但由于它不知道数学模式应该在哪里结束,因此它会继续在数学模式下排版,从而导致这种奇怪的输出。
使用数学模式的正确语法可以很容易地解决这个问题。由于您不需要第一列和第三列中的段落,因此您也可以切换到另一个列定义:
\documentclass{article}
\usepackage{tabularx}
\begin{document}
\begin{tabularx}{0.8\textwidth} { |
l |
>{\raggedright\arraybackslash}X |
c |
}
\hline
Place/Transition & Explanation & Time \\
\hline
$T_1$ and $T_{2(n+1)}$ & Robot operation which relates to loadlocks. Transition $T_1$ indicates that wafer unloading from the loadlocks and $T_{2(n+1)}$ means that the robot loads the wafer to the loadlocks. & w \\
\hline
item 31 & item 32 & item 33 \\
\hline
\end{tabularx}
\end{document}
可以借助该booktabs
包创建一个替代解决方案,它可以帮助您减少单元格之间的边框数量:
\documentclass{article}
\usepackage{tabularx}
\usepackage{booktabs}
\begin{document}
\renewcommand{\arraystretch}{1.25}
\begin{tabularx}{0.8\textwidth} {
l
>{\raggedright\arraybackslash}X
c
}
\toprule
Place/Transition & Explanation & Time \\
\midrule
$T_1$ and $T_{2(n+1)}$ & Robot operation which relates to loadlocks. Transition $T_1$ indicates that wafer unloading from the loadlocks and $T_{2(n+1)}$ means that the robot loads the wafer to the loadlocks. & w \\
item 31 & item 32 & item 33 \\
\bottomrule
\end{tabularx}
\end{document}
请注意,如果您想将表格扩展到双列布局中文本列的宽度,则可能需要替换0.8\textwidth
:\linewidth
\documentclass[journal]{IEEEtran}
\usepackage{lipsum}
\usepackage{tabularx}
\begin{document}
\lipsum[1]
\noindent%
\begin{tabularx}{\linewidth} { |
l |
>{\raggedright\arraybackslash}X |
c |
}
\hline
Place/Transition & Explanation & Time \\
\hline
$T_1$ and $T_{2(n+1)}$ & Robot operation which relates to loadlocks. Transition $T_1$ indicates that wafer unloading from the loadlocks and $T_{2(n+1)}$ means that the robot loads the wafer to the loadlocks. & w \\
\hline
item 31 & item 32 & item 33 \\
\hline
\end{tabularx}
\newpage
Right column
\end{document}
答案2
以下是与第二张表格相辅相成的想法@JasperHabicht 的回答:删除两端的空白填充,并允许在第一列换行。
\documentclass{article}
\usepackage{tabularx} % for 'tabularx' env. and 'X' column type
\usepackage{booktabs} % for well-spaced horizontal rules
\usepackage{ragged2e} % for '\RaggedRight' macro
\newlength\mylen
\begin{document}
\begin{center}
\settowidth\mylen{Transition} % target width of column 1
\begin{tabularx}{0.8\textwidth} {@{}
>{\RaggedRight}p{\mylen} >{\RaggedRight}X c @{}}
\toprule
Place\slash Transition & Explanation & Time \\
\midrule
$T_1$ and $T_{2(n+1)}$ &
Robot operation which relates to loadlocks. Transition $T_1$ indicates that wafer unloading from the loadlocks, and $T_{2(n+1)}$ means that the robot loads the wafer to the loadlocks. &
$w$ \\
\addlinespace
item 31 & item 32 & item 33 \\
\bottomrule
\end{tabularx}
\end{center}
\end{document}