
但是,當我使用來自的參考代碼時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}
結果如下。
也許,有人有其他參考來創建我想要的表格嗎?
當我用 \noindent\begin{tabularx}{\linewidth} 取代 \begin{tabularx}{0.8\textwidth} 時,結果如下:
答案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 的回答:去掉兩端的空白填充,並允許在第 1 列中換行。
\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}